Merge pull request #469 from mrueg/prometheus2
prometheus: Add help descriptions, improve metric names
This commit is contained in:
commit
a3a64a6125
1 changed files with 28 additions and 20 deletions
|
|
@ -3,34 +3,42 @@ Rendering weather data in the Prometheus format.
|
|||
|
||||
"""
|
||||
|
||||
EXPORTED_FIELDS = [
|
||||
"FeelsLikeC", "FeelsLikeF", "cloudcover", "humidity",
|
||||
"precipMM", "pressure", "temp_C", "temp_F", "uvIndex",
|
||||
"visibility", "winddirDegree", "windspeedKmph",
|
||||
"windspeedMiles",
|
||||
]
|
||||
|
||||
def _render_current(data):
|
||||
EXPORTED_FIELDS = {
|
||||
"FeelsLikeC":("Feels Like Temperature in Celsius", "temperature_feels_like_celsius"),
|
||||
"FeelsLikeF":("Feels Like Temperature in Fahrenheit", "temperature_feels_like_fahrenheit"),
|
||||
"cloudcover":("Cloud Coverage in Percent", "cloudcover_percentage"),
|
||||
"humidity":("Humidity in Percent", "humidity_percentage"),
|
||||
"precipMM":("Precipitation (Rainfall) in mm", "precipitation_mm"),
|
||||
"pressure":("Air pressure in hPa", "pressure_hpa"),
|
||||
"temp_C":("Temperature in Celsius", "temperature_celsius"),
|
||||
"temp_F":("Temperature in Fahrenheit", "temperature_fahrenheit"),
|
||||
"uvIndex":("Ultaviolet Radiation Index", "uv_index"),
|
||||
"visibility":("Visible Distance in Kilometres", "visibility"),
|
||||
"winddirDegree":("Wind Direction in Degree", "winddir_degree"),
|
||||
"windspeedKmph":("Wind Speed in Kilometres per Hour", "windspeed_kmph"),
|
||||
"windspeedMiles":("Wind Speed in Miles per Hour", "windspeed_mph"),
|
||||
}
|
||||
|
||||
EXPORTED_FIELDS_DESC = {
|
||||
"weatherDesc":("Weather Description", "weather_desc"),
|
||||
"winddir16Point":("Wind Direction on a 16-wind compass rose", "winddir_16_point"),
|
||||
}
|
||||
|
||||
def _render_crurent(data):
|
||||
|
||||
output = []
|
||||
current_condition = data["current_condition"][0]
|
||||
for field in EXPORTED_FIELDS:
|
||||
try:
|
||||
output.append("%s{forecast=\"0h\"} %s" % (field, current_condition[field]))
|
||||
output.append("# %s\n%s{forecast=\"0h\"} %s" % (EXPORTED_FIELDS[field][0], EXPORTED_FIELDS[field][1], current_condition[field]))
|
||||
except IndexError:
|
||||
pass
|
||||
for field in EXPORTED_FIELDS_DESC:
|
||||
try:
|
||||
output.append("# %s\n%s{forecast=\"0h\", description=\"%s\"} 1" % EXPORTED_FIELDS_DESC[field][0], EXPORTED_FIELDS_DESC[field][1], current_condition[field])
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
try:
|
||||
weather_desc = current_condition["weatherDesc"][0]["value"]
|
||||
output.append("weatherDesc{forecast=\"0h\", description=\"%s\"} 1" % weather_desc)
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
try:
|
||||
winddir16point = current_condition["winddir16Point"]
|
||||
output.append("winddir16Point{forecast=\"0h\", description=\"%s\"} 1" % winddir16point)
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
return "\n".join(output)+"\n"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue