solana_exporter/cmd/solana-exporter/desc.go

36 lines
1.1 KiB
Go
Raw Normal View History

2024-10-24 05:20:30 -07:00
package main
import (
"github.com/asymmetric-research/solana-exporter/pkg/slog"
2024-10-24 05:20:30 -07:00
"github.com/prometheus/client_golang/prometheus"
)
2024-10-29 04:04:49 -07:00
type GaugeDesc struct {
Desc *prometheus.Desc
Name string
Help string
VariableLabels []string
}
2024-10-24 05:20:30 -07:00
func NewGaugeDesc(name string, description string, variableLabels ...string) *GaugeDesc {
return &GaugeDesc{
Desc: prometheus.NewDesc(name, description, variableLabels, nil),
Name: name,
Help: description,
VariableLabels: variableLabels,
}
}
func (c *GaugeDesc) MustNewConstMetric(value float64, labels ...string) prometheus.Metric {
2024-10-25 01:16:48 -07:00
logger := slog.Get()
2024-10-24 05:20:30 -07:00
if len(labels) != len(c.VariableLabels) {
2024-10-25 01:16:48 -07:00
logger.Fatalf("Provided labels (%v) do not match %s labels (%v)", labels, c.Name, c.VariableLabels)
2024-10-24 05:20:30 -07:00
}
2024-10-25 02:50:16 -07:00
logger.Debugf("Emitting %v to %s(%v)", value, labels, c.Name)
2024-10-24 05:20:30 -07:00
return prometheus.MustNewConstMetric(c.Desc, prometheus.GaugeValue, value, labels...)
}
func (c *GaugeDesc) NewInvalidMetric(err error) prometheus.Metric {
return prometheus.NewInvalidMetric(c.Desc, err)
}