Skip to content

Commit

Permalink
Fully working exporter and binary release prep
Browse files Browse the repository at this point in the history
Also:
 * fixed an accidental spin-wait in `wait_for_not_ready_timeout`
 * updated dependencies, including tokio to v1.2
 * various API improvements to custom unit value types
 * README improvements
  • Loading branch information
timothyb89 committed Feb 27, 2021
1 parent 2ff606a commit 535473f
Show file tree
Hide file tree
Showing 8 changed files with 931 additions and 438 deletions.
771 changes: 358 additions & 413 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ serde = { version = "1.0", features = ["derive"], optional = true}
serde_json = { version = "1.0", optional = true }

# requirements for exporter
warp = { version = "0.2", optional = true }
tokio = { version = "0.2", features = ["macros"], optional = true }
warp = { version = "0.3", optional = true }
tokio = { version = "1.2", features = ["full"], optional = true }
tokio-stream = { version = "0.1", optional = true }
simple-prometheus-exporter = { git = "https://github.com/timothyb89/simple-prometheus-exporter-rs", tag = "v0.1.0", optional = true }

[features]
default = []

bin = ["env_logger", "color-eyre", "structopt", "serde", "serde_json"]
exporter = ["warp", "tokio", "simple-prometheus-exporter"]
exporter = ["warp", "tokio", "tokio-stream", "simple-prometheus-exporter"]

[[bin]]
name = "metriful-exporter"
Expand All @@ -49,3 +50,6 @@ required-features = ["bin", "exporter"]
name = "metriful-tool"
path = "src/bin/metriful_tool.rs"
required-features = ["bin"]

[profile.release]
lto = true
287 changes: 287 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,293 @@ Requires rustc >= 1.48.
[`rust-i2cdev`]: https://github.com/rust-embedded/rust-i2cdev
[`rust-sysfs-gpio`]: https://github.com/rust-embedded/rust-sysfs-gpio

## `metriful-exporter`

`metriful-exporter` serves all Metriful metrics over HTTP as both JSON and
Prometheus metrics.

### Installation

1. Copy the `metriful-exporter` binary into `/usr/local/bin/`
2. Create a systemd service file for the exporter at
`/etc/systemd/system/metriful-exporter.service`:

```
[Unit]
Description=metriful monitoring service
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=1
User=root
ExecStart=/usr/local/bin/metriful-exporter --gpio-ready 17 --interval 100s
[Install]
WantedBy=multi-user.target
```
3. Enable and start the service: `sudo systemctl enable --now metriful-exporter`
4. If desired, add a scrape config to your Prometheus instance:
```yaml
- job_name: metriful-office
scrape_interval: 100s
static_configs:
- targets: ['pi.lan:8083']
labels:
location: Inside
room: Office
```
Make sure the scrape interval matches the exporter's interval (either 3,
100, or 300 seconds)
### API examples
The following examples use [`xh`].
Prometheus metrics: `xh get pi.lan:8083/metrics`: <details><summary>Expand</summary>
```prometheus
metriful_ready 1
metriful_air_gas_sensor_resistance{unit="ohms"} 479736
metriful_air_humidity{unit="% relative humidity"} 17.100000381469727
metriful_air_pressure{unit="pascals"} 84247
metriful_air_temperature{unit="degrees Celsius"} 22
metriful_air_quality_aqi{unit="AQI"} 25
metriful_air_quality_aqi_accuracy{unit="AQI accuracy"} 0
metriful_air_quality_estimated_co2{unit="parts per million"} 500
metriful_air_quality_estimated_voc{unit="parts per million"} 5
metriful_light_illuminance{unit="lux"} 293.5
metriful_light_white_level{unit="white level"} 8249
metriful_sound_measurement_stable{unit="sound measurement stability"} 0
metriful_sound_peak_amplitude{unit="millipascals"} 8489.5
metriful_sound_weighted_spl{unit="A-weighted sound pressure level"} 37.5
metriful_sound_spl_b1{unit="decibels",band_midpoint_hz="125",band_lower_hz="88",band_upper_hz="177"} 38.79999923706055
metriful_sound_spl_b2{unit="decibels",band_midpoint_hz="250",band_lower_hz="177",band_upper_hz="354"} 33.099998474121094
metriful_sound_spl_b3{unit="decibels",band_midpoint_hz="500",band_lower_hz="354",band_upper_hz="707"} 35.099998474121094
metriful_sound_spl_b4{unit="decibels",band_midpoint_hz="1000",band_lower_hz="707",band_upper_hz="1414"} 32.29999923706055
metriful_sound_spl_b5{unit="decibels",band_midpoint_hz="2000",band_lower_hz="1414",band_upper_hz="2828"} 29.399999618530273
metriful_sound_spl_b6{unit="decibels",band_midpoint_hz="4000",band_lower_hz="2828",band_upper_hz="5657"} 26
metriful_read_count 2
metriful_error_count 0
```
</details>

JSON metrics: `xh get pi.lan:8083/json`: <details><summary>Expand</summary>

```json
{
"error_count": 0,
"initial_status": {
"light_int": {
"status": "disabled"
},
"mode": {
"mode": "standby"
},
"particle_sensor": "disabled",
"sound_int": {
"status": "disabled"
}
},
"options": {
"device": "/dev/i2c-1",
"gpio_ready": 17,
"i2c_address": 113,
"interval": {
"period": "3s"
},
"port": 8083,
"timeout": null
},
"read_count": 2,
"reading": {
"formatted_value": "air data:\n temperature: 22 ℃\n pressure: 84247 Pa\n humidity: 17.1 % RH\n gas sensor resistance: 479736 Ω\n\nair quality data:\n air quality index: 25\n estimated CO2: 500 ppm\n estimated VOCs: 5 ppm\n AQI accuracy: invalid\n\nlight data:\n illuminance: 293.5 lx\n white level: 8249\n\nsound data:\n a-weighted SPL: 37.5 dBa\n SPL frequency bands: [38.8, 33.1, 35.1, 32.3, 29.4, 26.0]\n peak amplitude: 8489.5 mPa\n measurement stability: unstable\n\nparticle data:\n duty cycle: 0 %\n concentration: 0\n validity: initializing\n\n",
"timestamp": "2021-02-27T22:57:45Z",
"unit_name": "all combined data",
"unit_symbol": null,
"value": {
"air": {
"formatted_value": "temperature: 22 ℃\npressure: 84247 Pa\nhumidity: 17.1 % RH\ngas sensor resistance: 479736 Ω\n",
"timestamp": "2021-02-27T22:57:45Z",
"unit_name": "combined air data",
"unit_symbol": null,
"value": {
"gas_sensor_resistance": {
"formatted_value": "479736 Ω",
"timestamp": "2021-02-27T22:57:45Z",
"unit_name": "ohms",
"unit_symbol": "Ω",
"value": 479736
},
"humidity": {
"formatted_value": "17.1 % RH",
"timestamp": "2021-02-27T22:57:45Z",
"unit_name": "% relative humidity",
"unit_symbol": "% RH",
"value": 17.100000381469727
},
"pressure": {
"formatted_value": "84247 Pa",
"timestamp": "2021-02-27T22:57:45Z",
"unit_name": "pascals",
"unit_symbol": "Pa",
"value": 84247
},
"temperature": {
"formatted_value": "22 ℃",
"timestamp": "2021-02-27T22:57:45Z",
"unit_name": "degrees Celsius",
"unit_symbol": "",
"value": 22.0
}
}
},
"air_quality": {
"formatted_value": "air quality index: 25\nestimated CO2: 500 ppm\nestimated VOCs: 5 ppm\nAQI accuracy: invalid\n",
"timestamp": "2021-02-27T22:57:45Z",
"unit_name": "combined air quality data",
"unit_symbol": null,
"value": {
"aqi": {
"formatted_value": "25",
"timestamp": "2021-02-27T22:57:45Z",
"unit_name": "AQI",
"unit_symbol": null,
"value": 25.0
},
"aqi_accuracy": {
"formatted_value": "invalid",
"timestamp": "2021-02-27T22:57:45Z",
"unit_name": "AQI accuracy",
"unit_symbol": null,
"value": "invalid"
},
"estimated_co2": {
"formatted_value": "500 ppm",
"timestamp": "2021-02-27T22:57:45Z",
"unit_name": "parts per million",
"unit_symbol": "ppm",
"value": 500.0
},
"estimated_voc": {
"formatted_value": "5 ppm",
"timestamp": "2021-02-27T22:57:45Z",
"unit_name": "parts per million",
"unit_symbol": "ppm",
"value": 5.0
}
}
},
"light": {
"formatted_value": "illuminance: 293.5 lx\nwhite level: 8249\n",
"timestamp": "2021-02-27T22:57:45Z",
"unit_name": "combined light data",
"unit_symbol": null,
"value": {
"illuminance": {
"formatted_value": "293.5 lx",
"timestamp": "2021-02-27T22:57:45Z",
"unit_name": "lux",
"unit_symbol": "lx",
"value": 293.5
},
"white_level": {
"formatted_value": "8249",
"timestamp": "2021-02-27T22:57:45Z",
"unit_name": "white level",
"unit_symbol": null,
"value": 8249
}
}
},
"particle": {
"formatted_value": "duty cycle: 0 %\nconcentration: 0\nvalidity: initializing\n",
"timestamp": "2021-02-27T22:57:45Z",
"unit_name": "combined particle data",
"unit_symbol": null,
"value": {
"concentration": {
"formatted_value": "0",
"timestamp": "2021-02-27T22:57:45Z",
"unit_name": "raw particle concentration",
"unit_symbol": null,
"value": {
"ppd42_value": 0,
"sds011_value": 0.0
}
},
"duty_cycle": {
"formatted_value": "0 %",
"timestamp": "2021-02-27T22:57:45Z",
"unit_name": "percent",
"unit_symbol": "%",
"value": 0.0
},
"validity": {
"formatted_value": "initializing",
"timestamp": "2021-02-27T22:57:45Z",
"unit_name": "particle data validity",
"unit_symbol": null,
"value": "initializing"
}
}
},
"sound": {
"formatted_value": "a-weighted SPL: 37.5 dBa\nSPL frequency bands: [38.8, 33.1, 35.1, 32.3, 29.4, 26.0]\npeak amplitude: 8489.5 mPa\nmeasurement stability: unstable\n",
"timestamp": "2021-02-27T22:57:45Z",
"unit_name": "combined sound data",
"unit_symbol": null,
"value": {
"measurement_stability": {
"formatted_value": "unstable",
"timestamp": "2021-02-27T22:57:45Z",
"unit_name": "sound measurement stability",
"unit_symbol": null,
"value": "unstable"
},
"peak_amplitude": {
"formatted_value": "8489.5 mPa",
"timestamp": "2021-02-27T22:57:45Z",
"unit_name": "millipascals",
"unit_symbol": "mPa",
"value": 8489.5
},
"spl_bands": {
"formatted_value": "[38.8, 33.1, 35.1, 32.3, 29.4, 26.0]",
"timestamp": "2021-02-27T22:57:45Z",
"unit_name": "sound pressure level frequency bands",
"unit_symbol": null,
"value": [
38.79999923706055,
33.099998474121094,
35.099998474121094,
32.29999923706055,
29.399999618530273,
26.0
]
},
"weighted_spl": {
"formatted_value": "37.5 dBa",
"timestamp": "2021-02-27T22:57:45Z",
"unit_name": "A-weighted sound pressure level",
"unit_symbol": "dBa",
"value": 37.5
}
}
}
}
}
}
```
</details>

[`xh`]: https://github.com/ducaale/xh

## `metriful-tool`

`metriful-tool` can be used to query and manage Metriful sensors.
Expand Down
1 change: 0 additions & 1 deletion metriful-exporter.service
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

[Unit]
Description=metriful monitoring service
After=network.target
Expand Down
Loading

0 comments on commit 535473f

Please sign in to comment.