]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/prometheus: implement command using CLIReadCommand
authorKefu Chai <kchai@redhat.com>
Fri, 26 Feb 2021 03:47:11 +0000 (11:47 +0800)
committerSage Weil <sage@newdream.net>
Tue, 16 Mar 2021 13:04:27 +0000 (08:04 -0500)
Signed-off-by: Kefu Chai <kchai@redhat.com>
(cherry picked from commit 3b9ecd14d7d714be7a7c72fa3d44d7781d360135)

src/pybind/mgr/prometheus/module.py

index 19c3f5f36c5299e79a781839f5752afd6fa14ff9..222ffd85832557b185a62e69deeb83a76831eebc 100644 (file)
@@ -10,7 +10,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
@@ -268,14 +268,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'
@@ -1235,7 +1227,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:
@@ -1258,13 +1254,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):