@@ -43,7 +43,6 @@ class Ceph(AgentCheck):
43
43
44
44
def __init__ (self , name , init_config , instances ):
45
45
super (Ceph , self ).__init__ (name , init_config , instances )
46
- self ._octopus = False
47
46
48
47
def _collect_raw (self , ceph_cmd , ceph_cluster , instance ):
49
48
use_sudo = _is_affirmative (instance .get ('use_sudo' , False ))
@@ -58,6 +57,7 @@ def _collect_raw(self, ceph_cmd, ceph_cluster, instance):
58
57
ceph_args = '{} --cluster {}' .format (ceph_args , ceph_cluster )
59
58
60
59
raw = {}
60
+ # `mon_status` is only a valid command in versions of Ceph prior to `octopus` (released 2020-03-23)
61
61
for cmd in ('mon_status' , 'status' , 'df detail' , 'osd pool stats' , 'osd perf' , 'health detail' , 'osd metadata' ):
62
62
try :
63
63
args = '{} {} -fjson' .format (ceph_args , cmd )
@@ -73,24 +73,22 @@ def _collect_raw(self, ceph_cmd, ceph_cluster, instance):
73
73
mon_map = raw .get ('status' , {}).get ('monmap' )
74
74
if mon_map is None :
75
75
raise RuntimeError ("Could not detect Ceph release series" )
76
- if 'min_mon_release_name' in mon_map and mon_map ['min_mon_release_name' ] == 'octopus' :
77
- self .log .debug ("Detected octopus version of ceph..." )
78
- self ._octopus = True
79
- else :
80
- self ._octopus = False
81
76
82
77
return raw
83
78
84
79
def _extract_tags (self , raw , instance ):
85
80
tags = instance .get ('tags' , [])
86
81
fsid = None
87
- if self . _octopus :
82
+ try :
88
83
fsid = raw ['status' ]['fsid' ]
89
- elif 'mon_status' in raw :
90
- fsid = raw ['mon_status' ]['monmap' ]['fsid' ]
84
+ except KeyError :
85
+ if 'mon_status' in raw :
86
+ fsid = raw ['mon_status' ]['monmap' ]['fsid' ]
87
+ else :
88
+ self .log .debug ("Could not find fsid" )
89
+
90
+ if 'mon_status' in raw :
91
91
tags .append (self .NAMESPACE + '_mon_state:%s' % raw ['mon_status' ]['state' ])
92
- else :
93
- self .log .debug ("Could not find fsid" )
94
92
95
93
if fsid is not None :
96
94
tags .append (self .NAMESPACE + '_fsid:%s' % fsid )
@@ -276,29 +274,29 @@ def _extract_metrics(self, raw, tags):
276
274
except KeyError :
277
275
self .log .debug ('Error retrieving pgstatus metrics' )
278
276
279
- if self ._octopus :
280
- try :
281
- num_mons = int (raw ['status' ]['monmap' ]['num_mons' ])
282
- self .gauge (self .NAMESPACE + '.num_mons' , num_mons , tags )
283
- except KeyError :
284
- self .log .debug ('Error retrieving num_mons metric' )
285
- else :
286
- try :
287
- num_mons = len (raw ['mon_status' ]['monmap' ]['mons' ])
288
- self .gauge (self .NAMESPACE + '.num_mons' , num_mons , tags )
289
- except KeyError :
290
- self .log .debug ('Error retrieving mon_status metrics' )
277
+ try :
278
+ num_mons = int (raw ['status' ]['monmap' ]['num_mons' ])
279
+ self .gauge (self .NAMESPACE + '.num_mons' , num_mons , tags )
280
+ except KeyError :
281
+ if 'mon_status' in raw :
282
+ try :
283
+ num_mons = len (raw ['mon_status' ]['monmap' ]['mons' ])
284
+ self .gauge (self .NAMESPACE + '.num_mons' , num_mons , tags )
285
+ except KeyError :
286
+ self .log .debug ('Error retrieving mon_status metrics' )
291
287
292
- try :
293
- num_mons_active = len (raw ['mon_status' ]['quorum' ])
294
- self .gauge (self .NAMESPACE + '.num_mons.active' , num_mons_active , tags )
295
- except KeyError :
296
- self .log .debug ('Error retrieving mon_status quorum metrics' )
288
+ try :
289
+ num_mons_active = len (raw ['mon_status' ]['quorum' ])
290
+ self .gauge (self .NAMESPACE + '.num_mons.active' , num_mons_active , tags )
291
+ except KeyError :
292
+ self .log .debug ('Error retrieving mon_status quorum metrics' )
293
+ else :
294
+ self .log .debug ('Error retrieving num_mons metric' )
297
295
298
296
try :
299
297
stats = raw ['df_detail' ]['stats' ]
300
- if not self . _octopus :
301
- self ._publish (stats , self .gauge , ['total_objects' ], tags )
298
+ # This will only work on Ceph versions prior to `octopus`, but will catch+return on later versions
299
+ self ._publish (stats , self .gauge , ['total_objects' ], tags )
302
300
used = float (stats ['total_used_bytes' ])
303
301
total = float (stats ['total_bytes' ])
304
302
if total > 0 :
0 commit comments