From: Jan Fajerski Date: Wed, 11 Oct 2017 18:07:19 +0000 (+0200) Subject: pybind/mgr_module: move PRIO_* and PERFCOUNTER_* to MgrModule class X-Git-Tag: v12.2.2~61^2~44 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=db09ea1c75c80dc189042c59e09ebc1c1f8d1249;p=ceph.git pybind/mgr_module: move PRIO_* and PERFCOUNTER_* to MgrModule class Signed-off-by: Jan Fajerski (cherry picked from commit f69484debade5f4fa2bd3a0d1badc9291cc9d7b7) --- diff --git a/src/pybind/mgr/influx/module.py b/src/pybind/mgr/influx/module.py index 327369300389..adeb452701d8 100644 --- a/src/pybind/mgr/influx/module.py +++ b/src/pybind/mgr/influx/module.py @@ -5,7 +5,6 @@ import json import errno from mgr_module import MgrModule -from mgr_module import PERFCOUNTER_HISTOGRAM try: from influxdb import InfluxDBClient @@ -77,7 +76,7 @@ class Module(MgrModule): metadata = self.get_metadata(svc_type, svc_id) for path, counter_info in counters.items(): - if counter_info['type'] & PERFCOUNTER_HISTOGRAM: + if counter_info['type'] & self.PERFCOUNTER_HISTOGRAM: continue value = counter_info['value'] diff --git a/src/pybind/mgr/mgr_module.py b/src/pybind/mgr/mgr_module.py index f8ad75e961cd..22ee148a1c94 100644 --- a/src/pybind/mgr/mgr_module.py +++ b/src/pybind/mgr/mgr_module.py @@ -9,24 +9,6 @@ import threading from collections import defaultdict -# Priority definitions for perf counters -PRIO_CRITICAL = 10 -PRIO_INTERESTING = 8 -PRIO_USEFUL = 5 -PRIO_UNINTERESTING = 2 -PRIO_DEBUGONLY = 0 - -# counter value types -PERFCOUNTER_TIME = 1 -PERFCOUNTER_U64 = 2 - -# counter types -PERFCOUNTER_LONGRUNAVG = 4 -PERFCOUNTER_COUNTER = 8 -PERFCOUNTER_HISTOGRAM = 0x10 -PERFCOUNTER_TYPE_MASK = ~2 - - class CommandResult(object): """ Use with MgrModule.send_command @@ -136,6 +118,23 @@ class CRUSHMap(object): class MgrModule(object): COMMANDS = [] + # Priority definitions for perf counters + PRIO_CRITICAL = 10 + PRIO_INTERESTING = 8 + PRIO_USEFUL = 5 + PRIO_UNINTERESTING = 2 + PRIO_DEBUGONLY = 0 + + # counter value types + PERFCOUNTER_TIME = 1 + PERFCOUNTER_U64 = 2 + + # counter types + PERFCOUNTER_LONGRUNAVG = 4 + PERFCOUNTER_COUNTER = 8 + PERFCOUNTER_HISTOGRAM = 0x10 + PERFCOUNTER_TYPE_MASK = ~2 + def __init__(self, handle): self._handle = handle self._logger = logging.getLogger(handle) diff --git a/src/pybind/mgr/prometheus/module.py b/src/pybind/mgr/prometheus/module.py index 162aadc91d81..1470218ae85f 100644 --- a/src/pybind/mgr/prometheus/module.py +++ b/src/pybind/mgr/prometheus/module.py @@ -33,33 +33,6 @@ def global_instance(): return _global_instance['plugin'] -# counter value types -PERFCOUNTER_TIME = 1 -PERFCOUNTER_U64 = 2 - -# counter types -PERFCOUNTER_LONGRUNAVG = 4 -PERFCOUNTER_COUNTER = 8 -PERFCOUNTER_HISTOGRAM = 0x10 -PERFCOUNTER_TYPE_MASK = ~2 - - -def stattype_to_str(stattype): - - typeonly = stattype & PERFCOUNTER_TYPE_MASK - if typeonly == 0: - return 'gauge' - if typeonly == PERFCOUNTER_LONGRUNAVG: - # this lie matches the DaemonState decoding: only val, no counts - return 'counter' - if typeonly == PERFCOUNTER_COUNTER: - return 'counter' - if typeonly == PERFCOUNTER_HISTOGRAM: - return 'histogram' - - return '' - - def health_status_to_number(status): if status == 'HEALTH_OK': @@ -168,6 +141,21 @@ class Module(MgrModule): self.schema = OrderedDict() _global_instance['plugin'] = self + def _stattype_to_str(self, stattype): + + typeonly = stattype & self.PERFCOUNTER_TYPE_MASK + if typeonly == 0: + return 'gauge' + if typeonly == self.PERFCOUNTER_LONGRUNAVG: + # this lie matches the DaemonState decoding: only val, no counts + return 'counter' + if typeonly == self.PERFCOUNTER_COUNTER: + return 'counter' + if typeonly == self.PERFCOUNTER_HISTOGRAM: + return 'histogram' + + return '' + def _setup_static_metrics(self): metrics = {} metrics['health_status'] = Metric( @@ -323,7 +311,7 @@ class Module(MgrModule): for daemon, counters in self.get_all_perf_counters().iteritems(): for path, counter_info in counters.items(): - stattype = stattype_to_str(counter_info['type']) + stattype = self._stattype_to_str(counter_info['type']) # XXX simplify first effort: no histograms # averages are already collapsed to one value for us if not stattype or stattype == 'histogram':