-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetrics.py
59 lines (48 loc) · 1.89 KB
/
metrics.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from prometheus_client import Gauge, CollectorRegistry
from prometheus_client.exposition import generate_latest
from model import Payload
registry = CollectorRegistry()
enviro_pressure = Gauge(
'enviro_pressure',
'enviro pressure sensor data',
['sensor', 'uid'],
registry=registry)
enviro_temperature = Gauge(
'enviro_temperature',
'enviro temerature sensor degrees celcius',
['sensor', 'uid'],
registry=registry)
enviro_color_temperature = Gauge(
'enviro_color_temperature',
'enviro light color sensor data',
['sensor', 'uid'],
registry=registry)
enviro_gas_resistance = Gauge(
'enviro_gas_resistance',
'enviro gas resistance sensor data ',
['sensor', 'uid'],
registry=registry)
enviro_aqi = Gauge(
'enviro_aqi',
'enviro air quality data (gas resistance vs humidity) ',
['sensor', 'uid'],
registry=registry)
enviro_humidity = Gauge(
'enviro_humidity',
'enviro humidity sensor data %',
['sensor', 'uid'],
registry=registry)
enviro_luminance = Gauge(
'enviro_luminance',
'enviro light sensor data luminance',
['sensor', 'uid'],
registry=registry)
def register_enviro_metrics(payload: Payload):
readings = payload.readings
enviro_pressure.labels(payload.nickname, payload.uid).set(readings.pressure)
enviro_color_temperature.labels(payload.nickname, payload.uid).set(readings.color_temperature)
enviro_temperature.labels(payload.nickname, payload.uid).set(readings.temperature)
enviro_humidity.labels(payload.nickname, payload.uid).set(readings.humidity)
enviro_gas_resistance.labels(payload.nickname, payload.uid).set(readings.gas_resistance)
enviro_aqi.labels(payload.nickname, payload.uid).set(readings.aqi)
enviro_luminance.labels(payload.nickname, payload.uid).set(readings.luminance)