},
[]string{"ePDUOutletStatusIndex", "ePDUOutletStatusOutletName"},
)
+
+ pm10Gauge = promauto.NewGaugeVec(
+ prometheus.GaugeOpts{
+ Name: "airsensor_pm10",
+ Help: "Used to measure air PM1.0 concentration in µg/m³",
+ },
+ []string{"location"},
+ )
+
pm25Gauge = promauto.NewGaugeVec(
prometheus.GaugeOpts{
Name: "airsensor_pm25",
tempExpire = make(map[string]time.Time)
powerExpire = make(map[string]time.Time)
+ pm10Expire = make(map[string]time.Time)
pm25Expire = make(map[string]time.Time)
aqiExpire = make(map[string]time.Time)
uptimeExpire = make(map[string]time.Time)
func handleAQI(obj map[string]interface{}) {
now := time.Now().UTC()
- // do the label update here
- //pm25Gauge.With(prometheus.Labels{"location": location}).Set(pm25)
aqiGauge.With(prometheus.Labels{"location": obj["location"].(string)}).Set(obj["aqi"].(float64))
expireMutex.Lock()
defer expireMutex.Unlock()
aqiExpire[obj["location"].(string)] = now
- //pm25Expire[location] = now
}
-func processPM25(location string, pm25 float64, sendChannel chan helper.RabbitSend) {
+func processPM25(location string, pm10 float64, pm25 float64, sendChannel chan helper.RabbitSend) {
// should have the senseType setup correctly now, if we're still here
dataMap := make(map[string]interface{}, 0)
dataMap["location"] = location
+ dataMap["pm10"] = pm10
dataMap["pm25"] = pm25
results, err := aqi.Calculate(aqi.PM25{Concentration: pm25})
if err != nil {
aqi := results.AQI
dataMap["aqi"] = aqi
+ pm10Gauge.With(prometheus.Labels{"location": location}).Set(pm10)
+ pm25Gauge.With(prometheus.Labels{"location": location}).Set(pm25)
+ now := time.Now().UTC()
+ expireMutex.Lock()
+ defer expireMutex.Unlock()
+ pm10Expire[location] = now
+ pm25Expire[location] = now
sendThis := helper.RabbitSend{Data: dataMap, RoutingKey: "aqi", IncludeDate: true}
sendChannel <- sendThis
} else if senseType == "pm25" {
location := data["location"].(string)
pm25 := data["pm25"].(float64)
- processPM25(location, pm25, sendChannel)
+ pm10 := data["pm10"].(float64)
+ processPM25(location, pm10, pm25, sendChannel)
} else {
logger.Info("Sense type not detected, ignoring")
}
pm25, ok := obj["pm25"].(float64)
if !ok {
logger.V(3).Info("pm25 not found in data, ignoring", "obj", obj)
- } else {
- processPM25(location, pm25, sendChannel)
+ }
+
+ pm10, ok := obj["pm10"].(float64)
+ if !ok {
+ logger.V(3).Info("pm10 not found in data, ignoring", "obj", obj)
+ }
+
+ if pm10 != 0.0 || pm25 != 0.0 {
+ processPM25(location, pm10, pm25, sendChannel)
}
temperature, ok := obj["temperature"].(float64)
func expireStaleMetrics() {
expireStaleMetric(tempExpire, tempGauge)
expireStaleMetric(powerExpire, powerGauge)
+ expireStaleMetric(pm10Expire, pm10Gauge)
expireStaleMetric(pm25Expire, pm25Gauge)
expireStaleMetric(aqiExpire, aqiGauge)
expireStaleMetric(uptimeExpire, uptimeGauge)