diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index d79448d..3009226 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -74,7 +74,7 @@ jobs: GIT_TAG=$(git tag --points-at HEAD | tr -d '\n') if [ ! -z "$GIT_TAG" ]; then TAGS="$TAGS --tag ${DOCKER_IMAGE}:${GIT_TAG}"; fi echo DOCKER_IMAGE=${DOCKER_IMAGE} >> $GITHUB_ENV - echo BUILDX_ARGS="--platform ${DOCKER_PLATFORMS} ${TAGS} --file ./Dockerfile ./" >> $GITHUB_ENV + echo BUILDX_ARGS="--platform ${DOCKER_PLATFORMS} --build-arg VERSION=${GIT_TAG} ${TAGS} --file ./Dockerfile ./" >> $GITHUB_ENV # https://github.com/docker/setup-qemu-action - name: Set up QEMU diff --git a/README.md b/README.md index e0f6de4..4f8e0c1 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,81 @@ -# Prometheus Awair Exporter +# Prometheus Awair Exporter [![Coverage Status](https://coveralls.io/repos/github/rtrox/prometheus-awair-exporter/badge.svg?branch=main)](https://coveralls.io/github/rtrox/prometheus-awair-exporter?branch=main) -[![Coverage Status](https://coveralls.io/repos/github/rtrox/prometheus-awair-exporter/badge.svg?branch=main)](https://coveralls.io/github/rtrox/prometheus-awair-exporter?branch=main) \ No newline at end of file +Prometheus Awair Exporter connects to an Awair Element device over the Local API, and exports metric via prometheus. + +## Operating the Exporter + +Prometheus-Awair-Exporter requires one environmental variable to be set - `AWAIR_HOSTNAME`, which defines the IP or hostname of the Awair device you wish to monitor. There are also additional flags which can be passed for debugging: +```bash +Usage of ./awair-exporter: + -debug + sets log level to debug + -gocollector + enables go stats exporter + -processcollector + enables process stats exporter +``` + +So a normal usage would be: +``` +AWAIR_HOSTNAME=192.168.1.2 ./awair-exporter +``` +## Running In Docker + +Docker images are also generated automatically from this repo, and are available [in DockerHub](https://hub.docker.com/repository/docker/rtrox/prometheus-awair-exporter) for use. example usage: + +```bash +docker run rtrox/prometheus-awair-exporter:v0.0.2 -e AWAIR_HOSTNAME=192.168.3.105 -p 8080:8080 +``` + +## Example Metric Output + +```bash +# HELP awair_absolute_humidity Absolute Humidity (g/m³) +# TYPE awair_absolute_humidity gauge +awair_absolute_humidity 7.71 +# HELP awair_co2 Carbon Dioxide (ppm) +# TYPE awair_co2 gauge +awair_co2 530 +# HELP awair_co2_est Estimated Carbon Dioxide (ppm - calculated by the TVOC sensor) +# TYPE awair_co2_est gauge +awair_co2_est 420 +# HELP awair_co2_est_baseline A unitless value that represents the baseline from which the TVOC sensor partially derives its estimated (e)CO₂output. +# TYPE awair_co2_est_baseline gauge +awair_co2_est_baseline 35270 +# HELP awair_device_info Info about the awair device +# TYPE awair_device_info gauge +awair_device_info{device_uuid="awair-element_1",firmware_version="1.2.8",voc_feature_set="34"} 1 +# HELP awair_dew_point The temperature at which water will condense and form into dew (ºC) +# TYPE awair_dew_point gauge +awair_dew_point 7.58 +# HELP awair_humidity Relative Humidity (%) +# TYPE awair_humidity gauge +awair_humidity 46.08 +# HELP awair_pm10 Estimated particulate matter less than 10 microns in diameter (µg/m³ - calculated by the PM2.5 sensor) +# TYPE awair_pm10 gauge +awair_pm10 21 +# HELP awair_pm25 Particulate matter less than 2.5 microns in diameter (µg/m³) +# TYPE awair_pm25 gauge +awair_pm25 20 +# HELP awair_score Awair Score (0-100) +# TYPE awair_score gauge +awair_score 96 +# HELP awair_temp Dry bulb temperature (ºC) +# TYPE awair_temp gauge +awair_temp 19.48 +# HELP awair_voc Total Volatile Organic Compounds (ppb) +# TYPE awair_voc gauge +awair_voc 98 +# HELP awair_voc_baseline A unitless value that represents the baseline from which the TVOC sensor partially derives its TVOC output. +# TYPE awair_voc_baseline gauge +awair_voc_baseline 37378 +# HELP awair_voc_ethanol_raw A unitless value that represents the Ethanol gas signal from which the TVOC sensor partially derives its TVOC output. +# TYPE awair_voc_ethanol_raw gauge +awair_voc_ethanol_raw 36 +# HELP awair_voc_h2_raw A unitless value that represents the Hydrogen gas signal from which the TVOC sensor partially derives its TVOC output. +# TYPE awair_voc_h2_raw gauge +awair_voc_h2_raw 25 +# HELP exporter_info Info about this awair-exporter +# TYPE exporter_info gauge +exporter_info{app_name="awair-exporter",hostname="192.168.1.2",version="x.x.x"} 1 +``` \ No newline at end of file diff --git a/awair-exporter b/awair-exporter new file mode 100755 index 0000000..05e93ec Binary files /dev/null and b/awair-exporter differ diff --git a/cmd/awair-exporter/awair-exporter.go b/cmd/awair-exporter/awair-exporter.go index 8294ac8..a53200d 100644 --- a/cmd/awair-exporter/awair-exporter.go +++ b/cmd/awair-exporter/awair-exporter.go @@ -47,6 +47,8 @@ func newHealthCheckHandler() http.Handler { func main() { debug := flag.Bool("debug", false, "sets log level to debug") + goCollector := flag.Bool("gocollector", false, "enables go stats exporter") + processCollector := flag.Bool("processcollector", false, "enables process stats exporter") flag.Parse() zerolog.SetGlobalLevel(zerolog.InfoLevel) @@ -100,19 +102,28 @@ func main() { Msg("Failed to connect to Awair device.") } - prometheus.MustRegister(ex) infoMetricOpts.ConstLabels = prometheus.Labels{ "app_name": app_name, "version": version, "hostname": hostname, } - prometheus.MustRegister(prometheus.NewGaugeFunc( - infoMetricOpts, - func() float64 { return 1 }, - )) + reg := prometheus.NewPedanticRegistry() + reg.MustRegister( + prometheus.NewGaugeFunc( + infoMetricOpts, + func() float64 { return 1 }, + ), + ex, + ) + if *goCollector { + reg.MustRegister(prometheus.NewGoCollector()) + } + if *processCollector { + reg.MustRegister(prometheus.NewProcessCollector(prometheus.ProcessCollectorOpts{})) + } router := http.NewServeMux() - router.Handle("/metrics", promhttp.Handler()) + router.Handle("/metrics", promhttp.HandlerFor(reg, promhttp.HandlerOpts{})) router.Handle("/healthz", newHealthCheckHandler()) srv.Addr = ":8080" srv.Handler = router diff --git a/kubernetes/manifests/deployment.yaml b/kubernetes/manifests/deployment.yaml index f8d4334..c761bdc 100644 --- a/kubernetes/manifests/deployment.yaml +++ b/kubernetes/manifests/deployment.yaml @@ -37,7 +37,7 @@ spec: fsGroup: 10001 containers: - name: awair-exporter - image: 'rtrox/prometheus-awair-exporter:a43adf6' + image: 'rtrox/prometheus-awair-exporter:v0.0.2' imagePullPolicy: IfNotPresent env: # AWAIR_HOSTNAME is the hostname we should reach out to