mirror of
https://github.com/tailscale/tailscale.git
synced 2025-07-13 09:09:06 +00:00
tsweb/varz: add binary name to version metric
Fixes tailscale/corp#29530 Change-Id: Iae04456d7ac5527897f060370e90c9517c00a818 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
3219de4cb8
commit
3b5ce9d1bc
@ -11,6 +11,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
"sort"
|
"sort"
|
||||||
@ -189,7 +191,11 @@ func writePromExpVar(w io.Writer, prefix string, kv expvar.KeyValue) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if vs, ok := v.(string); ok && strings.HasSuffix(name, "version") {
|
if vs, ok := v.(string); ok && strings.HasSuffix(name, "version") {
|
||||||
fmt.Fprintf(w, "%s{version=%q} 1\n", name, vs)
|
if name == "version" {
|
||||||
|
fmt.Fprintf(w, "%s{version=%q,binary=%q} 1\n", name, vs, binaryName())
|
||||||
|
} else {
|
||||||
|
fmt.Fprintf(w, "%s{version=%q} 1\n", name, vs)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
switch v := v.(type) {
|
switch v := v.(type) {
|
||||||
@ -308,6 +314,18 @@ func ExpvarDoHandler(expvarDoFunc func(f func(expvar.KeyValue))) func(http.Respo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var binaryName = sync.OnceValue(func() string {
|
||||||
|
exe, err := os.Executable()
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
exe2, err := filepath.EvalSymlinks(exe)
|
||||||
|
if err != nil {
|
||||||
|
return filepath.Base(exe)
|
||||||
|
}
|
||||||
|
return filepath.Base(exe2)
|
||||||
|
})
|
||||||
|
|
||||||
// PrometheusMetricsReflectRooter is an optional interface that expvar.Var implementations
|
// PrometheusMetricsReflectRooter is an optional interface that expvar.Var implementations
|
||||||
// can implement to indicate that they should be walked recursively with reflect to find
|
// can implement to indicate that they should be walked recursively with reflect to find
|
||||||
// sets of fields to export.
|
// sets of fields to export.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user