OpenWeatherMap Exporter
The openweathermap_exporter
is a prometheus exporter to query weather readings for many locations and publis their values in as metrics prometheus exposition format.
This uses the related crate openweathermap_client to query weather from the API.
Installation
Currently, no binaries or container images are being built. The only way to install it (assuming you have rust already installed) is via:
cargo install openweathermap_exporter
Automatic, building of
- release binaries (to be manually installed, cargo binstalled, or packaged)
- cross-platform container images
is in the works as are several other features.
Get An API Key
To obtain an OpenWeatherMap API Key, see this section.
Create A Config File
Create a config file. Start with the the template below (also available in source here )
This file should be named owm_exporter.yaml
and placed in the working directory from where you plan to run the exporter or in the user's home (~/
, %USERPROFILE%
) directory.
#listen:
# address: localhost # Defaults to localhost. Can be omitted and specified in the environment variable LISTEN_ADDRESS.
# port: 9001 # Defaults to 9001. Can be omitted and specified in the environment variable LISTEN_PORT.
owm:
api_key: # You must provide a an api key. Can be omitted from this file and specified in the environment variable API_KEY.
# units: metric # metric is the default
# language: en # en is the default
# The exporter doesn't currently warn if the duration of all the calls exceeds the duration
# of `poll_interval_seconds`. It's up to you to reconfigure so that all readings can be read
# withing the `poll_interval_seconds` timeframe. This will probably be updated in a future
# release.
#poll_interval_seconds: 60
#max_calls_per_minute: 60
cities:
- name: Bangkok
country_code: TH
- name: New York, NY
country_code: US
coordinates:
- lat: -0.829278
lon: -90.982067
display_name: The Galapagos
locations:
- id: 3936456
Run The Exporter
By default the exporter is pretty quiet. It uses env_logger to control the log level.
When first using the exporter, consider running with info
or debug
level
RUST_LOG=info cargo run
Available log levels are error
, warn
, info
, debug
, trace
.
Verify Metrics Are Published
All metrics returned by the free v2.5 API will be exported for scraping. At the moment any route will suffice to load the metrics. If you have not changed the default listen options you can test the your running instance with:
curl http://localhost:9001/
Metric Names
Because metric names are encouraged to contain unit names:
A metric name...
- ...should have a suffix describing the unit
openweathermap_exporter
metrics all include the unit of the measurement in their name and HELP text. If you change the setting for owm.units
in your config file, the names of the metrics and their HELP text will change accordingly.
See Example Of Metric Names to see how they're named and what information is available in the labels.
Example Dashboard
I don't have a generalized dashboard template ready yet. But will share one soon. This is what my weather dashboard looks like:
Example Of Metric Names
This is a scrape using the example template config file.
# HELP owm_cloudiness_percent % cloudiness
# TYPE owm_cloudiness_percent gauge
owm_cloudiness_percent 0
owm_cloudiness_percent 100
owm_cloudiness_percent 96
owm_cloudiness_percent 100
# HELP owm_temperature_degrees_celsius Temperature in °C
# TYPE owm_temperature_degrees_celsius gauge
owm_temperature_degrees_celsius 26.1
owm_temperature_degrees_celsius 18.28
owm_temperature_degrees_celsius 27.76
owm_temperature_degrees_celsius 16.02
# HELP owm_humidity_percent % Humidity
# TYPE owm_humidity_percent gauge
owm_humidity_percent 83
owm_humidity_percent 79
owm_humidity_percent 76
owm_humidity_percent 56
# HELP owm_temperature_feels_like_degrees_celsius Perceived temperature in °C
# TYPE owm_temperature_feels_like_degrees_celsius gauge
owm_temperature_feels_like_degrees_celsius 18.15
owm_temperature_feels_like_degrees_celsius 15.14
owm_temperature_feels_like_degrees_celsius 31.93
owm_temperature_feels_like_degrees_celsius 26.1
# HELP owm_wind_speed_meters_per_second Wind speed in meters/second
# TYPE owm_wind_speed_meters_per_second gauge
owm_wind_speed_meters_per_second 8.75
owm_wind_speed_meters_per_second 0.08
owm_wind_speed_meters_per_second 5.8
owm_wind_speed_meters_per_second 2.57
# HELP owm_visibility_meters Visibility in meters, 10000 max
# TYPE owm_visibility_meters gauge
owm_visibility_meters 10000
owm_visibility_meters 10000
owm_visibility_meters 10000
owm_visibility_meters 3882
# HELP owm_wind_direction_degrees Wind direction in degrees
# TYPE owm_wind_direction_degrees gauge
owm_wind_direction_degrees 178
owm_wind_direction_degrees 330
owm_wind_direction_degrees 250
owm_wind_direction_degrees 196
# HELP owm_timestamp_seconds Timestamp of last reading in seconds since UNIX epoch
# TYPE owm_timestamp_seconds gauge
owm_timestamp_seconds 1666883173
owm_timestamp_seconds 1666883459
owm_timestamp_seconds 1666883199
owm_timestamp_seconds 1666883178
# HELP owm_pressure_hpa Atmospheric pressure in hPa
# TYPE owm_pressure_hpa gauge
owm_pressure_hpa 1010
owm_pressure_hpa 1011
owm_pressure_hpa 990
owm_pressure_hpa 1019
# HELP owm_wind_gust_meters_per_second Wind gust speed in meters/second
# TYPE owm_wind_gust_meters_per_second gauge
owm_wind_gust_meters_per_second 5.96
owm_wind_gust_meters_per_second 0.31
# HELP owm_query_success Whether the most recent query for a location's weather succeeded
# TYPE owm_query_success gauge
owm_query_success 1
owm_query_success 1
owm_query_success 1
owm_query_success 1
# HELP owm_api_call_time_milliseconds Histogram of successful call times per location in milliseconds
# TYPE owm_api_call_time_milliseconds summary
owm_api_call_time_milliseconds 59
owm_api_call_time_milliseconds 58.997791357811785
owm_api_call_time_milliseconds 61.99786870677149
owm_api_call_time_milliseconds 61.99786870677149
owm_api_call_time_milliseconds 61.99786870677149
owm_api_call_time_milliseconds 61.99786870677149
owm_api_call_time_milliseconds 65
owm_api_call_time_milliseconds_sum 1941
owm_api_call_time_milliseconds_count 20
Getting An OpenWeatherMap API Key
To obtain an API key, go to https://openweathermap.org/home/sign_in to sign in or create an account. Once logged in, select your user name from the top-right menu bar and then My API Keys. Use the Create key form to create a new key.