Add endpoint for getting the version of the binary (#555)
* Add endpoint for getting the version of the binary Fixes #553 Signed-off-by: Zlepper <hansen13579@gmail.com>
This commit is contained in:
parent
c9f1e5068a
commit
f1384759cb
27
exporter.go
27
exporter.go
|
@ -3,6 +3,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
_ "net/http/pprof"
|
_ "net/http/pprof"
|
||||||
|
@ -28,6 +29,17 @@ type windowsCollector struct {
|
||||||
collectors map[string]collector.Collector
|
collectors map[string]collector.Collector
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Same struct prometheus uses for their /version endpoint.
|
||||||
|
// Separate copy to avoid pulling all of prometheus as a dependency
|
||||||
|
type prometheusVersion struct {
|
||||||
|
Version string `json:"version"`
|
||||||
|
Revision string `json:"revision"`
|
||||||
|
Branch string `json:"branch"`
|
||||||
|
BuildUser string `json:"buildUser"`
|
||||||
|
BuildDate string `json:"buildDate"`
|
||||||
|
GoVersion string `json:"goVersion"`
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
defaultCollectors = "cpu,cs,logical_disk,net,os,service,system,textfile"
|
defaultCollectors = "cpu,cs,logical_disk,net,os,service,system,textfile"
|
||||||
defaultCollectorsPlaceholder = "[defaults]"
|
defaultCollectorsPlaceholder = "[defaults]"
|
||||||
|
@ -337,6 +349,21 @@ func main() {
|
||||||
|
|
||||||
http.HandleFunc(*metricsPath, withConcurrencyLimit(*maxRequests, h.ServeHTTP))
|
http.HandleFunc(*metricsPath, withConcurrencyLimit(*maxRequests, h.ServeHTTP))
|
||||||
http.HandleFunc("/health", healthCheck)
|
http.HandleFunc("/health", healthCheck)
|
||||||
|
http.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
// we can't use "version" directly as it is a package, and not an object that
|
||||||
|
// can be serialized.
|
||||||
|
err := json.NewEncoder(w).Encode(prometheusVersion{
|
||||||
|
Version: version.Version,
|
||||||
|
Revision: version.Revision,
|
||||||
|
Branch: version.Branch,
|
||||||
|
BuildUser: version.BuildUser,
|
||||||
|
BuildDate: version.BuildDate,
|
||||||
|
GoVersion: version.GoVersion,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, fmt.Sprintf("error encoding JSON: %s", err), http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
})
|
||||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
_, _ = w.Write([]byte(`<html>
|
_, _ = w.Write([]byte(`<html>
|
||||||
<head><title>windows_exporter</title></head>
|
<head><title>windows_exporter</title></head>
|
||||||
|
|
Loading…
Reference in New Issue