1#!/bin/sh 2 3set -e 4 5: << =cut 6 7=head1 NAME 8 9etherpadlite_ - Monitor number of pads with etherpad-lite plugin called ep_pads_stats 10 11=head1 APPLICABLE SYSTEMS 12 13Etherpad-Lite instances 14 15=head1 CONFIGURATION 16 17Requires installed ep_pads_stats 18(https://www.npmjs.com/package/ep_pads_stats) plugin and an installed 19jq, a command-line json processor. 20 21This is a wildcard plugin. To monitor a etherpad-lite instance, link 22etherpadlite_<instancename> to this file. 23 24 [etherpadlite_instancename] 25 env.url http://127.0.0.1:9001/stats.json 26 27=head1 AUTHOR 28 29Copyright (C) 2020 Sebastian L. (https://momou.ch) 30 31=head1 LICENSE 32 33GPLv2 34 35=head1 MAGIC MARKERS 36 37 #%# family=manual 38 #%# capabilities=autoconf 39 40=cut 41 42. "$MUNIN_LIBDIR/plugins/plugin.sh" 43 44STATS_URL=${url:-"http://127.0.0.1:9001/stats.json"} 45INSTANCENAME="${0##*etherpadlite_}" 46CLEANINSTANCE="$(clean_fieldname "$INSTANCENAME")" 47 48print_json_data() { 49 local FIRST="$1" 50 [ -z "$FIRST" ] && exit 0 51 shift 1 52 for KEY in "$@"; do 53 VALUE=$(echo "$FIRST" | jq -cr ".$KEY") 54 echo "${KEY}.value $VALUE" 55 done 56} 57 58case $1 in 59 60 autoconf) 61 if [ -x /usr/bin/curl ]; then 62 if [ -x /usr/bin/jq ]; then 63 curl -s -f -m 2 -I "$STATS_URL" | grep -iq "Content-Type: application/json" && echo "yes" && exit 0 || echo "no (invalid or empty response from ep_pad_stats plugin ($STATS_URL))" && exit 0 64 else 65 echo "no (jq not found)" && exit 0 66 fi 67 else 68 echo "no (/usr/bin/curl not found)" && exit 0 69 fi 70 ;; 71 72 config) 73 74cat << EOM 75multigraph etherpadlite_$CLEANINSTANCE 76graph_title Etherlite-Pads on $CLEANINSTANCE instance 77graph_args --base 1000 -l 0 78graph_printf %.0lf 79graph_vlabel available pads 80graph_info number of available pads 81padsCount.label active pads 82padsCount.info number of active pads 83padsCount.min 0 84blankPads.label blank pads 85blankPads.info number of blank pads 86blankPads.min 0 87EOM 88 exit 0 89 ;; 90 91esac 92 93JSONSTATS=$(curl -s -f -m 2 "$STATS_URL") 94echo "multigraph etherpadlite_$CLEANINSTANCE" 95print_json_data "$JSONSTATS" padsCount blankPads 96