#open-weather-map #prometheus-metrics #prometheus-exporter #metrics-exporter #prometheus #metrics #exporter

app openweathermap_exporter

一个聚合器,轮询 OpenWeatherMap 免费API数据,并以 Prometheus 展示格式暴露

5 个版本 (3 个重大更新)

0.4.0 2024年5月31日
0.3.0 2024年3月27日
0.2.0 2023年4月25日
0.1.1 2022年10月28日
0.1.0 2022年10月7日

#635命令行工具

Download history 142/week @ 2024-05-31 6/week @ 2024-06-07 3/week @ 2024-06-14

每月303次下载

MIT-0 许可证

170KB
1K SLoC

OpenWeatherMap Exporter

openweathermap_exporter 是一个 Prometheus 导出器,用于查询多个位置的天气读数,并将它们的值以 Prometheus 展示格式发布。

docs.rs | crates.io

它使用相关的 crate openweathermap_client 从API查询天气。

安装

目前,没有构建二进制文件或容器镜像。假设您已经安装了 rust ,安装的唯一方法是

cargo install openweathermap_exporter

自动构建以下内容:

  • 发布二进制文件(需要手动安装、通过 cargo binstall 安装或打包)
  • 跨平台容器镜像

正在进行中,还有其他一些功能

获取 API 密钥

要获取 OpenWeatherMap API 密钥,请参阅本节

创建配置文件

创建一个配置文件。从下面的模板开始(也在此处提供源这里)。此文件应命名为 owm_exporter.yaml 并放置在您计划运行导出器的工作目录中或用户的家目录(~/%USERPROFILE%)目录中。

#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

运行导出器

默认情况下,导出器相当安静。它使用 env_logger 来控制日志级别。

首次使用导出器时,请考虑以 infodebug 级别运行

RUST_LOG=info cargo run

可用的日志级别有 errorwarninfodebugtrace

验证指标是否已发布

免费 v2.5 API 返回的所有指标都将导出以供抓取。目前任何路由都可以用来加载指标。如果您没有更改默认的监听选项,可以使用以下方法测试您的运行实例:

curl https://127.0.0.1:9001/

指标名称

因为建议指标名称 包含单位名称

一个指标名称...

  • ...应该有一个描述单位的后缀

openweathermap_exporter 指标都包含在它们名称和 HELP 文本中的测量单位。如果您更改配置文件中 owm.units 的设置,指标的名称和它们的 HELP 文本将相应更改。

查看 指标名称示例 了解它们的命名方式和标签中可用的信息。

示例仪表板

我还没有准备好通用的仪表板模板。但很快就会分享一个。这是我天气仪表板的样子

weather-dashboard

指标名称示例

这是一个使用 示例模板配置文件 执行的抓取。

# HELP owm_cloudiness_percent % cloudiness
# TYPE owm_cloudiness_percent gauge
owm_cloudiness_percent{location="New York",q="New York, NY,US",reading_id="5128581",reading_lat="40.7143",reading_lon="-74.006",reading_name="New York"} 0
owm_cloudiness_percent{location="Lima",id="3936456",reading_id="3936456",reading_lat="-12.0432",reading_lon="-77.0282",reading_name="Lima"} 100
owm_cloudiness_percent{location="The Galapagos",lat="-0.829278",lon="-0.829278",display_name="The Galapagos",reading_id="6295630",reading_lat="-0.8293",reading_lon="-0.8293",reading_name="Globe"} 96
owm_cloudiness_percent{location="Bangkok",q="Bangkok,TH",reading_id="1609350",reading_lat="13.75",reading_lon="100.5167",reading_name="Bangkok"} 100

# HELP owm_temperature_degrees_celsius Temperature in °C
# TYPE owm_temperature_degrees_celsius gauge
owm_temperature_degrees_celsius{location="The Galapagos",lat="-0.829278",lon="-0.829278",display_name="The Galapagos",reading_id="6295630",reading_lat="-0.8293",reading_lon="-0.8293",reading_name="Globe"} 26.1
owm_temperature_degrees_celsius{location="Lima",id="3936456",reading_id="3936456",reading_lat="-12.0432",reading_lon="-77.0282",reading_name="Lima"} 18.28
owm_temperature_degrees_celsius{location="Bangkok",q="Bangkok,TH",reading_id="1609350",reading_lat="13.75",reading_lon="100.5167",reading_name="Bangkok"} 27.76
owm_temperature_degrees_celsius{location="New York",q="New York, NY,US",reading_id="5128581",reading_lat="40.7143",reading_lon="-74.006",reading_name="New York"} 16.02

