Adding Subscription and Metric feature
[ric-app/hw-python.git] / src / manager / MetricManager.py
1 # ==================================================================================
2 #
3 #       Copyright (c) 2021 Samsung Electronics Co., Ltd. All Rights Reserved.
4 #
5 #   Licensed under the Apache License, Version 2.0 (the "License");
6 #   you may not use this file except in compliance with the License.
7 #   You may obtain a copy of the License at
8 #
9 #          http://www.apache.org/licenses/LICENSE-2.0
10 #
11 #   Unless required by applicable law or agreed to in writing, software
12 #   distributed under the License is distributed on an "AS IS" BASIS,
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 #   See the License for the specific language governing permissions and
15 #   limitations under the License.
16 #
17 # ==================================================================================
18
19 from ricxappframe.xapp_frame import RMRXapp
20 from ricxappframe.metric import metric
21 from ._BaseManager import _BaseManager
22 from datetime import datetime
23
24 # noinspection PyProtectedMember,PyProtectedMember
25 class MetricManager(_BaseManager):
26
27     def __init__(self, rmr_xapp: RMRXapp):
28         super().__init__(rmr_xapp)
29         self.metric_mgr = metric.MetricsManager(self._rmr_xapp._mrc, "system-time", "hw-python")
30
31     def send_metric(self):
32
33         # datetime object containing current date and time
34         now = datetime.now()
35         dt_string = now.strftime("%d/%m/%Y %H:%M:%S")
36         metric_list = [dt_string]
37         self.logger.info("MetricManager:: metric time {}".format(metric_list))
38         self.metric_mgr.send_metrics(metric_list)
39         self.logger.info("MetricManager:: metric sent")
40