nws_exporter

build status docs.rs crates.io

Prometheus metrics exporter for api.weather.gov

Features

nws_exporter fetches weather information for a particular [NWS station] using the [api.weather.gov] API and emits it as Prometheus metrics. Users must pick a particular station to fetch weather information from. The following metrics are emitted when available (not all fields are available for all stations).

Build

nws_exporter is a Rust program and must be built from source using a Rust toolchain.

Build from source

If you want to build from the latest code in the nws_exporter repo, you can build using the following steps.

text git clone git@github.com:56quarters/nws_exporter.git && cd nws_exporter cargo build --release

Install via cargo

After you have a Rust toolchain, you can also install the latest release directly via cargo install

text cargo install nws_exporter

Usage

Picking a station

In order to export NWS forecast information, nws_exporter needs to be told which NWS station to request information for. You can get a list of the available stations in your state by using the API itself. An example of this using curl is below.

text curl -sS 'https://api.weather.gov/stations?state=MA' | jq | less

This command lists all available stations in the state of Massachusetts. The properties.stationIdentifier field for each station is the ID that you should use with nws_exporter. For example KBOS is the ID for the station at Logan Airport in Boston.

You can then run nws_exporter for this station as demonstrated below.

text ./nws_exporter --station KBOS

Run

You can run nws_exporter as a Systemd service using the provided unit file. This unit file assumes that you have copied the resulting nws_exporter binary to /usr/local/bin/nws_exporter.

text sudo cp target/release/nws_exporter /usr/local/bin/nws_exporter sudo cp ext/nws_exporter.service /etc/systemd/system/nws_exporter.service sudo systemctl daemon-reload sudo systemctl enable nws_exporter.service sudo systemctl start nws_exporter.serivce

Prometheus

Prometheus metrics are exposed on port 9782 at /metrics. Once nws_exporter is running, configure scrapes of it by your Prometheus server. Add the host running nws_exporter as a target under the Prometheus scrape_configs section as described by the example below.

```yaml

Sample config for Prometheus.

global: scrapeinterval: 15s evaluationinterval: 15s externallabels: monitor: 'myprom'

scrapeconfigs: - jobname: nwsexporter staticconfigs: - targets: ['example:9782'] ```

License

nws_exporter is available under the terms of the GPL, version 3.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be licensed as above, without any additional terms or conditions.