+

Last commit for ceph_status: 1d5efebce4c69f5991cd13440312cd3d0ea7c6f6

Fixed s/nagios/munin/ error in documentation

Benjamin Renard [2013-12-03 09:30:38]
Fixed s/nagios/munin/ error in documentation
#!/usr/bin/python

"""
: << =cut

=head1 NAME

Ceph Cluster status plugin for Munin by Benjamin Renard <brenard@zionetrix.net>

=head1 NOTES

Usage:

$0 config
	show graphs that should be generated

$0
	show the data for the graphs

This plugin have 3 modes :

  - ceph_usage : graph data/allocated and total space cluster usage
  - ceph_osd : graph ceph OSDs number (total/UP/IN)
  - ceph_mon : graph ceph MONs number (total/UP)

To install this plugin :

  ln -s /path/to/ceph_status /etc/munin/plugins/ceph_usage
  ln -s /path/to/ceph_status /etc/munin/plugins/ceph_osd
  ln -s /path/to/ceph_status /etc/munin/plugins/ceph_mon

If you are using cephx, you have to manually configure it :

- You have to create ceph user first :

  ceph auth get-or-create client.munin mon 'allow r' > /etc/ceph/ceph.client.munin.keyring
  chown munin: /etc/ceph/ceph.client.munin.keyring
  chmod 400 /etc/ceph/ceph.client.munin.keyring

- After, you have to configure ceph_status execution :

  [ceph_*]
      user munin
      env.ceph_id munin
      env.ceph_keyring /etc/ceph/ceph.client.munin.keyring


=head1 AUTHOR

Benjamin Renard <brenard@zionetrix.net>

=head1 LICENSE

Copyright (C) 2013 Benjamin Renard

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License version 2
as published by the Free Software Foundation.

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.

=head1 MAGIC MARKERS

 #%# capabilities=config

=cut
"""

import sys,os

cmd=sys.argv[0].split('/')
cmd=cmd[len(cmd)-1]
if cmd=='ceph_osd':
	mode='osd'
elif cmd=="ceph_usage":
	mode='usage'
elif cmd=="ceph_mon":
	mode='mon'
else:
	print "Plugin name %s not recognized. Valid names : ceph_osd, ceph_usage or ceph_mon" % cmd
	sys.exit(1)

if (sys.argv.__len__()>1) and (sys.argv[1]=="config"):
	if mode=='usage':
		print """graph_title Ceph usage
graph_category ceph
graph_vlabel bytes
graph_info Ceph cluster usage
graph_args --base 1000 -l 0
capacity.label Capacity
allocated.label Allocated
allocated.draw AREA
data.label Data
data.draw AREA"""
	elif mode=='osd':
		print """graph_title Ceph OSDs
graph_category ceph
graph_info CEPH OSDs
graph_args -l 0
osds.label Num OSDs
osds_up.label OSDs UP
osds_in.label OSDs IN"""
	elif mode=='mon':
		print """graph_title Ceph MONs
graph_category ceph
graph_info CEPH MONs
graph_args -l 0
mon.label Num MONs
mon_up.label MONs UP"""
else:
	import subprocess,json
	if 'ceph_bin' in os.environ:
		ceph_cmd=[os.environ['ceph_bin']]
	else:
		ceph_cmd=['/usr/bin/ceph']

	if not os.path.exists(ceph_cmd[0]):
		print >> sys.stderr, 'ERROR : Ceph binary %s does not exists' % ceph_cmd[0]
		sys.exit(1)

	if 'ceph_id' in os.environ:
		ceph_cmd.append("--id")
		ceph_cmd.append(os.environ['ceph_id'])
	if 'ceph_keyring' in os.environ:
		ceph_cmd.append("--keyring")
		ceph_cmd.append(os.environ['ceph_keyring'])

	ceph_cmd.append('status')
	ceph_cmd.append('--format=json')

	p = subprocess.Popen(ceph_cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
	output, err = p.communicate()
	if output:
		data=json.loads(output)

		if mode=='usage':
			if 'pgmap' not in data:
				print >> sys.stderr, "Error reading pgmap status"
				sys.ext(1)
			print "capacity.value %s\nallocated.value %s\ndata.value %s" % (data['pgmap']['bytes_total'],data['pgmap']['bytes_used'],data['pgmap']['data_bytes'])
		elif mode=='osd':
			if 'osdmap' in data and 'osdmap' in data['osdmap']:
				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'])
			else:
				print >> sys.stderr, "Error reading osdmap status"
				sys.ext(1)
		elif mode=='mon':
			print "mon.value %s\nmon_up.value %s" % (len(data['monmap']['mons']),len(data['health']['timechecks']['mons']))
	else:
		if err:
			print >> sys.stderr, "Error reading ceph status"
		else:
			print >> sys.stderr, "Unknown error reading ceph status"
		sys.exit(1)
ViewGit