# HELP owm_humidity_percent % Humidity
# TYPE owm_humidity_percent gauge
owm_humidity_percent{location="Bangkok",q="Bangkok,TH",reading_id="1609350",reading_lat="13.75",reading_lon="100.5167",reading_name="Bangkok"} 83
owm_humidity_percent{location="The Galapagos",lat="-0.829278",lon="-0.829278",display_name="The Galapagos",reading_id="6295630",reading_lat="-0.8293",reading_lon="-0.8293",reading_name="Globe"} 79
owm_humidity_percent{location="Lima",id="3936456",reading_id="3936456",reading_lat="-12.0432",reading_lon="-77.0282",reading_name="Lima"} 76
owm_humidity_percent{location="New York",q="New York, NY,US",reading_id="5128581",reading_lat="40.7143",reading_lon="-74.006",reading_name="New York"} 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{location="Lima",id="3936456",reading_id="3936456",reading_lat="-12.0432",reading_lon="-77.0282",reading_name="Lima"} 18.15
owm_temperature_feels_like_degrees_celsius{location="New York",q="New York, NY,US",reading_id="5128581",reading_lat="40.7143",reading_lon="-74.006",reading_name="New York"} 15.14
owm_temperature_feels_like_degrees_celsius{location="Bangkok",q="Bangkok,TH",reading_id="1609350",reading_lat="13.75",reading_lon="100.5167",reading_name="Bangkok"} 31.93
owm_temperature_feels_like_degrees_celsius{location="The Galapagos",lat="-0.829278",lon="-0.829278",display_name="The Galapagos",reading_id="6295630",reading_lat="-0.8293",reading_lon="-0.8293",reading_name="Globe"} 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{location="New York",q="New York, NY,US",reading_id="5128581",reading_lat="40.7143",reading_lon="-74.006",reading_name="New York"} 8.75
owm_wind_speed_meters_per_second{location="Bangkok",q="Bangkok,TH",reading_id="1609350",reading_lat="13.75",reading_lon="100.5167",reading_name="Bangkok"} 0.08
owm_wind_speed_meters_per_second{location="The Galapagos",lat="-0.829278",lon="-0.829278",display_name="The Galapagos",reading_id="6295630",reading_lat="-0.8293",reading_lon="-0.8293",reading_name="Globe"} 5.8
owm_wind_speed_meters_per_second{location="Lima",id="3936456",reading_id="3936456",reading_lat="-12.0432",reading_lon="-77.0282",reading_name="Lima"} 2.57

# HELP owm_visibility_meters Visibility in meters, 10000 max
# TYPE owm_visibility_meters gauge
owm_visibility_meters{location="Lima",id="3936456",reading_id="3936456",reading_lat="-12.0432",reading_lon="-77.0282",reading_name="Lima"} 10000
owm_visibility_meters{location="The Galapagos",lat="-0.829278",lon="-0.829278",display_name="The Galapagos",reading_id="6295630",reading_lat="-0.8293",reading_lon="-0.8293",reading_name="Globe"} 10000
owm_visibility_meters{location="New York",q="New York, NY,US",reading_id="5128581",reading_lat="40.7143",reading_lon="-74.006",reading_name="New York"} 10000
owm_visibility_meters{location="Bangkok",q="Bangkok,TH",reading_id="1609350",reading_lat="13.75",reading_lon="100.5167",reading_name="Bangkok"} 3882

