#!/bin/sh
#
# Plugin to monitor the rendering throughput of Renderd
#
# Parameters:
#
# 	config   (required)
# 	autoconf (optional - used by munin-config)
#
# Copyright (c) 2007 - 2020 by mod_tile contributors (see AUTHORS file)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; If not, see http://www.gnu.org/licenses/.

if [ "$1" = "config" ]; then

  echo 'graph_title Renderd throughput'
  echo 'graph_args --base 1000 -l 0'
  echo 'graph_vlabel Metatiles per ${graph_period}'
  echo 'graph_category renderd'
  echo 'graph_info Displays the number of metatiles being rendered by renderd per ${graph_period}'
  echo 'req.label Request Queue'
  echo 'req.type DERIVE'
  echo 'req.min 0'
  echo 'req.draw AREA'
  echo 'req.info Throughput of Metatiles submitted for on the fly rendering'
  echo 'reqLow.label Low priority request Queue'
  echo 'reqLow.type DERIVE'
  echo 'reqLow.min 0'
  echo 'reqLow.draw STACK'
  echo 'reqLow.info Throughput of Metatiles submitted low priority for on the fly rendering'
  echo 'reqPrio.label Priority request Queue'
  echo 'reqPrio.type DERIVE'
  echo 'reqPrio.min 0'
  echo 'reqPrio.draw STACK'
  echo 'reqPrio.info Throughput of Metatiles submitted high priority for on the fly rendering'
  echo 'dirty.label Dirty Queue'
  echo 'dirty.type DERIVE'
  echo 'dirty.min 0'
  echo 'dirty.draw STACK'
  echo 'dirty.info Throughput of dirty Metatiles submitted for re-render'
  echo 'reqBulk.label Bulk request Queue'
  echo 'reqBulk.type DERIVE'
  echo 'reqBulk.min 0'
  echo 'reqBulk.draw STACK'
  echo 'reqBulk.info Throughput of Metatiles submitted with background priority'
  echo 'dropped.label Dropped (x20)'
  echo 'dropped.type DERIVE'
  echo 'dropped.min 0'
  echo 'dropped.draw LINE2'
  echo 'dropped.info Number of Tiles dropped due to queue overload (x20)'
  echo 'dropped.cdef dropped,20,/'
  exit 0
fi

reqprocessed=$(sed -e '/^ReqRendered/!d' -e 's/.*: //' -e q /run/renderd/renderd.stats)
reqprioprocessed=$(sed -e '/^ReqPrioRendered/!d' -e 's/.*: //' -e q /run/renderd/renderd.stats)
reqpriolowprocessed=$(sed -e '/^ReqLowRendered/!d' -e 's/.*: //' -e q /run/renderd/renderd.stats)
dirtprocessed=$(sed -e '/^DirtyRendered/!d' -e 's/.*: //' -e q /run/renderd/renderd.stats)
reqbulkprocessed=$(sed -e '/^ReqBulkRendered/!d' -e 's/.*: //' -e q /run/renderd/renderd.stats)
dropped=$(sed -e '/^DropedRequest/!d' -e 's/.*: //' -e q /run/renderd/renderd.stats)

echo "req.value " $reqprocessed
echo "reqLow.value " $reqpriolowprocessed
echo "reqPrio.value " $reqprioprocessed
echo "dirty.value " $dirtprocessed
echo "reqBulk.value " $reqbulkprocessed
echo "dropped.value " $dropped

#  LocalWords:  reqprocessed ReqRendered dirtprocessed DirtyRendered req
#  LocalWords:  DropedRequest
