BrightcoveOS / Diamond

1.18k stars 384 forks source link

cephstats.py not support ceph version 10.2.2 #861

Closed suslikas closed 7 years ago

suslikas commented 8 years ago

collectors/cephstats/cephstats.py not work properly on ceph version 10.2.2. I little bit fix code and start use json output with ceph is support.

cat adfcephstats.py

# coding=utf-8

"""
Alan Vezhbitskis
www.alan.lt

CEPH cluster statistic

"""

import json
import os
import subprocess
import diamond.collector
import diamond.convertor

class AdfCephStatsCollector(diamond.collector.Collector):

    def get_default_config_help(self):
        config_help = super(AdfCephStatsCollector, self).get_default_config_help()
        config_help.update({
            'path': 'Metrics store location path',
            'ceph_path': 'Ceph bin file path'
        })
        return config_help

    def get_default_config(self):
        config = super(AdfCephStatsCollector, self).get_default_config()
        config.update({
            'path': 'cephstats',
            'ceph_path': '/usr/bin/ceph'
        })
        return config

    def _command(self, command):
        return os.popen(self.config['ceph_path'] + " " + command).read()

    def _json_load(self, string):
        return json.loads(string)

    def collect(self):

        try:
            ret = self._command("-s -f json")
            json = self._json_load(ret)
        except Exception, e:
            self.log.info('Could not get stats: %s' % e)
            return False

        if json:
            for k, v in json['pgmap'].items():
                if k in [
                    "num_pgs",
                    "data_bytes",
                    "bytes_used",
                    "bytes_avail",
                    "bytes_total",
                    "degraded_objects",
                    "degraded_total",
                    "degraded_ratio",
                    "recovering_objects_per_sec",
                    "recovering_bytes_per_sec",
                    "recovering_keys_per_sec",
                    "num_objects_recovered",
                    "num_bytes_recovered",
                    "num_keys_recovered",
                    "read_bytes_sec",
                    "write_bytes_sec",
                    "read_op_per_sec",
                    "write_op_per_sec"
                ]:
                    name = 'pgmap.' + k
                    self.publish_gauge(name, int(v))

        if int(json['pgmap']['read_op_per_sec']) and int(json['pgmap']['write_op_per_sec']): 
            self.publish_gauge('pgmap.iops', int(json['pgmap']['read_op_per_sec']+json['pgmap']['write_op_per_sec']))
        else:
            self.publish_gauge('pgmap.iops', -1)

        return True
kormoc commented 7 years ago

This repo has moved to https://github.com/python-diamond/Diamond

Please open a new ticket there if this issue is not resolved with the current code there.

Thanks!