Code Coverage

Cobertura Coverage Report > osmclient.cli_commands >

metrics.py

Trend

Classes100%
 
Lines42%
   
Conditionals100%
 

File Coverage summary

NameClassesLinesConditionals
metrics.py
100%
1/1
42%
13/31
100%
0/0

Coverage Breakdown by Class

NameLinesConditionals
metrics.py
42%
13/31
N/A

Source

osmclient/cli_commands/metrics.py
1 # Copyright ETSI Contributors and Others.
2 # All Rights Reserved.
3 #
4 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
5 #    not use this file except in compliance with the License. You may obtain
6 #    a copy of the License at
7 #
8 #         http://www.apache.org/licenses/LICENSE-2.0
9 #
10 #    Unless required by applicable law or agreed to in writing, software
11 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 #    License for the specific language governing permissions and limitations
14 #    under the License.
15
16 1 import click
17 1 from osmclient.cli_commands import utils
18 1 import time
19 1 import logging
20
21 1 logger = logging.getLogger("osmclient")
22
23
24 1 @click.command(
25     name="ns-metric-export",
26     short_help="exports a metric to the internal OSM bus, which can be read by other apps",
27 )
28 1 @click.option("--ns", prompt=True, help="NS instance id or name")
29 1 @click.option(
30     "--vnf", prompt=True, help="VNF name (VNF member index as declared in the NSD)"
31 )
32 1 @click.option("--vdu", prompt=True, help="VDU name (VDU name as declared in the VNFD)")
33 1 @click.option("--metric", prompt=True, help="name of the metric (e.g. cpu_utilization)")
34 # @click.option('--period', default='1w',
35 #              help='metric collection period (e.g. 20s, 30m, 2h, 3d, 1w)')
36 1 @click.option(
37     "--interval", help="periodic interval (seconds) to export metrics continuously"
38 )
39 1 @click.pass_context
40 1 def ns_metric_export(ctx, ns, vnf, vdu, metric, interval):
41     """exports a metric to the internal OSM bus, which can be read by other apps"""
42     # TODO: Check how to validate interval.
43     # Should it be an integer (seconds), or should a suffix (s,m,h,d,w) also be permitted?
44 0     logger.debug("")
45 0     ns_instance = ctx.obj.ns.get(ns)
46 0     metric_data = {}
47 0     metric_data["ns_id"] = ns_instance["_id"]
48 0     metric_data["correlation_id"] = ns_instance["_id"]
49 0     metric_data["vnf_member_index"] = vnf
50 0     metric_data["vdu_name"] = vdu
51 0     metric_data["metric_name"] = metric
52 0     metric_data["collection_unit"] = "WEEK"
53 0     metric_data["collection_period"] = 1
54 0     utils.check_client_version(ctx.obj, ctx.command.name)
55 0     if not interval:
56 0         print("{}".format(ctx.obj.ns.export_metric(metric_data)))
57     else:
58 0         i = 1
59 0         while True:
60 0             print("{} {}".format(ctx.obj.ns.export_metric(metric_data), i))
61 0             time.sleep(int(interval))
62 0             i += 1