root/sd_speed

Revision 1, 4.0 kB (checked in by ixs, 16 years ago)

initial checkin

  • Property svn:executable set to *
Line 
1 #!/usr/bin/python
2
3 # Copyright (C) 2009 Andreas Thienemann <andreas@bawue.net>
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU Library General Public License as published by
7 # the Free Software Foundation; version 2 only
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU Library General Public License for more details.
13 #
14 # You should have received a copy of the GNU Library General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 #
18
19 #
20 # Munin Plugin to get storage device throughput for Bacula by parsing the bconsole
21 # output.
22 #
23 # Parameters:
24 #
25 #       config   (required)
26 #       autoconf (optional - only used by munin-config)
27 #
28
29 # Magic markers (optional - only used by munin-config and some
30 # installation scripts):
31 #
32 #%# family=contrib
33 #%# capabilities=autoconf
34
35 import subprocess
36 import time
37 import sys
38 import re
39 import os
40
41 def parse_devices():
42         """ Parse the bconsole output once to get the device names """
43
44         bconsole = subprocess.Popen("bconsole", stdin=subprocess.PIPE, stdout=subprocess.PIPE)
45         stdout, stderr = bconsole.communicate("status\n2")
46
47         devs = []
48
49         # Hold the line numbers for devices
50         dev_line = []
51         input = stdout.split("\n")
52
53         for line, i in zip(input, range(0, len(input))):
54                 if line.startswith("Connecting to Storage daemon "):
55                         hostname = line.split()[-1].split(":")[0]
56                 if line.startswith("Device \""):
57                         dev_line.append(i)
58
59         for pos in dev_line:
60                 # Get the device name
61                 dev_name = input[pos].split()[1][1:-1]
62                 dev_dev = input[pos].split()[2][1:-1]
63                 dev_dev_clean = re.sub("^[^A-Za-z_]", "_", dev_dev, 1)
64                 dev_dev_clean = re.sub("[^A-Za-z0-9_]", "_", dev_dev_clean, 0)
65                 devs.append([dev_name, dev_dev, dev_dev_clean])
66
67         return hostname, devs
68
69
70 def parse():
71         """ Parse the bconsole output """
72
73         bconsole = subprocess.Popen("bconsole", stdin=subprocess.PIPE, stdout=subprocess.PIPE)
74         stdout, stderr = bconsole.communicate("status\n2")
75
76         devstats = []
77
78         # Hold the line numbers for devices
79         dev_line = []
80         input = stdout.split("\n")
81
82         for line, i in zip(input, range(0, len(input))):
83                 if line.startswith("Device \""):
84                         dev_line.append(i)
85
86         for pos in dev_line:
87                 # Get the device name
88                 dev_dev = input[pos].split()[2][1:-1]
89                 dev_dev_clean = re.sub("^[^A-Za-z_]", "_", dev_dev, 1)
90                 dev_dev_clean = re.sub("[^A-Za-z0-9_]", "_", dev_dev_clean, 0)
91
92                 # Get the current bytes
93                 if input[pos].endswith("is mounted with:"):
94                         bytes = long(input[pos+5].split()[1].split("=")[1].replace(",", ""))
95                         devstats.append([dev_dev, dev_dev_clean, bytes])
96                 else:
97                         devstats.append([dev_dev, dev_dev_clean, 0])
98
99         return devstats
100
101
102 def print_config():
103         hostname, devstats = parse_devices()
104         print "graph_title Bacula Storage Daemon throughput"
105         print "graph_vlabel bytes per ${graph_period}"
106         print "graph_args --base 1024 -l 0"
107         print "graph_scale yes"
108         print "graph_info Bacula Storage Daemon througput measurement based on written bytes. This may be somewhat inacurate whenever a tape is changed."
109         print "graph_category Bacula"
110         print "graph_order",
111         for dev in devstats:
112                 print dev[2],
113         print
114         if os.getenv("report_hostname") is not None and \
115                 os.getenv("report_hostname").upper() in ["YES", "TRUE", "1", "Y"]:
116                 print "host_name", hostname
117         for dev in devstats:
118                 print "%s.label %s" % (dev[2], dev[1])
119                 print "%s.type DERIVE" % (dev[2])
120                 print "%s.min 0" % (dev[2])
121 #               print "%s.max %s" % (dev[2], str(1024*1024*1024*16))
122 #               print "%s.cdef up,8,*" (dev[2])
123         sys.exit(0)
124
125
126 if "config" in sys.argv[1:]:
127         print_config()
128 elif "autoconf" in sys.argv[1:]:
129         for dir in os.getenv("PATH").split(":"):
130                 for root, dirs, files in os.walk(dir):
131                         if "bconsole" in files:
132                                 print "yes"
133                                 sys.exit(0)
134         print "no"
135         sys.exit(1)
136 elif "suggest" in sys.argv[1:]:
137         sys.exit(1)
138 else:
139         for dev in parse():
140                 print "%s.value %s" % (dev[1], dev[2])
Note: See TracBrowser for help on using the browser.