Skip to content

Commit

Permalink
Merge pull request #7 from jeremyje/fixasync
Browse files Browse the repository at this point in the history
Add async gauge metrics
  • Loading branch information
jeremyje authored Oct 25, 2022
2 parents 7bffffe + 45387a7 commit dd40c4d
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions internal/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,19 @@ type metricsSink struct {
CPUThermalJunctionMax asyncfloat64.Gauge
CPUInfoPollCount syncfloat64.Counter
CPUDetail asyncfloat64.Gauge
lastValue *coretempsdk.CoreTempInfo
}

func (m *metricsSink) ObserveAsync(ctx context.Context) {
m.Observe(ctx, m.lastValue)
}

func (m *metricsSink) Observe(ctx context.Context, info *coretempsdk.CoreTempInfo) {
if info == nil {
return
}

m.lastValue = info
attrs := getDefaultAttributes()
curAttrs := append(attrs, attribute.String("model", info.CPUName))

Expand Down Expand Up @@ -119,11 +129,17 @@ func newMetrics(meter metric.Meter) (*metricsSink, error) {
return nil, err
}

return &metricsSink{
sink := &metricsSink{
CPUCoreTemperature: cpuCoreTemperature,
CPUCoreLoad: cpuCoreLoad,
CPUThermalJunctionMax: cpuThermalJunctionMax,
CPUInfoPollCount: cpuInfoPollCount,
CPUDetail: cpuDetail,
}, nil
}

meter.RegisterCallback([]instrument.Asynchronous{cpuCoreTemperature, cpuCoreLoad, cpuThermalJunctionMax, cpuDetail}, func(ctx context.Context) {
sink.ObserveAsync(ctx)
})

return sink, nil
}

0 comments on commit dd40c4d

Please sign in to comment.