2
0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01:00
contrib-munin/plugins/bacula/bacula_sd

144 lines
4.6 KiB
Plaintext
Raw Normal View History

2009-02-09 19:05:42 +01:00
#!/usr/bin/python
# Copyright (C) 2009 Andreas Thienemann <andreas@bawue.net>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Library General Public License as published by
# the Free Software Foundation; version 2 only
#
# 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 Library General Public License for more details.
#
# You should have received a copy of the GNU Library 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.
#
2018-03-27 04:46:21 +02:00
#
2009-02-09 19:05:42 +01:00
#
# Munin Plugin to get storage device throughput for Bacula by parsing the bconsole
# output.
#
# Parameters:
#
2018-03-27 04:46:21 +02:00
# config (required)
# autoconf (optional - only used by munin-config)
#
2009-02-09 19:05:42 +01:00
#
# Magic markers (optional - only used by munin-config and some
# installation scripts):
#
2018-03-27 04:46:21 +02:00
# #%# family=contrib
# #%# capabilities=autoconf
2009-02-09 19:05:42 +01:00
import subprocess
import sys
import re
import os
2018-03-27 04:46:21 +02:00
2009-02-09 19:05:42 +01:00
def parse_devices():
2018-03-27 04:46:21 +02:00
""" Parse the bconsole output once to get the device names """
2009-02-09 19:05:42 +01:00
2018-03-27 04:46:21 +02:00
bconsole = subprocess.Popen("bconsole", stdin=subprocess.PIPE, stdout=subprocess.PIPE)
stdout, stderr = bconsole.communicate("status\n2")
2009-02-09 19:05:42 +01:00
2018-03-27 04:46:21 +02:00
devs = []
2009-02-09 19:05:42 +01:00
2018-03-27 04:46:21 +02:00
# Hold the line numbers for devices
dev_line = []
input_lines = stdout.split("\n")
2009-02-09 19:05:42 +01:00
2018-03-27 04:46:21 +02:00
for line, i in zip(input_lines, range(0, len(input_lines))):
if line.startswith("Connecting to Storage daemon "):
hostname = line.split()[-1].split(":")[0]
if line.startswith("Device \""):
dev_line.append(i)
2009-02-09 19:05:42 +01:00
2018-03-27 04:46:21 +02:00
for pos in dev_line:
# Get the device name
dev_name = input_lines[pos].split()[1][1:-1]
dev_dev = input_lines[pos].split()[2][1:-1]
dev_dev_clean = re.sub("^[^A-Za-z_]", "_", dev_dev, 1)
dev_dev_clean = re.sub("[^A-Za-z0-9_]", "_", dev_dev_clean, 0)
devs.append([dev_name, dev_dev, dev_dev_clean])
2009-02-09 19:05:42 +01:00
2018-03-27 04:46:21 +02:00
return hostname, devs
2009-02-09 19:05:42 +01:00
def parse():
2018-03-27 04:46:21 +02:00
""" Parse the bconsole output """
2009-02-09 19:05:42 +01:00
2018-03-27 04:46:21 +02:00
bconsole = subprocess.Popen("bconsole", stdin=subprocess.PIPE, stdout=subprocess.PIPE)
stdout, stderr = bconsole.communicate("status\n2")
2009-02-09 19:05:42 +01:00
2018-03-27 04:46:21 +02:00
devstats = []
2009-02-09 19:05:42 +01:00
2018-03-27 04:46:21 +02:00
# Hold the line numbers for devices
dev_line = []
input_lines = stdout.split("\n")
2009-02-09 19:05:42 +01:00
2018-03-27 04:46:21 +02:00
for line, i in zip(input_lines, range(0, len(input_lines))):
if line.startswith("Device \""):
dev_line.append(i)
2009-02-09 19:05:42 +01:00
2018-03-27 04:46:21 +02:00
for pos in dev_line:
# Get the device name
dev_dev = input_lines[pos].split()[2][1:-1]
dev_dev_clean = re.sub("^[^A-Za-z_]", "_", dev_dev, 1)
dev_dev_clean = re.sub("[^A-Za-z0-9_]", "_", dev_dev_clean, 0)
2009-02-09 19:05:42 +01:00
2018-03-27 04:46:21 +02:00
# Get the current bytes
if input_lines[pos].endswith("is mounted with:"):
bytes_count_text = input_lines[pos+5].split()[1].split("=")[1].replace(",", "")
try:
bytes_count = long(bytes_count_text)
except NameError:
bytes_count = int(bytes_count_text)
devstats.append([dev_dev, dev_dev_clean, bytes_count])
else:
devstats.append([dev_dev, dev_dev_clean, 0])
2009-02-09 19:05:42 +01:00
2018-03-27 04:46:21 +02:00
return devstats
2009-02-09 19:05:42 +01:00
def print_config():
2018-03-27 04:46:21 +02:00
hostname, devstats = parse_devices()
print("graph_title Bacula Storage Daemon throughput")
print("graph_vlabel bytes per ${graph_period}")
print("graph_args --base 1024 -l 0")
print("graph_scale yes")
print("graph_info Bacula Storage Daemon througput measurement based on written bytes. "
"This may be somewhat inacurate whenever a tape is changed.")
print("graph_category backup")
print("graph_order", " ".join([dev[2] for dev in devstats]))
print()
if (os.getenv("report_hostname") is not None
and (os.getenv("report_hostname").upper() in ["YES", "TRUE", "1", "Y"])):
print("host_name", hostname)
for dev in devstats:
print("%s.label %s" % (dev[2], dev[1]))
print("%s.type DERIVE" % (dev[2]))
print("%s.min 0" % (dev[2]))
# print("%s.max %s" % (dev[2], str(1024*1024*1024*16)))
# print("%s.cdef up,8,*" (dev[2]))
sys.exit(0)
2009-02-09 19:05:42 +01:00
if "config" in sys.argv[1:]:
2018-03-27 04:46:21 +02:00
print_config()
2009-02-09 19:05:42 +01:00
elif "autoconf" in sys.argv[1:]:
2018-03-27 04:46:21 +02:00
for directory in os.getenv("PATH").split(":"):
for root, dirs, files in os.walk(directory):
if "bconsole" in files:
print("yes")
sys.exit(0)
print("no")
sys.exit(0)
2009-02-09 19:05:42 +01:00
elif "suggest" in sys.argv[1:]:
2018-03-27 04:46:21 +02:00
sys.exit(1)
2009-02-09 19:05:42 +01:00
else:
2018-03-27 04:46:21 +02:00
for dev in parse():
print("%s.value %s" % (dev[1], dev[2]))