2018-08-26 21:57:19 +02:00
|
|
|
package version
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2018-08-27 15:22:32 +02:00
|
|
|
"runtime"
|
2020-06-11 16:32:54 +02:00
|
|
|
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
2018-08-26 21:57:19 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
zreplVersion string // set by build infrastructure
|
|
|
|
)
|
|
|
|
|
|
|
|
type ZreplVersionInformation struct {
|
|
|
|
Version string
|
2020-09-06 15:39:34 +02:00
|
|
|
RuntimeGo string
|
2018-08-26 21:57:19 +02:00
|
|
|
RuntimeGOOS string
|
|
|
|
RuntimeGOARCH string
|
|
|
|
RUNTIMECompiler string
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewZreplVersionInformation() *ZreplVersionInformation {
|
|
|
|
return &ZreplVersionInformation{
|
|
|
|
Version: zreplVersion,
|
2020-09-06 15:39:34 +02:00
|
|
|
RuntimeGo: runtime.Version(),
|
2018-08-26 21:57:19 +02:00
|
|
|
RuntimeGOOS: runtime.GOOS,
|
|
|
|
RuntimeGOARCH: runtime.GOARCH,
|
|
|
|
RUNTIMECompiler: runtime.Compiler,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *ZreplVersionInformation) String() string {
|
2020-09-06 15:39:34 +02:00
|
|
|
return fmt.Sprintf("zrepl version=%s go=%s GOOS=%s GOARCH=%s Compiler=%s",
|
|
|
|
i.Version, i.RuntimeGo, i.RuntimeGOOS, i.RuntimeGOARCH, i.RUNTIMECompiler)
|
2018-08-26 21:57:19 +02:00
|
|
|
}
|
2020-06-11 16:32:54 +02:00
|
|
|
|
|
|
|
var prometheusMetric = prometheus.NewUntypedFunc(
|
|
|
|
prometheus.UntypedOpts{
|
|
|
|
Namespace: "zrepl",
|
|
|
|
Subsystem: "version",
|
|
|
|
Name: "daemon",
|
|
|
|
Help: "zrepl daemon version",
|
|
|
|
ConstLabels: map[string]string{
|
|
|
|
"raw": zreplVersion,
|
|
|
|
"version_info": NewZreplVersionInformation().String(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
func() float64 { return 1 },
|
|
|
|
)
|
|
|
|
|
|
|
|
func PrometheusRegister(r prometheus.Registerer) {
|
|
|
|
r.MustRegister(prometheusMetric)
|
|
|
|
}
|