1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-09-19 09:03:20 +00:00

p: updating openweather_ to be multigraph

Now it graph all the values coming from the API
This commit is contained in:
Steve Schnepp 2015-01-01 14:09:08 +00:00
parent c8f30b0956
commit 2c5943e469

View file

@ -5,48 +5,135 @@
# This part is taken from the original plugin # This part is taken from the original plugin
# Example usage: # Example usage:
# Do # Do
# ln -s /path/to/openweather_ openweather_<type>_<id> # ln -s /path/to/openweather_ openweather_<query_string>
# where <type> is currently ignored (formerly one of # where <query_string> is either a search query "q_Paris" or
# [station, weather]) and <id> is a suitable # or an id search "id_2988507"
# city id from http://openweathermap.org/
# These parameters translate directly into a URL formed like this:
# http://openweathermap.org/data/<api>/weather?id=<id>
# #
# Example config: # These parameters translate directly into a URL formed like this:
# [openweather_*] # http://api.openweathermap.org/data/<api>/weather?<query_string>
# #
entity_id=${0##*_} query_string=$(printf '%s' "${0#*_}" | tr '_' '=')
TMPFILE=$(mktemp) TMPFILE=$(mktemp)
trap 'rm -f $TMPFILE' EXIT trap 'rm -f $TMPFILE' EXIT
# API returns temp in K, we have to convert it in C
KELVIN_BIAS=273 KELVIN_BIAS=273
curl -s "http://openweathermap.org/data/2.5/weather?id=${entity_id}" | tr ':{},' ' \n' > $TMPFILE curl -s "http://api.openweathermap.org/data/2.5/weather?mode=xml&${query_string}" > $TMPFILE
while read KEY VALUE EXTRA CITY=$(fgrep "<city id=" $TMPFILE | tr -sc '[:alnum:]' ' ' | cut -d " " -f 6)
do
[ "$KEY" = '"main"' ] && KEY=$VALUE && VALUE=$EXTRA
[ "$KEY" = '"temp"' ] && {
VALUE=${VALUE%%.*}
[ "$1" != "config" ] && echo "temp.value $(( $VALUE - $KELVIN_BIAS ))"
}
[ "$KEY" = '"name"' ] && { if [ "$1" = "config" ];
[ "$1" = "config" ] && { then
cat <<- EOF cat <<- EOF
graph_title Temperature in ${VALUE} multigraph $0
graph_args --lower-limit 0 graph_title Temperature in ${CITY}
graph_vlabel Celsius graph_vlabel Celsius
graph_category weather graph_category weather
graph_scale no graph_info This graph show the temperature in ${CITY}
graph_info This graph show the temperature in ${VALUE} temp_avg.label avg
temp.label temperature temp_avg.cdef $KELVIN_BIAS,-
temp.info Temperature in degree Celsius
temp.type GAUGE multigraph $0.temp
graph_title Temperature in ${CITY}
graph_vlabel Celsius
graph_category weather
graph_info This graph show the temperature in ${CITY}
temp_avg.label avg
temp_avg.cdef $KELVIN_BIAS,-
temp_min.label min
temp_min.cdef $KELVIN_BIAS,-
temp_max.label max
temp_max.cdef $KELVIN_BIAS,-
multigraph $0.humidity
graph_title Humidity in ${CITY}
graph_vlabel %
graph_category weather
graph_info This graph show the humidity in ${CITY}
humidity.label humidity
multigraph $0.pressure
graph_title Pressure in ${CITY}
graph_vlabel hPa
graph_category weather
graph_info This graph show the pressure in ${CITY}
pressure.label pressure
multigraph $0.wind_speed
graph_title Wind Speed in ${CITY}
graph_vlabel m/s
graph_category weather
graph_info This graph show the wind speed in ${CITY}
speed.label wind speed
multigraph $0.wind_direction
graph_title Wind direction in ${CITY}
graph_vlabel m/s
graph_category weather
graph_info This graph show the wind direction in ${CITY}
direction.label wind direction
EOF EOF
}
} # Continue if dirty config is enabled
done < $TMPFILE [ "$MUNIN_CAP_DIRTYCONFIG" = 1 ] || exit 0
fi
TEMP_AVG=$(fgrep "<temperature value=" $TMPFILE | tr -sc '[:alnum:].' ' ' | cut -d " " -f 4)
TEMP_MIN=$(fgrep "<temperature value=" $TMPFILE | tr -sc '[:alnum:].' ' ' | cut -d " " -f 6)
TEMP_MAX=$(fgrep "<temperature value=" $TMPFILE | tr -sc '[:alnum:].' ' ' | cut -d " " -f 8)
HUMIDITY=$(fgrep "<humidity value=" $TMPFILE | tr -sc '[:alnum:].' ' ' | cut -d " " -f 4)
PRESSURE=$(fgrep "<pressure value=" $TMPFILE | tr -sc '[:alnum:].' ' ' | cut -d " " -f 4)
WD_SPEED=$(fgrep "<speed value=" $TMPFILE | tr -sc '[:alnum:].' ' ' | cut -d " " -f 4)
WD_DIREC=$(fgrep "<direction value=" $TMPFILE | tr -sc '[:alnum:].' ' ' | cut -d " " -f 4)
cat <<- EOF
multigraph $0
temp_avg.value $TEMP_AVG
multigraph $0.temp
temp_avg.value $TEMP_AVG
temp_min.value $TEMP_MIN
temp_max.value $TEMP_MAX
multigraph $0.humidity
humidity.value $HUMIDITY
multigraph $0.pressure
pressure.value $PRESSURE
multigraph $0.wind_speed
speed.value $WD_SPEED
multigraph $0.wind_direction
direction.label $WD_DIREC
EOF
exit 0 exit 0
: <<EOF
<?xml version="1.0" encoding="utf-8"?>
<current>
<city id="2988507" name="Paris">
<coord lon="2.35" lat="48.85"/>
<country>FR</country>
<sun rise="2015-01-01T07:43:52" set="2015-01-01T16:04:40"/>
</city>
<temperature value="275.099" min="275.099" max="275.099" unit="kelvin"/>
<humidity value="100" unit="%"/>
<pressure value="1038.33" unit="hPa"/>
<wind>
<speed value="2.46" name="Light breeze"/>
<direction value="190.509" code="S" name="South"/>
</wind>
<clouds value="0" name="clear sky"/>
<visibility/>
<precipitation mode="no"/>
<weather number="800" value="Sky is Clear" icon="01d"/>
<lastupdate value="2015-01-01T11:42:50"/>
</current>
EOF