PurpleAirPrometheusDataLogger module

Copyright 2023 carlkidcrypto, All rights reserved. A Python class designed to use the PurpleAirAPI for requesting sensor(s) data. Data will be exposed via a Prometheus-compatible HTTP endpoint.

For best practice from PurpleAir: “The data from individual sensors will update no less than every 30 seconds. As a courtesy, we ask that you limit the number of requests to no more than once every 1 to 10 minutes, assuming you are only using the API to obtain data from sensors. If retrieving data from multiple sensors at once, please send a single request rather than individual requests in succession.”

class PurpleAirPrometheusDataLogger.PurpleAirPrometheusDataLogger(PurpleAirApiReadKey=None, PurpleAirApiWriteKey=None, PurpleAirApiIpv4Address=None, prometheus_port=9760, registry=<prometheus_client.registry.CollectorRegistry object>)

Bases: PurpleAirDataLogger

A data logger class that exposes PurpleAir sensor data as Prometheus metrics. Each numeric sensor field is represented as a Gauge with a ‘sensor_index’ label, allowing multiple sensors to share the same metric names.

store_sensor_data(single_sensor_data_dict)

Update Prometheus Gauges with the latest sensor data.

Parameters:

single_sensor_data_dict (dict) – A python dictionary containing all fields for insertion. If a sensor doesn’t support a certain field make sure it is None and part of the dictionary. This method does no type or error checking. That is up to the caller.