1 # Copyright ETSI Contributors and Others.
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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
17 from osmclient
.cli_commands
import utils
21 logger
= logging
.getLogger("osmclient")
25 name
="ns-metric-export",
26 short_help
="exports a metric to the internal OSM bus, which can be read by other apps",
28 @click.option("--ns", prompt
=True, help="NS instance id or name")
30 "--vnf", prompt
=True, help="VNF name (VNF member index as declared in the NSD)"
32 @click.option("--vdu", prompt
=True, help="VDU name (VDU name as declared in the VNFD)")
33 @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)')
37 "--interval", help="periodic interval (seconds) to export metrics continuously"
40 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?
45 ns_instance
= ctx
.obj
.ns
.get(ns
)
47 metric_data
["ns_id"] = ns_instance
["_id"]
48 metric_data
["correlation_id"] = ns_instance
["_id"]
49 metric_data
["vnf_member_index"] = vnf
50 metric_data
["vdu_name"] = vdu
51 metric_data
["metric_name"] = metric
52 metric_data
["collection_unit"] = "WEEK"
53 metric_data
["collection_period"] = 1
54 utils
.check_client_version(ctx
.obj
, ctx
.command
.name
)
56 print("{}".format(ctx
.obj
.ns
.export_metric(metric_data
)))
60 print("{} {}".format(ctx
.obj
.ns
.export_metric(metric_data
), i
))
61 time
.sleep(int(interval
))