Ales Komarek | 2675e84 | 2016-10-05 00:10:44 +0200 | [diff] [blame] | 1 | #!/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 | |
| 16 | import collectd |
| 17 | |
| 18 | import collectd_base as base |
| 19 | |
| 20 | INTERVAL = 60 |
| 21 | |
| 22 | |
| 23 | class 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 | |
| 51 | plugin = CephOSDStatsPlugin(collectd, 'ceph_mon') |
| 52 | |
| 53 | |
| 54 | def init_callback(): |
| 55 | plugin.restore_sigchld() |
| 56 | |
| 57 | |
| 58 | def config_callback(conf): |
| 59 | plugin.config_callback(conf) |
| 60 | |
| 61 | |
| 62 | def read_callback(): |
| 63 | plugin.read_callback() |
| 64 | |
| 65 | collectd.register_init(init_callback) |
| 66 | collectd.register_config(config_callback) |
| 67 | collectd.register_read(read_callback, INTERVAL) |