Projet

Général

Profil

Révision 71637f44

ID71637f44e7a75b2a8470b14f7b6f5334c14001ee
Parent 0cef46c0
Enfant aedea208

Ajouté par Jort Bloem il y a environ 12 ans

Initial checking of ceph-osd-info. Dumps all ceph values into munin.

Voir les différences:

plugins/ceph/ceph-osd-info
1
#!/usr/bin/python
2

  
3
"""
4
: << =cut
5

  
6
=head1 NAME
7

  
8
ceph osd stats by BTG
9

  
10
=head1 NOTES
11

  
12
I have no idea what I'm doing here
13

  
14
Usage:
15

  
16
$0 config
17
	show graphs that should be generated
18

  
19
$0
20
	show the data for the graphs
21

  
22
Place this in /etc/munin/plugins/ and munin should find it.
23

  
24
You may need to add "timeout 240" to /etc/munin/munin-node.conf and restart
25

  
26
=head1 AUTHOR
27

  
28
Jort Bloem
29

  
30
=head1 EXCUSES
31

  
32
This is one of the first programs I wrote in Python. I got carried away
33
by Python's powerfull one-line commands. Just because you can, doesn't
34
mean you should. 
35

  
36
This program needs a rewrite, and if there were any problems with it,
37
I probably would.
38

  
39
=head1 LICENSE
40

  
41
Copyright (C) 2013 Business Technology Group (btg.co.nz)
42

  
43
Permission is granted to copy, distribute and/or modify this document
44
under the terms of the GNU Free Documentation License, Version 1.3
45
or any later version published by the Free Software Foundation;
46
with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
47
A copy of the license is included in the section entitled "GNU
48
Free Documentation License".
49

  
50
If you wish to use this code on any other terms, please contact us
51
with your needs, we'll do what we can. This may not include payment.
52
We don't bite.
53

  
54
=head1 MAGIC MARKERS
55

  
56
 #%# capabilities=config
57

  
58
=cut
59
"""
60

  
61
import socket,os,json,sys,re,glob,itertools
62

  
63
# this overides config values for specific graphs:
64
# "graphname.osd1":{"graph_title":"This is the graph for OSD 1!"}
65
# "graphname.osd*":{"graph_title":"This is one of the 'dig deeper' graphs!"}
66
# "graphname":{"graph_title":"This is my great graph!"}
67
#
68
# "graphname" overrides defaults, both for graphname and graphname.osd*
69
# "graphname.osd*" overrides graphname and defaults (for the sub-graphs), but cannot have the OSD number in it.
70
# "graphname.osd1" (or .osd2, or .osd3...) is the final setting for osd1 - may be needed if you want the number of the osd in it.
71
# if "graphname.osd*" and "graphname.osd1" are not used, all the settings will be the same as the parent graph,
72
#  except the title will have " - OSD 1" (or whichever osd it is) appended.
73
#
74
# Alternatively, "graph":None will hide a graph.
75

  
76
settings_graph={
77
#	"osd_opq":{"graph_title":"test"},
78
}
79

  
80

  
81
### BUG REPORT TODO README!
82
# If subgraph is true, then graphs for osd* are created individually.
83
# This causes the master (client) munin to take so long to update rrds that timeouts happen.
84
# Solutions:
85
# 1: set subgraph to false.
86
# 2: increase the timeout, wherever that is
87
# 3: return config, but no data, for individual graphs, so rrds aren't updated, then link individual rrds to their parent rrd.
88
# 4: change munin so which rrd file is used can be overridden
89
#
90
# option 1: add "timeout 240" to /etc/munin/munin-node.conf and restart
91

  
92
subgraphs=True
93

  
94
def read_osd(filename):
95
	s=socket.socket(socket.AF_UNIX,socket.SOCK_STREAM)
96
	s.connect(filename)
97
	s.send("\0\0\0\1")
98
	return json.loads(s.recv(10240)[4:])
99

  
100
def osd_list():
101
	return dict([(osd.split(".")[1],read_osd(osd)) for osd in glob.glob("/var/run/ceph/ceph-osd.*.asok")])
102

  
103
def collapse_one(inputdict,newkeyformat="%s_%s"):
104
	"""map inputdict["a"]["b"]=val to outdict["a_b"]=val"""
105
	outdict={}
106
	for outer in inputdict.items():
107
		#print "outer => %s %s" % outer
108
		for inner in outer[1].items():
109
			outdict[newkeyformat % (outer[0],inner[0])]=inner[1]
110
	return outdict
111

  
112
def sortlist(listtosort):
113
	listtosort=list(listtosort)
114
	listtosort.sort()
115
	return listtosort
116

  
117
# get and tidy osd_list, get derived keys.
118
data=osd_list()
119
osds=list(data.keys())
120
osds.sort()
121
for key in osds:
122
	data[key]=collapse_one(data[key])
123

  
124
graphlist=[item[1].keys() for item in data.items()]+settings_graph.keys()
125
graphlist=list(set(itertools.chain(*graphlist)))
126

  
127
if (sys.argv.__len__()>1) and (sys.argv[1]=="config"):
128
	for graph in graphlist:
129
		if (graph not in settings_graph):
130
			graphsettings={}
131
		elif settings_graph[graph]==None:
132
			continue
133
		else:
134
			graphsettings=settings_graph[graph]
135
		gr_simple=graph.replace("-","_").replace(":","_")
136
		gr_pretty=graph.replace("_"," ").title()
137
		gr=graph.replace("-","_").replace(":","_")
138
		graphdefaults={"graph_title":gr_pretty,"graph_vlabel":gr_pretty,"graph_category":"osd"}
139
		graphsettings=dict(graphdefaults.items()+graphsettings.items())
140
		print "multigraph %s" % (gr_simple)
141
		print "\n".join(["%s %s" % setting for setting in graphsettings.items()])
142
		for osd in sortlist(data.keys()):
143
			print "osd%s_%s.label osd %s" % (osd,gr_simple,osd)
144
		if subgraphs:
145
			for osd in sortlist(data.keys()):
146
				print "multigraph %s.osd%s" % (gr_simple,osd)
147
				thisrecord=dict(graphsettings.items()+[("graph_title","%s - OSD %s" % (graphsettings["graph_title"],osd),)])
148
				#print thisrecord
149
				if ("%s.osd*" % (graph) in settings_graph):
150
					thisrecord=dict(thisrecord.items()+settings_graph["%s.osd%s" % (graph,osd)].items())
151
				if ("%s.osd%s" % (graph,osd) in settings_graph):
152
					thisrecord=dict(thisrecord.items()+settings_graph["%s.osd%s" % (graph,osd)].items())
153
				print "\n".join(["%s %s" % setting for setting in thisrecord.items()])
154
				print "osd%s_%s.label osd %s" % (osd,gr_simple,osd)
155
else:
156
	for graph in graphlist:
157
		gr=graph.replace("-","_").replace(":","_")
158
		print "multigraph %s" % gr
159
		for osd in osds:
160
			if type(data[osd][graph])==dict:
161
				if data[osd][graph]["avgcount"]==0:
162
					data[osd][graph]="NaN"
163
				else:
164
					data[osd][graph]=float(data[osd][graph]["sum"])/float(data[osd][graph]["avgcount"])
165
		for osd in osds:
166
			value=data[osd][graph]
167
			print "osd%s_%s.value %s" % (osd,gr,data[osd][graph])
168
		if subgraphs:
169
			for osd in osds:
170
				print "multigraph %s.osd%s" % (gr,osd)
171
				print "osd%s_%s.value %s" % (osd,gr,data[osd][graph])
172

  

Formats disponibles : Unified diff