mirror of
https://github.com/steinhobelgruen/netatmo-exporter.git
synced 2024-11-24 02:13:55 +00:00
Add station name as metric label (#3)
This commit is contained in:
parent
3cd880a5c5
commit
4a463b65c4
30
collector.go
30
collector.go
|
@ -20,6 +20,7 @@ var (
|
|||
|
||||
varLabels = []string{
|
||||
"module",
|
||||
"station",
|
||||
}
|
||||
|
||||
prefix = "netatmo_sensor_"
|
||||
|
@ -101,15 +102,16 @@ func (m *netatmoCollector) Collect(mChan chan<- prometheus.Metric) {
|
|||
mChan <- netatmoUp
|
||||
|
||||
for _, dev := range devices.Devices() {
|
||||
collectData(mChan, dev)
|
||||
stationName := dev.StationName
|
||||
collectData(mChan, dev, stationName)
|
||||
|
||||
for _, module := range dev.LinkedModules {
|
||||
collectData(mChan, module)
|
||||
collectData(mChan, module, stationName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func collectData(ch chan<- prometheus.Metric, device *netatmo.Device) {
|
||||
func collectData(ch chan<- prometheus.Metric, device *netatmo.Device, stationName string) {
|
||||
moduleName := device.ModuleName
|
||||
data := device.DashboardData
|
||||
|
||||
|
@ -122,43 +124,43 @@ func collectData(ch chan<- prometheus.Metric, device *netatmo.Device) {
|
|||
return
|
||||
}
|
||||
|
||||
sendMetric(ch, updatedDesc, prometheus.CounterValue, float64(date.UTC().Unix()), moduleName)
|
||||
sendMetric(ch, updatedDesc, prometheus.CounterValue, float64(date.UTC().Unix()), moduleName, stationName)
|
||||
|
||||
if data.Temperature != nil {
|
||||
sendMetric(ch, tempDesc, prometheus.GaugeValue, float64(*data.Temperature), moduleName)
|
||||
sendMetric(ch, tempDesc, prometheus.GaugeValue, float64(*data.Temperature), moduleName, stationName)
|
||||
}
|
||||
|
||||
if data.Humidity != nil {
|
||||
sendMetric(ch, humidityDesc, prometheus.GaugeValue, float64(*data.Humidity), moduleName)
|
||||
sendMetric(ch, humidityDesc, prometheus.GaugeValue, float64(*data.Humidity), moduleName, stationName)
|
||||
}
|
||||
|
||||
if data.CO2 != nil {
|
||||
sendMetric(ch, cotwoDesc, prometheus.GaugeValue, float64(*data.CO2), moduleName)
|
||||
sendMetric(ch, cotwoDesc, prometheus.GaugeValue, float64(*data.CO2), moduleName, stationName)
|
||||
}
|
||||
|
||||
if data.Noise != nil {
|
||||
sendMetric(ch, noiseDesc, prometheus.GaugeValue, float64(*data.Noise), moduleName)
|
||||
sendMetric(ch, noiseDesc, prometheus.GaugeValue, float64(*data.Noise), moduleName, stationName)
|
||||
}
|
||||
|
||||
if data.Pressure != nil {
|
||||
sendMetric(ch, pressureDesc, prometheus.GaugeValue, float64(*data.Pressure), moduleName)
|
||||
sendMetric(ch, pressureDesc, prometheus.GaugeValue, float64(*data.Pressure), moduleName, stationName)
|
||||
}
|
||||
|
||||
if data.WindStrength != nil {
|
||||
sendMetric(ch, windStrengthDesc, prometheus.GaugeValue, float64(*data.WindStrength), moduleName)
|
||||
sendMetric(ch, windStrengthDesc, prometheus.GaugeValue, float64(*data.WindStrength), moduleName, stationName)
|
||||
}
|
||||
|
||||
if data.WindAngle != nil {
|
||||
sendMetric(ch, windDirectionDesc, prometheus.GaugeValue, float64(*data.WindAngle), moduleName)
|
||||
sendMetric(ch, windDirectionDesc, prometheus.GaugeValue, float64(*data.WindAngle), moduleName, stationName)
|
||||
}
|
||||
|
||||
if data.Rain != nil {
|
||||
sendMetric(ch, rainDesc, prometheus.GaugeValue, float64(*data.Rain), moduleName)
|
||||
sendMetric(ch, rainDesc, prometheus.GaugeValue, float64(*data.Rain), moduleName, stationName)
|
||||
}
|
||||
}
|
||||
|
||||
func sendMetric(ch chan<- prometheus.Metric, desc *prometheus.Desc, valueType prometheus.ValueType, value float64, moduleName string) {
|
||||
m, err := prometheus.NewConstMetric(desc, valueType, value, moduleName)
|
||||
func sendMetric(ch chan<- prometheus.Metric, desc *prometheus.Desc, valueType prometheus.ValueType, value float64, moduleName string, stationName string) {
|
||||
m, err := prometheus.NewConstMetric(desc, valueType, value, moduleName, stationName)
|
||||
if err != nil {
|
||||
log.Printf("Error creating %s metric: %s", updatedDesc.String(), err)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue