Benjamin Renard commited on 2013-12-03 09:19:04
Showing 3 changed files, with 224 additions and 0 deletions.
... | ... |
@@ -0,0 +1 @@ |
1 |
+*~ |
... | ... |
@@ -0,0 +1,62 @@ |
1 |
+Ceph Cluster status plugin for Munin |
|
2 |
+==================================== |
|
3 |
+ |
|
4 |
+Usage |
|
5 |
+----- |
|
6 |
+ |
|
7 |
+$0 config |
|
8 |
+ show graphs that should be generated |
|
9 |
+ |
|
10 |
+$0 |
|
11 |
+ show the data for the graphs |
|
12 |
+ |
|
13 |
+This plugin have 3 modes : |
|
14 |
+ |
|
15 |
+ - ceph_usage : graph data/allocated and total space cluster usage |
|
16 |
+ - ceph_osd : graph ceph OSDs number (total/UP/IN) |
|
17 |
+ - ceph_mon : graph ceph MONs number (total/UP) |
|
18 |
+ |
|
19 |
+To install this plugin : |
|
20 |
+ |
|
21 |
+ ln -s /path/to/ceph_status /etc/munin/plugins/ceph_usage |
|
22 |
+ ln -s /path/to/ceph_status /etc/munin/plugins/ceph_osd |
|
23 |
+ ln -s /path/to/ceph_status /etc/munin/plugins/ceph_mon |
|
24 |
+ |
|
25 |
+If you are using cephx, you have to manually configure it : |
|
26 |
+ |
|
27 |
+- You have to create ceph user first : |
|
28 |
+ |
|
29 |
+ ceph auth get-or-create client.nagios mon 'allow r' > /etc/ceph/ceph.client.nagios.keyring |
|
30 |
+ chown munin: /etc/ceph/ceph.client.nagios.keyring |
|
31 |
+ chmod 400 /etc/ceph/ceph.client.nagios.keyring |
|
32 |
+ |
|
33 |
+- After, you have to configure ceph_status execution : |
|
34 |
+ |
|
35 |
+ [ceph_*] |
|
36 |
+ user munin |
|
37 |
+ env.ceph_id munin |
|
38 |
+ env.ceph_keyring /etc/ceph/ceph.client.munin.keyring |
|
39 |
+ |
|
40 |
+ |
|
41 |
+Author |
|
42 |
+------ |
|
43 |
+ |
|
44 |
+Benjamin Renard <brenard@zionetrix.net> |
|
45 |
+ |
|
46 |
+License |
|
47 |
+------- |
|
48 |
+ |
|
49 |
+Copyright (C) 2013 Benjamin Renard |
|
50 |
+ |
|
51 |
+This program is free software; you can redistribute it and/or |
|
52 |
+modify it under the terms of the GNU General Public License version 2 |
|
53 |
+as published by the Free Software Foundation. |
|
54 |
+ |
|
55 |
+This program is distributed in the hope that it will be useful, |
|
56 |
+but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
57 |
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
58 |
+GNU General Public License for more details. |
|
59 |
+ |
|
60 |
+You should have received a copy of the GNU General Public License |
|
61 |
+along with this program; if not, write to the Free Software |
|
62 |
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
... | ... |
@@ -0,0 +1,161 @@ |
1 |
+#!/usr/bin/python |
|
2 |
+ |
|
3 |
+""" |
|
4 |
+: << =cut |
|
5 |
+ |
|
6 |
+=head1 NAME |
|
7 |
+ |
|
8 |
+Ceph Cluster status plugin for Munin by Benjamin Renard <brenard@zionetrix.net> |
|
9 |
+ |
|
10 |
+=head1 NOTES |
|
11 |
+ |
|
12 |
+Usage: |
|
13 |
+ |
|
14 |
+$0 config |
|
15 |
+ show graphs that should be generated |
|
16 |
+ |
|
17 |
+$0 |
|
18 |
+ show the data for the graphs |
|
19 |
+ |
|
20 |
+This plugin have 3 modes : |
|
21 |
+ |
|
22 |
+ - ceph_usage : graph data/allocated and total space cluster usage |
|
23 |
+ - ceph_osd : graph ceph OSDs number (total/UP/IN) |
|
24 |
+ - ceph_mon : graph ceph MONs number (total/UP) |
|
25 |
+ |
|
26 |
+To install this plugin : |
|
27 |
+ |
|
28 |
+ ln -s /path/to/ceph_status /etc/munin/plugins/ceph_usage |
|
29 |
+ ln -s /path/to/ceph_status /etc/munin/plugins/ceph_osd |
|
30 |
+ ln -s /path/to/ceph_status /etc/munin/plugins/ceph_mon |
|
31 |
+ |
|
32 |
+If you are using cephx, you have to manually configure it : |
|
33 |
+ |
|
34 |
+- You have to create ceph user first : |
|
35 |
+ |
|
36 |
+ ceph auth get-or-create client.nagios mon 'allow r' > /etc/ceph/ceph.client.nagios.keyring |
|
37 |
+ chown munin: /etc/ceph/ceph.client.nagios.keyring |
|
38 |
+ chmod 400 /etc/ceph/ceph.client.nagios.keyring |
|
39 |
+ |
|
40 |
+- After, you have to configure ceph_status execution : |
|
41 |
+ |
|
42 |
+ [ceph_*] |
|
43 |
+ user munin |
|
44 |
+ env.ceph_id munin |
|
45 |
+ env.ceph_keyring /etc/ceph/ceph.client.munin.keyring |
|
46 |
+ |
|
47 |
+ |
|
48 |
+=head1 AUTHOR |
|
49 |
+ |
|
50 |
+Benjamin Renard <brenard@zionetrix.net> |
|
51 |
+ |
|
52 |
+=head1 LICENSE |
|
53 |
+ |
|
54 |
+Copyright (C) 2013 Benjamin Renard |
|
55 |
+ |
|
56 |
+This program is free software; you can redistribute it and/or |
|
57 |
+modify it under the terms of the GNU General Public License version 2 |
|
58 |
+as published by the Free Software Foundation. |
|
59 |
+ |
|
60 |
+This program is distributed in the hope that it will be useful, |
|
61 |
+but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
62 |
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
63 |
+GNU General Public License for more details. |
|
64 |
+ |
|
65 |
+You should have received a copy of the GNU General Public License |
|
66 |
+along with this program; if not, write to the Free Software |
|
67 |
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
68 |
+ |
|
69 |
+=head1 MAGIC MARKERS |
|
70 |
+ |
|
71 |
+ #%# capabilities=config |
|
72 |
+ |
|
73 |
+=cut |
|
74 |
+""" |
|
75 |
+ |
|
76 |
+import sys,os |
|
77 |
+ |
|
78 |
+cmd=sys.argv[0].split('/') |
|
79 |
+cmd=cmd[len(cmd)-1] |
|
80 |
+if cmd=='ceph_osd': |
|
81 |
+ mode='osd' |
|
82 |
+elif cmd=="ceph_usage": |
|
83 |
+ mode='usage' |
|
84 |
+elif cmd=="ceph_mon": |
|
85 |
+ mode='mon' |
|
86 |
+else: |
|
87 |
+ print "Plugin name %s not recognized. Valid names : ceph_osd, ceph_usage or ceph_mon" % cmd |
|
88 |
+ sys.exit(1) |
|
89 |
+ |
|
90 |
+if (sys.argv.__len__()>1) and (sys.argv[1]=="config"): |
|
91 |
+ if mode=='usage': |
|
92 |
+ print """graph_title Ceph usage |
|
93 |
+graph_category ceph |
|
94 |
+graph_vlabel bytes |
|
95 |
+graph_info Ceph cluster usage |
|
96 |
+graph_args --base 1000 -l 0 |
|
97 |
+capacity.label Capacity |
|
98 |
+allocated.label Allocated |
|
99 |
+allocated.draw AREA |
|
100 |
+data.label Data |
|
101 |
+data.draw AREA""" |
|
102 |
+ elif mode=='osd': |
|
103 |
+ print """graph_title Ceph OSDs |
|
104 |
+graph_category ceph |
|
105 |
+graph_info CEPH OSDs |
|
106 |
+graph_args -l 0 |
|
107 |
+osds.label Num OSDs |
|
108 |
+osds_up.label OSDs UP |
|
109 |
+osds_in.label OSDs IN""" |
|
110 |
+ elif mode=='mon': |
|
111 |
+ print """graph_title Ceph MONs |
|
112 |
+graph_category ceph |
|
113 |
+graph_info CEPH MONs |
|
114 |
+graph_args -l 0 |
|
115 |
+mon.label Num MONs |
|
116 |
+mon_up.label MONs UP""" |
|
117 |
+else: |
|
118 |
+ import subprocess,json |
|
119 |
+ if 'ceph_bin' in os.environ: |
|
120 |
+ ceph_cmd=[os.environ['ceph_bin']] |
|
121 |
+ else: |
|
122 |
+ ceph_cmd=['/usr/bin/ceph'] |
|
123 |
+ |
|
124 |
+ if not os.path.exists(ceph_cmd[0]): |
|
125 |
+ print >> sys.stderr, 'ERROR : Ceph binary %s does not exists' % ceph_cmd[0] |
|
126 |
+ sys.exit(1) |
|
127 |
+ |
|
128 |
+ if 'ceph_id' in os.environ: |
|
129 |
+ ceph_cmd.append("--id") |
|
130 |
+ ceph_cmd.append(os.environ['ceph_id']) |
|
131 |
+ if 'ceph_keyring' in os.environ: |
|
132 |
+ ceph_cmd.append("--keyring") |
|
133 |
+ ceph_cmd.append(os.environ['ceph_keyring']) |
|
134 |
+ |
|
135 |
+ ceph_cmd.append('status') |
|
136 |
+ ceph_cmd.append('--format=json') |
|
137 |
+ |
|
138 |
+ p = subprocess.Popen(ceph_cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE) |
|
139 |
+ output, err = p.communicate() |
|
140 |
+ if output: |
|
141 |
+ data=json.loads(output) |
|
142 |
+ |
|
143 |
+ if mode=='usage': |
|
144 |
+ if 'pgmap' not in data: |
|
145 |
+ print >> sys.stderr, "Error reading pgmap status" |
|
146 |
+ sys.ext(1) |
|
147 |
+ print "capacity.value %s\nallocated.value %s\ndata.value %s" % (data['pgmap']['bytes_total'],data['pgmap']['bytes_used'],data['pgmap']['data_bytes']) |
|
148 |
+ elif mode=='osd': |
|
149 |
+ if 'osdmap' in data and 'osdmap' in data['osdmap']: |
|
150 |
+ print "osds.value %s\nosds_up.value %s\nosds_in.value %s" % (data['osdmap']['osdmap']['num_osds'],data['osdmap']['osdmap']['num_up_osds'],data['osdmap']['osdmap']['num_in_osds']) |
|
151 |
+ else: |
|
152 |
+ print >> sys.stderr, "Error reading osdmap status" |
|
153 |
+ sys.ext(1) |
|
154 |
+ elif mode=='mon': |
|
155 |
+ print "mon.value %s\nmon_up.value %s" % (len(data['monmap']['mons']),len(data['health']['timechecks']['mons'])) |
|
156 |
+ else: |
|
157 |
+ if err: |
|
158 |
+ print >> sys.stderr, "Error reading ceph status" |
|
159 |
+ else: |
|
160 |
+ print >> sys.stderr, "Unknown error reading ceph status" |
|
161 |
+ sys.exit(1) |
|
0 | 162 |