summaryrefslogtreecommitdiffstats
path: root/src/pybind/mgr/stats/module.py
blob: fcc1bce97b5cf617b3d58b4e27904e64b766b3b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""
performance stats for ceph filesystem (for now...)
"""

import json
from typing import List, Dict

from mgr_module import MgrModule, Option, NotifyType

from .fs.perf_stats import FSPerfStats

class Module(MgrModule):
    COMMANDS = [
        {
            "cmd": "fs perf stats "
                   "name=mds_rank,type=CephString,req=false "
                   "name=client_id,type=CephString,req=false "
                   "name=client_ip,type=CephString,req=false ",
            "desc": "retrieve ceph fs performance stats",
            "perm": "r"
        },
    ]
    MODULE_OPTIONS: List[Option] = []
    NOTIFY_TYPES = [NotifyType.command, NotifyType.fs_map]

    def __init__(self, *args, **kwargs):
        super(Module, self).__init__(*args, **kwargs)
        self.fs_perf_stats = FSPerfStats(self)

    def notify(self, notify_type: NotifyType, notify_id):
        if notify_type == NotifyType.command:
            self.fs_perf_stats.notify_cmd(notify_id)
        elif notify_type == NotifyType.fs_map:
            self.fs_perf_stats.notify_fsmap()

    def handle_command(self, inbuf, cmd):
        prefix = cmd['prefix']
        # only supported command is `fs perf stats` right now
        if prefix.startswith('fs perf stats'):
            return self.fs_perf_stats.get_perf_data(cmd)
        raise NotImplementedError(cmd['prefix'])