Debian Codegraph @

aodhclient/v2/metrics_cli.py

raw
1 #
2 # Licensed under the Apache License, Version 2.0 (the "License"); you may
3 # not use this file except in compliance with the License. You may obtain
4 # a copy of the License at
5 #
6 # http://www.apache.org/licenses/LICENSE-2.0
7 #
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11 # License for the specific language governing permissions and limitations
12 # under the License.
13
14 from cliff import lister
15
16 from aodhclient import utils
17
18 METRIC_COLS = ["name", "labels", "value"]
19
20
21 class CliMetrics(lister.Lister):
22 """Get Metrics"""
23
24 @staticmethod
25 def metrics2cols(metrics):
26 cols_data = []
27 if "evaluation_results" in metrics:
28 for alarm in metrics["evaluation_results"]:
29 for state, count in alarm["state_counters"].items():
30 # prometheus style labels
31 labels = ('alarm_id="{{{}}}", project_id="{{{}}}", '
32 'state="{{{}}}"').format(alarm['alarm_id'],
33 alarm['project_id'],
34 state)
35 cols_data.append(["evaluation_result", labels, count])
36 # Extend for other types of metrics here
37 return METRIC_COLS, cols_data
38
39 def get_parser(self, prog_name):
40 parser = super().get_parser(prog_name)
41 return parser
42
43 def take_action(self, parsed_args):
44 metrics = utils.get_client(self).metrics.get()
45 return self.metrics2cols(metrics)