Add histograms

This commit is contained in:
Josh Deprez 2024-09-30 14:56:22 +10:00
parent 5e80ec9991
commit 29340a3933

View file

@ -35,7 +35,15 @@ var (
"VBAT": jmetrics.NewLiteGaugeSummary("lifepo4wered_voltage_bat", "Battery voltage (mV)"),
"IOUT": jmetrics.NewLiteGaugeSummary("lifepo4wered_current_out", "Current out (mA)"),
}
lifepo4weredPOut = jmetrics.NewLiteGaugeSummary("lifepo4wered_power_out", "Power out (mW)")
lifepo4weredPOutSummary = jmetrics.NewLiteGaugeSummary("lifepo4wered_power_out", "Power out (mW)")
lifepo4weredHists = map[string]prometheus.Histogram{
"VIN": promauto.NewHistogram(prometheus.HistogramOpts{Namespace: "lifepo4wered", Name: "voltage_in", Help: "Voltage in (mV)"}),
"VOUT": promauto.NewHistogram(prometheus.HistogramOpts{Namespace: "lifepo4wered", Name: "voltage_out", Help: "Voltage out (mV)"}),
"VBAT": promauto.NewHistogram(prometheus.HistogramOpts{Namespace: "lifepo4wered", Name: "voltage_bat", Help: "Battery voltage (mV)"}),
"IOUT": promauto.NewHistogram(prometheus.HistogramOpts{Namespace: "lifepo4wered", Name: "current_out", Help: "Current out (mA)"}),
}
lifepo4weredPOutHist = promauto.NewHistogram(prometheus.HistogramOpts{Namespace: "lifepo4wered", Name: "power_out", Help: "Power out (mW)"})
)
func pollVars() {
@ -58,11 +66,13 @@ func pollVars() {
labels["var"] = name
lifepo4weredVars.With(labels).Set(float64(num))
v, ok := lifepo4weredSummaries[name]
if !ok {
continue
if v := lifepo4weredSummaries[name]; v != nil {
v.Observe(float64(num))
}
v.Observe(float64(num))
if h := lifepo4weredHists[name]; h != nil {
h.Observe(float64(num))
}
switch name {
case "VOUT", "IOUT":
pout *= num
@ -72,7 +82,9 @@ func pollVars() {
log.Fatalf("Couldn't scan output: %v", err)
}
lifepo4weredPOut.Observe(float64(pout) / 1e3) // mV * mA = µW; 1000µW = 1mW.
poutmw := float64(pout) / 1e3
lifepo4weredPOutSummary.Observe(poutmw) // mV * mA = µW; 1000µW = 1mW.
lifepo4weredPOutHist.Observe(poutmw)
}
func main() {