#!/bin/sh
#
# Copyright (c) 2015 Antonio Terceiro
#
# 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; version 2 dated June,
# 1991.
#
# 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, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
# Plugin to monitor the number of packages processed by a debci worker

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

	echo "graph_title packages processed by worker"
	echo 'graph_args --base 1000 -l 0'
	echo 'graph_vlabel Packages processed by debci-worker'
	echo 'graph_category debci'
	echo 'graph_info This graph shows the number of packages that has been processed by a given worker.'

	echo "debci_packages_processed.label Packages"
	echo "debci_packages_processed.info Number of packages processed"
	echo "debci_packages_processed.draw AREASTACK"

	exit 0
fi

processed=$(journalctl '--unit=debci-publisher.service' --since=-5m | grep -c 'debci\[[0-9]\+\]: \S\+ \S\+ \S\+ publishing$')
echo "debci_packages_processed.value $processed"
