Add lite summaries
This commit is contained in:
parent
0ff59c54c8
commit
399a371e7b
3 changed files with 54 additions and 4 deletions
55
exporter.go
55
exporter.go
|
@ -18,6 +18,7 @@ import (
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"gitea.drjosh.dev/josh/jmetrics"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
|
@ -85,6 +86,15 @@ func mainImpl() error {
|
||||||
NativeHistogramBucketFactor: 1.001,
|
NativeHistogramBucketFactor: 1.001,
|
||||||
NativeHistogramZeroThreshold: 0.001,
|
NativeHistogramZeroThreshold: 0.001,
|
||||||
})
|
})
|
||||||
|
busVoltageSumm := jmetrics.NewLiteGaugeSummary(jmetrics.LiteGaugeSummaryOpts{
|
||||||
|
Namespace: "ina219",
|
||||||
|
Subsystem: "summ",
|
||||||
|
Name: "bus_voltage",
|
||||||
|
Help: "Bus voltage (V)",
|
||||||
|
ConstLabels: constLabels,
|
||||||
|
})
|
||||||
|
prometheus.MustRegister(busVoltageSumm)
|
||||||
|
|
||||||
busCurrentHist := promauto.NewHistogram(prometheus.HistogramOpts{
|
busCurrentHist := promauto.NewHistogram(prometheus.HistogramOpts{
|
||||||
Namespace: "ina219",
|
Namespace: "ina219",
|
||||||
Name: "bus_current",
|
Name: "bus_current",
|
||||||
|
@ -93,6 +103,15 @@ func mainImpl() error {
|
||||||
NativeHistogramBucketFactor: 1.001,
|
NativeHistogramBucketFactor: 1.001,
|
||||||
NativeHistogramZeroThreshold: 0.001,
|
NativeHistogramZeroThreshold: 0.001,
|
||||||
})
|
})
|
||||||
|
busCurrentSumm := jmetrics.NewLiteGaugeSummary(jmetrics.LiteGaugeSummaryOpts{
|
||||||
|
Namespace: "ina219",
|
||||||
|
Subsystem: "summ",
|
||||||
|
Name: "bus_current",
|
||||||
|
Help: "Bus current (A)",
|
||||||
|
ConstLabels: constLabels,
|
||||||
|
})
|
||||||
|
prometheus.MustRegister(busCurrentSumm)
|
||||||
|
|
||||||
busPowerHist := promauto.NewHistogram(prometheus.HistogramOpts{
|
busPowerHist := promauto.NewHistogram(prometheus.HistogramOpts{
|
||||||
Namespace: "ina219",
|
Namespace: "ina219",
|
||||||
Name: "bus_power",
|
Name: "bus_power",
|
||||||
|
@ -101,6 +120,15 @@ func mainImpl() error {
|
||||||
NativeHistogramBucketFactor: 1.001,
|
NativeHistogramBucketFactor: 1.001,
|
||||||
NativeHistogramZeroThreshold: 0.001,
|
NativeHistogramZeroThreshold: 0.001,
|
||||||
})
|
})
|
||||||
|
busPowerSumm := jmetrics.NewLiteGaugeSummary(jmetrics.LiteGaugeSummaryOpts{
|
||||||
|
Namespace: "ina219",
|
||||||
|
Subsystem: "summ",
|
||||||
|
Name: "bus_power",
|
||||||
|
Help: "Bus power (W)",
|
||||||
|
ConstLabels: constLabels,
|
||||||
|
})
|
||||||
|
prometheus.MustRegister(busPowerSumm)
|
||||||
|
|
||||||
shuntVoltageHist := promauto.NewHistogram(prometheus.HistogramOpts{
|
shuntVoltageHist := promauto.NewHistogram(prometheus.HistogramOpts{
|
||||||
Namespace: "ina219",
|
Namespace: "ina219",
|
||||||
Name: "shunt_voltage",
|
Name: "shunt_voltage",
|
||||||
|
@ -109,6 +137,14 @@ func mainImpl() error {
|
||||||
NativeHistogramBucketFactor: 1.001,
|
NativeHistogramBucketFactor: 1.001,
|
||||||
NativeHistogramZeroThreshold: 0.001,
|
NativeHistogramZeroThreshold: 0.001,
|
||||||
})
|
})
|
||||||
|
shuntVoltageSumm := jmetrics.NewLiteGaugeSummary(jmetrics.LiteGaugeSummaryOpts{
|
||||||
|
Namespace: "ina219",
|
||||||
|
Subsystem: "summ",
|
||||||
|
Name: "shunt_voltage",
|
||||||
|
Help: "Shunt voltage (V)",
|
||||||
|
ConstLabels: constLabels,
|
||||||
|
})
|
||||||
|
prometheus.MustRegister(shuntVoltageSumm)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
http.Handle("/metrics", promhttp.Handler())
|
http.Handle("/metrics", promhttp.Handler())
|
||||||
|
@ -128,10 +164,21 @@ func mainImpl() error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("sensor reading error: %v", err)
|
return fmt.Errorf("sensor reading error: %v", err)
|
||||||
}
|
}
|
||||||
busVoltageHist.Observe(float64(p.Voltage) / float64(physic.Volt))
|
busVolts := float64(p.Voltage) / float64(physic.Volt)
|
||||||
busCurrentHist.Observe(float64(p.Current) / float64(physic.Ampere))
|
busVoltageHist.Observe(busVolts)
|
||||||
busPowerHist.Observe(float64(p.Power) / float64(physic.Watt))
|
busVoltageSumm.Observe(busVolts)
|
||||||
shuntVoltageHist.Observe(float64(p.Shunt) / float64(physic.Volt))
|
|
||||||
|
busAmps := float64(p.Current) / float64(physic.Ampere)
|
||||||
|
busCurrentHist.Observe(busAmps)
|
||||||
|
busCurrentSumm.Observe(busAmps)
|
||||||
|
|
||||||
|
busWatts := float64(p.Power) / float64(physic.Watt)
|
||||||
|
busPowerHist.Observe(busWatts)
|
||||||
|
busPowerSumm.Observe(busWatts)
|
||||||
|
|
||||||
|
shuntVolts := float64(p.Shunt) / float64(physic.Volt)
|
||||||
|
shuntVoltageHist.Observe(shuntVolts)
|
||||||
|
shuntVoltageSumm.Observe(shuntVolts)
|
||||||
|
|
||||||
case <-halt:
|
case <-halt:
|
||||||
return nil
|
return nil
|
||||||
|
|
1
go.mod
1
go.mod
|
@ -3,6 +3,7 @@ module gitea.drjosh.dev/josh/ina219-exporter
|
||||||
go 1.23.1
|
go 1.23.1
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
gitea.drjosh.dev/josh/jmetrics v0.0.2
|
||||||
github.com/prometheus/client_golang v1.20.4
|
github.com/prometheus/client_golang v1.20.4
|
||||||
periph.io/x/conn/v3 v3.7.1
|
periph.io/x/conn/v3 v3.7.1
|
||||||
periph.io/x/devices/v3 v3.7.1
|
periph.io/x/devices/v3 v3.7.1
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -1,3 +1,5 @@
|
||||||
|
gitea.drjosh.dev/josh/jmetrics v0.0.2 h1:k3qollGGryN46ZJSc2QE7o8Qc5tjAkI/etGhOPc3uMg=
|
||||||
|
gitea.drjosh.dev/josh/jmetrics v0.0.2/go.mod h1:2nQ3pf8j3kSfLIjRVWrKWuWGPjh/TKnu7MDx6PFb4BM=
|
||||||
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
||||||
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
||||||
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||||
|
|
Loading…
Reference in a new issue