# HELP owm_wind_direction_degrees Wind direction in degrees (0-360)
# TYPE owm_wind_direction_degrees gauge
owm_wind_direction_degrees{location="The Galapagos",lat="-0.829278",lon="-0.829278",display_name="The Galapagos",reading_id="6295630",reading_lat="-0.8293",reading_lon="-0.8293",reading_name="Globe"} 178
owm_wind_direction_degrees{location="New York",q="New York, NY,US",reading_id="5128581",reading_lat="40.7143",reading_lon="-74.006",reading_name="New York"} 330
owm_wind_direction_degrees{location="Lima",id="3936456",reading_id="3936456",reading_lat="-12.0432",reading_lon="-77.0282",reading_name="Lima"} 250
owm_wind_direction_degrees{location="Bangkok",q="Bangkok,TH",reading_id="1609350",reading_lat="13.75",reading_lon="100.5167",reading_name="Bangkok"} 196

# HELP owm_timestamp_seconds Timestamp of last reading in seconds since UNIX epoch
# TYPE owm_timestamp_seconds gauge
owm_timestamp_seconds{location="Lima",id="3936456",reading_id="3936456",reading_lat="-12.0432",reading_lon="-77.0282",reading_name="Lima"} 1666883173
owm_timestamp_seconds{location="The Galapagos",lat="-0.829278",lon="-0.829278",display_name="The Galapagos",reading_id="6295630",reading_lat="-0.8293",reading_lon="-0.8293",reading_name="Globe"} 1666883459
owm_timestamp_seconds{location="New York",q="New York, NY,US",reading_id="5128581",reading_lat="40.7143",reading_lon="-74.006",reading_name="New York"} 1666883199
owm_timestamp_seconds{location="Bangkok",q="Bangkok,TH",reading_id="1609350",reading_lat="13.75",reading_lon="100.5167",reading_name="Bangkok"} 1666883178

# HELP owm_pressure_hpa Atmospheric pressure in hPa
# TYPE owm_pressure_hpa gauge
owm_pressure_hpa{location="The Galapagos",lat="-0.829278",lon="-0.829278",display_name="The Galapagos",reading_id="6295630",reading_lat="-0.8293",reading_lon="-0.8293",reading_name="Globe"} 1010
owm_pressure_hpa{location="Bangkok",q="Bangkok,TH",reading_id="1609350",reading_lat="13.75",reading_lon="100.5167",reading_name="Bangkok"} 1011
owm_pressure_hpa{location="Lima",id="3936456",reading_id="3936456",reading_lat="-12.0432",reading_lon="-77.0282",reading_name="Lima"} 990
owm_pressure_hpa{location="New York",q="New York, NY,US",reading_id="5128581",reading_lat="40.7143",reading_lon="-74.006",reading_name="New York"} 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{location="The Galapagos",lat="-0.829278",lon="-0.829278",display_name="The Galapagos",reading_id="6295630",reading_lat="-0.8293",reading_lon="-0.8293",reading_name="Globe"} 5.96
owm_wind_gust_meters_per_second{location="Bangkok",q="Bangkok,TH",reading_id="1609350",reading_lat="13.75",reading_lon="100.5167",reading_name="Bangkok"} 0.31

# HELP owm_query_success Whether the most recent query for a location's weather succeeded (0 or 1)
# TYPE owm_query_success gauge
owm_query_success{q="New York, NY,US"} 1
owm_query_success{q="Bangkok,TH"} 1
owm_query_success{lat="-0.829278",lon="-0.829278",display_name="The Galapagos"} 1
owm_query_success{id="3936456"} 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{quantile="0"} 59
owm_api_call_time_milliseconds{quantile="0.5"} 58.997791357811785
owm_api_call_time_milliseconds{quantile="0.9"} 61.99786870677149
owm_api_call_time_milliseconds{quantile="0.95"} 61.99786870677149
owm_api_call_time_milliseconds{quantile="0.99"} 61.99786870677149
owm_api_call_time_milliseconds{quantile="0.999"} 61.99786870677149
owm_api_call_time_milliseconds{quantile="1"} 65
owm_api_call_time_milliseconds_sum 1941
owm_api_call_time_milliseconds_count 20

获取 OpenWeatherMap API 密钥

要获取 API 密钥,请访问 https://openweathermap.org/home/sign_in 登录或创建账户。登录后,从右上角菜单栏选择您的用户名,然后选择 我的 API 密钥。使用 创建密钥 表单创建一个新的密钥。

依赖关系

~19–31MB
~578K SLoC