mirror of
https://github.com/steinhobelgruen/netatmo-exporter.git
synced 2024-11-01 03:13:55 +00:00
Remove global metric
This commit is contained in:
parent
c6c3a0c452
commit
104816fd0c
45
collector.go
45
collector.go
|
@ -9,84 +9,84 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
netatmoUp = prometheus.NewGauge(prometheus.GaugeOpts{
|
prefix = "netatmo_"
|
||||||
Name: "netatmo_up",
|
netatmoUpDesc = prometheus.NewDesc(prefix+"up",
|
||||||
Help: "Zero if there was an error scraping the Netatmo API.",
|
"Zero if there was an error scraping the Netatmo API.",
|
||||||
})
|
nil, nil)
|
||||||
|
|
||||||
varLabels = []string{
|
varLabels = []string{
|
||||||
"module",
|
"module",
|
||||||
"station",
|
"station",
|
||||||
}
|
}
|
||||||
|
|
||||||
prefix = "netatmo_sensor_"
|
sensorPrefix = prefix + "sensor_"
|
||||||
|
|
||||||
updatedDesc = prometheus.NewDesc(
|
updatedDesc = prometheus.NewDesc(
|
||||||
prefix+"updated",
|
sensorPrefix+"updated",
|
||||||
"Timestamp of last update",
|
"Timestamp of last update",
|
||||||
varLabels,
|
varLabels,
|
||||||
nil)
|
nil)
|
||||||
|
|
||||||
tempDesc = prometheus.NewDesc(
|
tempDesc = prometheus.NewDesc(
|
||||||
prefix+"temperature_celsius",
|
sensorPrefix+"temperature_celsius",
|
||||||
"Temperature measurement in celsius",
|
"Temperature measurement in celsius",
|
||||||
varLabels,
|
varLabels,
|
||||||
nil)
|
nil)
|
||||||
|
|
||||||
humidityDesc = prometheus.NewDesc(
|
humidityDesc = prometheus.NewDesc(
|
||||||
prefix+"humidity_percent",
|
sensorPrefix+"humidity_percent",
|
||||||
"Relative humidity measurement in percent",
|
"Relative humidity measurement in percent",
|
||||||
varLabels,
|
varLabels,
|
||||||
nil)
|
nil)
|
||||||
|
|
||||||
cotwoDesc = prometheus.NewDesc(
|
cotwoDesc = prometheus.NewDesc(
|
||||||
prefix+"co2_ppm",
|
sensorPrefix+"co2_ppm",
|
||||||
"Carbondioxide measurement in parts per million",
|
"Carbondioxide measurement in parts per million",
|
||||||
varLabels,
|
varLabels,
|
||||||
nil)
|
nil)
|
||||||
|
|
||||||
noiseDesc = prometheus.NewDesc(
|
noiseDesc = prometheus.NewDesc(
|
||||||
prefix+"noise_db",
|
sensorPrefix+"noise_db",
|
||||||
"Noise measurement in decibels",
|
"Noise measurement in decibels",
|
||||||
varLabels,
|
varLabels,
|
||||||
nil)
|
nil)
|
||||||
|
|
||||||
pressureDesc = prometheus.NewDesc(
|
pressureDesc = prometheus.NewDesc(
|
||||||
prefix+"pressure_mb",
|
sensorPrefix+"pressure_mb",
|
||||||
"Atmospheric pressure measurement in millibar",
|
"Atmospheric pressure measurement in millibar",
|
||||||
varLabels,
|
varLabels,
|
||||||
nil)
|
nil)
|
||||||
|
|
||||||
windStrengthDesc = prometheus.NewDesc(
|
windStrengthDesc = prometheus.NewDesc(
|
||||||
prefix+"wind_strength_kph",
|
sensorPrefix+"wind_strength_kph",
|
||||||
"Wind strength in kilometers per hour",
|
"Wind strength in kilometers per hour",
|
||||||
varLabels,
|
varLabels,
|
||||||
nil)
|
nil)
|
||||||
|
|
||||||
windDirectionDesc = prometheus.NewDesc(
|
windDirectionDesc = prometheus.NewDesc(
|
||||||
prefix+"wind_direction_degrees",
|
sensorPrefix+"wind_direction_degrees",
|
||||||
"Wind direction in degrees",
|
"Wind direction in degrees",
|
||||||
varLabels,
|
varLabels,
|
||||||
nil)
|
nil)
|
||||||
|
|
||||||
rainDesc = prometheus.NewDesc(
|
rainDesc = prometheus.NewDesc(
|
||||||
prefix+"rain_amount_mm",
|
sensorPrefix+"rain_amount_mm",
|
||||||
"Rain amount in millimeters",
|
"Rain amount in millimeters",
|
||||||
varLabels,
|
varLabels,
|
||||||
nil)
|
nil)
|
||||||
|
|
||||||
batteryDesc = prometheus.NewDesc(
|
batteryDesc = prometheus.NewDesc(
|
||||||
prefix+"battery_percent",
|
sensorPrefix+"battery_percent",
|
||||||
"Battery remaining life (10: low)",
|
"Battery remaining life (10: low)",
|
||||||
varLabels,
|
varLabels,
|
||||||
nil)
|
nil)
|
||||||
wifiDesc = prometheus.NewDesc(
|
wifiDesc = prometheus.NewDesc(
|
||||||
prefix+"wifi_signal_strength",
|
sensorPrefix+"wifi_signal_strength",
|
||||||
"Wifi signal strength (86: bad, 71: avg, 56: good)",
|
"Wifi signal strength (86: bad, 71: avg, 56: good)",
|
||||||
varLabels,
|
varLabels,
|
||||||
nil)
|
nil)
|
||||||
rfDesc = prometheus.NewDesc(
|
rfDesc = prometheus.NewDesc(
|
||||||
prefix+"rf_signal_strength",
|
sensorPrefix+"rf_signal_strength",
|
||||||
"RF signal strength (90: lowest, 60: highest)",
|
"RF signal strength (90: lowest, 60: highest)",
|
||||||
varLabels,
|
varLabels,
|
||||||
nil)
|
nil)
|
||||||
|
@ -110,12 +110,10 @@ func (c *netatmoCollector) Collect(mChan chan<- prometheus.Metric) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.log.Errorf("Error getting data: %s", err)
|
c.log.Errorf("Error getting data: %s", err)
|
||||||
|
|
||||||
netatmoUp.Set(0)
|
c.sendMetric(mChan, netatmoUpDesc, prometheus.GaugeValue, 0.0)
|
||||||
mChan <- netatmoUp
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
netatmoUp.Set(1)
|
c.sendMetric(mChan, netatmoUpDesc, prometheus.GaugeValue, 1.0)
|
||||||
mChan <- netatmoUp
|
|
||||||
|
|
||||||
for _, dev := range devices.Devices() {
|
for _, dev := range devices.Devices() {
|
||||||
stationName := dev.StationName
|
stationName := dev.StationName
|
||||||
|
@ -187,10 +185,11 @@ func (c *netatmoCollector) collectData(ch chan<- prometheus.Metric, device *neta
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *netatmoCollector) sendMetric(ch chan<- prometheus.Metric, desc *prometheus.Desc, valueType prometheus.ValueType, value float64, moduleName string, stationName string) {
|
func (c *netatmoCollector) sendMetric(ch chan<- prometheus.Metric, desc *prometheus.Desc, valueType prometheus.ValueType, value float64, labelValues ...string) {
|
||||||
m, err := prometheus.NewConstMetric(desc, valueType, value, moduleName, stationName)
|
m, err := prometheus.NewConstMetric(desc, valueType, value, labelValues...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.log.Errorf("Error creating %s metric: %s", updatedDesc.String(), err)
|
c.log.Errorf("Error creating %s metric: %s", updatedDesc.String(), err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
ch <- m
|
ch <- m
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue