From 3b9ecd14d7d714be7a7c72fa3d44d7781d360135 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Fri, 26 Feb 2021 11:47:11 +0800 Subject: [PATCH] mgr/prometheus: implement command using CLIReadCommand Signed-off-by: Kefu Chai --- src/pybind/mgr/prometheus/module.py | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/src/pybind/mgr/prometheus/module.py b/src/pybind/mgr/prometheus/module.py index e83f9191b11..0f4048391f5 100644 --- a/src/pybind/mgr/prometheus/module.py +++ b/src/pybind/mgr/prometheus/module.py @@ -9,7 +9,7 @@ import re import socket import threading import time -from mgr_module import MgrModule, MgrStandbyModule, PG_STATES, Option, ServiceInfoT +from mgr_module import CLIReadCommand, MgrModule, MgrStandbyModule, PG_STATES, Option, ServiceInfoT from mgr_util import get_default_addr, profile_method from rbd import RBD from collections import namedtuple @@ -242,14 +242,6 @@ class MetricCollectionThread(threading.Thread): class Module(MgrModule): - COMMANDS = [ - { - "cmd": "prometheus file_sd_config", - "desc": "Return file_sd compatible prometheus config for mgr cluster", - "perm": "r" - }, - ] - MODULE_OPTIONS = [ Option( 'server_addr' @@ -1180,7 +1172,11 @@ class Module(MgrModule): return ''.join(_metrics) + '\n' + @CLIReadCommand('prometheus file_sd_config') def get_file_sd_config(self): + ''' + Return file_sd compatible prometheus config for mgr cluster + ''' servers = self.list_servers() targets = [] for server in servers: @@ -1203,13 +1199,6 @@ class Module(MgrModule): self.collect() self.get_file_sd_config() - def handle_command(self, inbuf, cmd): - if cmd['prefix'] == 'prometheus file_sd_config': - return self.get_file_sd_config() - else: - return (-errno.EINVAL, '', - "Command not found '{0}'".format(cmd['prefix'])) - def serve(self): class Root(object): -- 2.47.3