summaryrefslogtreecommitdiffstats
path: root/src/pybind/mgr/dashboard/controllers/monitor.py
blob: 288b6977acea5dbc9a4cd4512ebdb4a850b49d1c (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# -*- coding: utf-8 -*-

import json

from .. import mgr
from ..security import Scope
from . import APIDoc, APIRouter, BaseController, Endpoint, EndpointDoc, ReadPermission

MONITOR_SCHEMA = {
    "mon_status": ({
        "name": (str, ""),
        "rank": (int, ""),
        "state": (str, ""),
        "election_epoch": (int, ""),
        "quorum": ([int], ""),
        "quorum_age": (int, ""),
        "features": ({
            "required_con": (str, ""),
            "required_mon": ([int], ""),
            "quorum_con": (str, ""),
            "quorum_mon": ([str], "")
        }, ""),
        "outside_quorum": ([str], ""),
        "extra_probe_peers": ([str], ""),
        "sync_provider": ([str], ""),
        "monmap": ({
            "epoch": (int, ""),
            "fsid": (str, ""),
            "modified": (str, ""),
            "created": (str, ""),
            "min_mon_release": (int, ""),
            "min_mon_release_name": (str, ""),
            "features": ({
                "persistent": ([str], ""),
                "optional": ([str], "")
            }, ""),
            "mons": ([{
                "rank": (int, ""),
                "name": (str, ""),
                "public_addrs": ({
                    "addrvec": ([{
                        "type": (str, ""),
                        "addr": (str, ""),
                        "nonce": (int, "")
                    }], "")
                }, ""),
                "addr": (str, ""),
                "public_addr": (str, ""),
                "priority": (int, ""),
                "weight": (int, ""),
                "stats": ({
                    "num_sessions": ([int], ""),
                }, "")
            }], "")
        }, ""),
        "feature_map": ({
            "mon": ([{
                "features": (str, ""),
                "release": (str, ""),
                "num": (int, "")
            }], ""),
            "mds": ([{
                "features": (str, ""),
                "release": (str, ""),
                "num": (int, "")
            }], ""),
            "client": ([{
                "features": (str, ""),
                "release": (str, ""),
                "num": (int, "")
            }], ""),
            "mgr": ([{
                "features": (str, ""),
                "release": (str, ""),
                "num": (int, "")
            }], ""),
        }, "")
    }, ""),
    "in_quorum": ([{
        "rank": (int, ""),
        "name": (str, ""),
        "public_addrs": ({
            "addrvec": ([{
                "type": (str, ""),
                "addr": (str, ""),
                "nonce": (int, "")
            }], "")
        }, ""),
        "addr": (str, ""),
        "public_addr": (str, ""),
        "priority": (int, ""),
        "weight": (int, ""),
        "stats": ({
            "num_sessions": ([int], "")
        }, "")
    }], ""),
    "out_quorum": ([int], "")
}


@APIRouter('/monitor', Scope.MONITOR)
@APIDoc("Get Monitor Details", "Monitor")
class Monitor(BaseController):
    @Endpoint()
    @ReadPermission
    @EndpointDoc("Get Monitor Details",
                 responses={200: MONITOR_SCHEMA})
    def __call__(self):
        in_quorum, out_quorum = [], []

        counters = ['mon.num_sessions']

        mon_status_json = mgr.get("mon_status")
        mon_status = json.loads(mon_status_json['json'])

        for mon in mon_status["monmap"]["mons"]:
            mon["stats"] = {}
            for counter in counters:
                data = mgr.get_counter("mon", mon["name"], counter)
                if data is not None:
                    mon["stats"][counter.split(".")[1]] = data[counter]
                else:
                    mon["stats"][counter.split(".")[1]] = []
            if mon["rank"] in mon_status["quorum"]:
                in_quorum.append(mon)
            else:
                out_quorum.append(mon)

        return {
            'mon_status': mon_status,
            'in_quorum': in_quorum,
            'out_quorum': out_quorum
        }