#!/bin/sh
#
# Plugin to monitor queue length of tiles submited for rendering in renderd
#
# Parameters:
#
# 	config   (required)
# 	autoconf (optional - used by munin-config)
#
# Copyright (c) 2007 - 2023 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 queue length'
  echo 'graph_args --base 1000 -l 0'
  echo 'graph_vlabel metatiles'
  echo 'graph_category renderd'
  echo 'reqPrio.label Priority request Queue'
  echo 'reqPrio.type GAUGE'
  echo 'reqPrio.max 100'
  echo 'req.label Request Queue'
  echo 'req.type GAUGE'
  echo 'req.max 100'
  echo 'reqLow.label Low priority request Queue'
  echo 'reqLow.type GAUGE'
  echo 'reqLow.max 100'
  echo 'dirty.label Dirty Queue'
  echo 'dirty.type GAUGE'
  echo 'dirty.max 1000'
  echo 'reqBulk.label Bulk request Queue'
  echo 'reqBulk.type GAUGE'
  echo 'reqBulk.max 100'
  exit 0
fi

reqlength=$(sed -e '/^ReqQueueLength/!d' -e 's/.*: //' -e q /run/renderd/renderd.stats)
reqpriolength=$(sed -e '/^ReqPrioQueueLength/!d' -e 's/.*: //' -e q /run/renderd/renderd.stats)
reqpriolowlength=$(sed -e '/^ReqLowQueueLength/!d' -e 's/.*: //' -e q /run/renderd/renderd.stats)
reqbulklength=$(sed -e '/^ReqBulkQueueLength/!d' -e 's/.*: //' -e q /run/renderd/renderd.stats)
dirtlength=$(sed -e '/^DirtQueueLength/!d' -e 's/.*: //' -e q /run/renderd/renderd.stats)

echo "reqPrio.value " $reqpriolength
echo "req.value " $reqlength
echo "reqLow.value " $reqpriolowlength
echo "dirty.value " $dirtlength
echo "reqBulk.value " $reqbulklength
