blob: cf5711c0975a7853f747b1f48ede9be70986cfa7 [file] [log] [blame]
Ales Komarek2675e842016-10-05 00:10:44 +02001#!/usr/bin/python
2# Copyright 2015 Mirantis, Inc.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16import collectd
17
18import collectd_base as base
19
20INTERVAL = 60
21
22
23class CephOSDStatsPlugin(base.CephBase):
24 """ Collect per OSD stats about store size and commit latency."""
25
26 def __init__(self, *args, **kwargs):
27 super(CephOSDStatsPlugin, self).__init__(*args, **kwargs)
28 self.plugin = 'ceph_osd'
29
30 def itermetrics(self):
31 osd_stats = self.execute_to_json('ceph pg dump osds --format json')
32 if not osd_stats:
33 raise base.CheckException("Fail to execute 'pg dump osds'")
34
35 for osd in osd_stats:
36 osd_id = osd['osd']
37
38 yield {
39 'type_instance': osd_id,
40 'type': 'osd_space',
41 'values': [osd['kb_used'] * 1000, osd['kb'] * 1000],
42 }
43
44 yield {
45 'type_instance': osd_id,
46 'type': 'osd_latency',
47 'values': [osd['fs_perf_stat']['apply_latency_ms'],
48 osd['fs_perf_stat']['commit_latency_ms']],
49 }
50
51plugin = CephOSDStatsPlugin(collectd, 'ceph_mon')
52
53
54def init_callback():
55 plugin.restore_sigchld()
56
57
58def config_callback(conf):
59 plugin.config_callback(conf)
60
61
62def read_callback():
63 plugin.read_callback()
64
65collectd.register_init(init_callback)
66collectd.register_config(config_callback)
67collectd.register_read(read_callback, INTERVAL)