Révision ca6107d3
Plugin feinstaubsensor: prepare for multiple fields per sensor metric
Optional components of the Feinstaubsensor may provide alternative
values for specific metrics (e.g. a BME280 sensor measures humidity,
temperature and atmospheric pressure).
| plugins/luftdaten/feinstaubsensor | ||
|---|---|---|
| 81 | 81 |
"graph_vlabel": "%", |
| 82 | 82 |
"graph_args": "-l 0", |
| 83 | 83 |
"graph_info": "Wifi signal strength", |
| 84 |
"api_value_name": "signal", |
|
| 84 |
"fields": [ |
|
| 85 |
{"api_key": "signal"},
|
|
| 86 |
], |
|
| 85 | 87 |
"value_type": "GAUGE", |
| 86 | 88 |
}, {
|
| 87 | 89 |
"name": "feinstaub_samples", |
| 88 | 90 |
"graph_title": "Feinstaub Sample Count", |
| 89 | 91 |
"graph_vlabel": "#", |
| 90 | 92 |
"graph_info": "Number of samples since bootup", |
| 91 |
"api_value_name": "samples", |
|
| 93 |
"fields": [ |
|
| 94 |
{"api_key": "samples"},
|
|
| 95 |
], |
|
| 92 | 96 |
"value_type": "DERIVE", |
| 93 | 97 |
}, {
|
| 94 | 98 |
"name": "feinstaub_humidity", |
| 95 | 99 |
"graph_title": "Feinstaub Humidity", |
| 96 | 100 |
"graph_vlabel": "% humidity", |
| 97 | 101 |
"graph_info": "Weather information: air humidity", |
| 98 |
"api_value_name": "humidity", |
|
| 102 |
"fields": [ |
|
| 103 |
{"api_key": "humidity"},
|
|
| 104 |
], |
|
| 99 | 105 |
"value_type": "GAUGE", |
| 100 | 106 |
}, {
|
| 101 | 107 |
"name": "feinstaub_temperature", |
| 102 | 108 |
"graph_title": "Feinstaub Temperature", |
| 103 | 109 |
"graph_vlabel": "°C", |
| 104 | 110 |
"graph_info": "Weather information: temperature", |
| 105 |
"api_value_name": "temperature", |
|
| 111 |
"fields": [ |
|
| 112 |
{"api_key": "temperature"},
|
|
| 113 |
], |
|
| 106 | 114 |
"value_type": "GAUGE", |
| 107 | 115 |
}, {
|
| 108 | 116 |
"name": "feinstaub_particles_pm10", |
| 109 | 117 |
"graph_title": "Feinstaub Particle Measurement P10", |
| 110 | 118 |
"graph_vlabel": "µg / m³", |
| 111 | 119 |
"graph_info": "Concentration of particles with a size between 2.5µm and 10µm", |
| 112 |
"api_value_name": "SDS_P1", |
|
| 120 |
"fields": [ |
|
| 121 |
{"api_key": "SDS_P1"},
|
|
| 122 |
], |
|
| 113 | 123 |
"value_type": "GAUGE", |
| 114 | 124 |
}, {
|
| 115 | 125 |
"name": "feinstaub_particles_pm2_5", |
| 116 | 126 |
"graph_title": "Feinstaub Particle Measurement P2.5", |
| 117 | 127 |
"graph_vlabel": "µg / m³", |
| 118 | 128 |
"graph_info": "Concentration of particles with a size up to 2.5µm", |
| 119 |
"api_value_name": "SDS_P2", |
|
| 129 |
"fields": [ |
|
| 130 |
{"api_key": "SDS_P2"},
|
|
| 131 |
], |
|
| 120 | 132 |
"value_type": "GAUGE", |
| 121 | 133 |
}] |
| 122 | 134 |
|
| ... | ... | |
| 181 | 193 |
for host_info in hosts: |
| 182 | 194 |
data = get_sensor_data(host_info.host) |
| 183 | 195 |
if data: |
| 184 |
for dataset in data["sensordatavalues"]: |
|
| 185 |
if dataset["value_type"] == graph_description["api_value_name"]: |
|
| 186 |
results.append((host_info, dataset["value"])) |
|
| 187 |
break |
|
| 188 |
else: |
|
| 189 |
# We cannot distinguish between fields that are not supported by the sensor (most |
|
| 190 |
# are optional) and missing data. Thus we cannot handle online/offline sensor data |
|
| 191 |
# fields, too. |
|
| 192 |
pass |
|
| 196 |
for data_field in graph_description["fields"]: |
|
| 197 |
for dataset in data["sensordatavalues"]: |
|
| 198 |
if dataset["value_type"] == data_field["api_key"]: |
|
| 199 |
results.append((host_info, data_field, dataset["value"])) |
|
| 200 |
break |
|
| 201 |
else: |
|
| 202 |
# We cannot distinguish between fields that are not supported by the sensor |
|
| 203 |
# (most are optional) and missing data. Thus we cannot handle online/offline |
|
| 204 |
# sensor data fields, too. |
|
| 205 |
pass |
|
| 193 | 206 |
# skip this multigraph, if no host contained this data field |
| 194 | 207 |
if results: |
| 195 | 208 |
print("multigraph {}".format(graph_description["name"]))
|
| ... | ... | |
| 199 | 212 |
for key in ("graph_title", "graph_vlabel", "graph_args", "graph_info"):
|
| 200 | 213 |
if key in graph_description: |
| 201 | 214 |
print("{} {}".format(key, graph_description[key]))
|
| 202 |
for host_info, value in results: |
|
| 203 |
print("{}.label {}".format(host_info.fieldname, host_info.label))
|
|
| 215 |
for host_info, data_field, value in results: |
|
| 216 |
try: |
|
| 217 |
label = "{} ({})".format(host_info.label, data_field["info"])
|
|
| 218 |
except KeyError: |
|
| 219 |
label = host_info.label |
|
| 220 |
print("{}.label {}".format(host_info.fieldname, label))
|
|
| 204 | 221 |
print("{}.type {}".format(host_info.fieldname, graph_description["value_type"]))
|
| 205 | 222 |
if include_values: |
| 206 |
for host_info, value in results: |
|
| 223 |
for host_info, data_field, value in results:
|
|
| 207 | 224 |
print("{}.value {}".format(host_info.fieldname, value))
|
| 208 | 225 |
print() |
| 209 | 226 |
|
Formats disponibles : Unified diff