@@ -21,6 +21,7 @@ import (
2121 "net/http"
2222 _ "net/http/pprof" // enabling debugging
2323 "net/url"
24+ "runtime/debug"
2425
2526 "github.com/NYTimes/gziphandler"
2627 "github.com/cockroachdb/field-eng-powertools/stopper"
@@ -34,6 +35,10 @@ import (
3435 log "github.com/sirupsen/logrus"
3536)
3637
38+ // Version of the visus binary, set using:
39+ // `-ldflags="-X github.com/cockroachlabs/visus/internal/http.Version=..."`
40+ var Version string
41+
3742type serverImpl struct {
3843 clientTLSConfig * clientTLSConfig
3944 config * server.Config
@@ -143,7 +148,7 @@ func (s *serverImpl) Start(ctx *stopper.Context) error {
143148 })
144149
145150 http .Handle (s .config .Endpoint , gziphandler .GzipHandler (handler ))
146-
151+ s . debugInfo ()
147152 ctx .Go (func (ctx * stopper.Context ) error {
148153 var err error
149154 if ! s .config .Insecure {
@@ -183,6 +188,37 @@ func (s *serverImpl) errorResponse(w http.ResponseWriter, msg string, err error)
183188 }
184189}
185190
191+ func (s * serverImpl ) debugInfo () {
192+ if bi , ok := debug .ReadBuildInfo (); ok {
193+ labels := prometheus.Labels {
194+ "go_version" : bi .GoVersion ,
195+ "module" : bi .Path ,
196+ }
197+ for _ , setting := range bi .Settings {
198+ switch setting .Key {
199+ case "vcs.revision" :
200+ labels ["commit" ] = setting .Value
201+ case "vcs.time" :
202+ labels ["build_time" ] = setting .Value
203+ }
204+ }
205+ labels ["version" ] = Version
206+ g := prometheus .NewGauge (prometheus.GaugeOpts {
207+ Name : "visus_info" ,
208+ Help : "information about the visus binary" ,
209+ ConstLabels : labels ,
210+ })
211+ g .Set (1 )
212+ s .registry .Register (g )
213+ }
214+ g := prometheus .NewGauge (prometheus.GaugeOpts {
215+ Name : "visus_start_seconds" ,
216+ Help : "the wall time at which visus was started" ,
217+ })
218+ g .SetToCurrentTime ()
219+ s .registry .Register (g )
220+ }
221+
186222// refresh the server configuration
187223func (s * serverImpl ) refresh (ctx * stopper.Context ) error {
188224 if err := s .keyPair .load (); err != nil {
0 commit comments