Add metrics comment for some additional info

This commit is contained in:
Daniel 2022-04-13 11:19:07 +02:00
parent dce16ad393
commit 8a16414766
2 changed files with 30 additions and 3 deletions

View file

@ -14,13 +14,18 @@ var (
instanceOption config.StringOption instanceOption config.StringOption
cfgOptionInstanceOrder = 0 cfgOptionInstanceOrder = 0
CfgOptionCommentKey = "core/metrics/comment"
commentOption config.StringOption
cfgOptionCommentOrder = 0
CfgOptionPushKey = "core/metrics/push" CfgOptionPushKey = "core/metrics/push"
pushOption config.StringOption pushOption config.StringOption
cfgOptionPushOrder = 0 cfgOptionPushOrder = 0
pushFlag string
instanceFlag string instanceFlag string
defaultInstance string defaultInstance string
commentFlag string
pushFlag string
) )
func init() { func init() {
@ -32,15 +37,16 @@ func init() {
} }
} }
flag.StringVar(&instanceFlag, "metrics-instance", defaultInstance, "set the default metrics instance label for all metrics")
flag.StringVar(&commentFlag, "metrics-comment", "", "set the default metrics comment label")
flag.StringVar(&pushFlag, "push-metrics", "", "set default URL to push prometheus metrics to") flag.StringVar(&pushFlag, "push-metrics", "", "set default URL to push prometheus metrics to")
flag.StringVar(&instanceFlag, "metrics-instance", defaultInstance, "set the default global instance label")
} }
func prepConfig() error { func prepConfig() error {
err := config.Register(&config.Option{ err := config.Register(&config.Option{
Name: "Metrics Instance Name", Name: "Metrics Instance Name",
Key: CfgOptionInstanceKey, Key: CfgOptionInstanceKey,
Description: "Define the prometheus instance label for exported metrics. Please note that changing the instance name will reset persisted metrics.", Description: "Define the prometheus instance label for all exported metrics. Please note that changing the metrics instance name will reset persisted metrics.",
Sensitive: true, Sensitive: true,
OptType: config.OptTypeString, OptType: config.OptTypeString,
ExpertiseLevel: config.ExpertiseLevelExpert, ExpertiseLevel: config.ExpertiseLevelExpert,
@ -58,6 +64,26 @@ func prepConfig() error {
} }
instanceOption = config.Concurrent.GetAsString(CfgOptionInstanceKey, instanceFlag) instanceOption = config.Concurrent.GetAsString(CfgOptionInstanceKey, instanceFlag)
err = config.Register(&config.Option{
Name: "Metrics Comment Label",
Key: CfgOptionCommentKey,
Description: "Define a metrics comment label, which is added to the info metric.",
Sensitive: true,
OptType: config.OptTypeString,
ExpertiseLevel: config.ExpertiseLevelExpert,
ReleaseLevel: config.ReleaseLevelStable,
DefaultValue: commentFlag,
RequiresRestart: true,
Annotations: config.Annotations{
config.DisplayOrderAnnotation: cfgOptionCommentOrder,
config.CategoryAnnotation: "Metrics",
},
})
if err != nil {
return err
}
commentOption = config.Concurrent.GetAsString(CfgOptionCommentKey, commentFlag)
err = config.Register(&config.Option{ err = config.Register(&config.Option{
Name: "Push Prometheus Metrics", Name: "Push Prometheus Metrics",
Key: CfgOptionPushKey, Key: CfgOptionPushKey,

View file

@ -23,6 +23,7 @@ func registerInfoMetric() error {
"go_arch": runtime.GOARCH, "go_arch": runtime.GOARCH,
"go_version": runtime.Version(), "go_version": runtime.Version(),
"go_compiler": runtime.Compiler, "go_compiler": runtime.Compiler,
"comment": commentOption(),
}, },
func() float64 { func() float64 {
return 1 return 1