Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 142 lines (113 sloc) 4.556 kb
27d8b3ad »
2011-06-06 Monitor script for DRBD (drbd.org).
1 #!/usr/bin/env python
2
3 # Cloudkick plugin that monitors various DRBD parameters.
4 #
5 # Plugin arguments:
6 # 1. Minor device number of the DRBD device to monitor
7 #
8 # Author: Andrew Miklas / PagerDuty
9 # Copyright (c) 2011 PagerDuty, Inc. <andrew@pagerduty.com>
10 #
11 # MIT License:
12 # Permission is hereby granted, free of charge, to any person obtaining a copy
13 # of this software and associated documentation files (the "Software"), to deal
14 # in the Software without restriction, including without limitation the rights
15 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16 # copies of the Software, and to permit persons to whom the Software is
17 # furnished to do so, subject to the following conditions:
27209bb9 »
2011-06-06 Make script executable and print and error if drbd device can't be fo…
18 #
27d8b3ad »
2011-06-06 Monitor script for DRBD (drbd.org).
19 # The above copyright notice and this permission notice shall be included in
20 # all copies or substantial portions of the Software.
27209bb9 »
2011-06-06 Make script executable and print and error if drbd device can't be fo…
21 #
27d8b3ad »
2011-06-06 Monitor script for DRBD (drbd.org).
22 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28 # THE SOFTWARE.
29
30 import sys
31 import re
32
33 def parse_line(line):
34 d = {}
35
36 # Extract everything that looks line a k/v pair
37 for kv_pair in line.split():
38 l = kv_pair.split(':', 1)
39 if len(l) < 2:
40 continue
41 d[l[0]] = l[1]
42
43 return d
44
45
46 def read_proc_drbd(filename, device_num):
27209bb9 »
2011-06-06 Make script executable and print and error if drbd device can't be fo…
47 try:
48 info_fd = open(filename, "r")
49 except IOError:
50 print 'status err drbd device (%s) not found' % (filename)
51 sys.exit(1)
52
27d8b3ad »
2011-06-06 Monitor script for DRBD (drbd.org).
53 device_num = str(device_num)
54 dev_stats = {}
55
56 while True:
57 line = info_fd.readline()
58 if not line: break
59
60 match = re.search(r'^\s*(\d+):\s+(.*)$', line)
61 if not match:
62 continue
63 if match.groups()[0] == device_num:
64 # Device stat lines come in pairs. We've already got the
65 # first one, so read in the second.
66 for l in [match.groups()[1], info_fd.readline()]:
67 dev_stats.update(parse_line(l))
68 return dev_stats
69
70 # Device not found
71 return None
72
73
74 fmt_string = str
75 fmt_count = str
76
77 def fmt_size(val):
78 # DRBD sizes are in KiBytes
79 return str(int(val) * 1024)
80
81
82 METRICS = (
83 ("connection_state", "cs", "string", fmt_string),
84 ("disk_state", "ds", "string", fmt_string),
85 ("roles", "ro", "string", fmt_string),
27209bb9 »
2011-06-06 Make script executable and print and error if drbd device can't be fo…
86
27d8b3ad »
2011-06-06 Monitor script for DRBD (drbd.org).
87 ("network_send", "ns", "int", fmt_size),
88 ("network_send_rate", "ns", "gauge", fmt_size),
89 ("network_receive", "nr", "int", fmt_size),
90 ("network_receive_rate", "nr", "gauge", fmt_size),
91 ("disk_write", "dw", "int", fmt_size),
92 ("disk_write_rate", "dw", "gauge", fmt_size),
93 ("disk_read", "dr", "int", fmt_size),
94 ("disk_read_rate", "dr", "gauge", fmt_size),
95 ("out_of_sync", "oos", "int", fmt_size),
96 ("out_of_sync_rate", "oos", "gauge", fmt_size),
27209bb9 »
2011-06-06 Make script executable and print and error if drbd device can't be fo…
97
27d8b3ad »
2011-06-06 Monitor script for DRBD (drbd.org).
98 ("activity_log", "al", "int", fmt_count),
99 ("activity_log_rate", "al", "gauge", fmt_count),
100 ("bit_map", "bm", "int", fmt_count),
101 ("bit_map_rate", "bm", "gauge", fmt_count),
102
103 ("local_count", "lo", "int", fmt_count),
104 ("pending", "pe", "int", fmt_count),
105 ("unacknowledged", "ua", "int", fmt_count),
106 ("application_pending", "ap", "int", fmt_count),
107 ("epochs", "ep", "int", fmt_count)
108 )
109
110 OK_CONN_STATES = ("Connected", "VerifyS", "VerifyT")
111 WARN_CONN_STATES = ("StandAlone", "Disconnecting", "StartingSyncS", "StartingSyncT", "WFBitMapS", "WFBitMapT", "WFSyncUUID", "SyncSource", "SyncTarget", "PausedSyncS", "PausedSyncT")
112
113
114 if len(sys.argv) < 2:
115 print >>sys.stderr, "Usage: check_drbd.py drbd_dev_num"
116 exit(2)
117
118 device_num = sys.argv[1]
119 dev_stats = read_proc_drbd("/proc/drbd", device_num)
120
121 if dev_stats is None:
122 print >>sys.stderr, "Couldn't find DRBD device number %s" % device_num
123 sys.exit(1)
124
125 conn_state = dev_stats.get("cs")
126 if conn_state is None:
127 print >>sys.stderr, "Connection state can't be found!"
128 sys.exit(1)
129
130 if conn_state in OK_CONN_STATES:
131 print 'status ok Connection is in an OK state'
132 elif conn_state in WARN_CONN_STATES:
133 print 'status warn Connection is in a WARN state'
134 else:
135 print 'status err Connection is in a ERR state'
136
137 for m in METRICS:
138 if m[1] in dev_stats:
139 print "metric %s %s %s" % (m[0], m[2], m[3](dev_stats.get(m[1])))
140
141 sys.exit(0)
Something went wrong with that request. Please try again.