95999a0435cb3ea099a328956e5ac983effe32d8
[ccsdk/oran.git] /
1 /*-
2  * ========================LICENSE_START=================================
3  * ONAP : ccsdk oran
4  * ======================================================================
5  * Copyright (C) 2022 Nordix Foundation. All rights reserved.
6  * ======================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ========================LICENSE_END===================================
19  */
20
21 package org.onap.ccsdk.oran.a1policymanagementservice.tasks;
22
23 import io.micrometer.core.instrument.MeterRegistry;
24 import java.lang.invoke.MethodHandles;
25 import lombok.AccessLevel;
26 import lombok.Getter;
27 import org.onap.ccsdk.oran.a1policymanagementservice.repository.Policies;
28 import org.onap.ccsdk.oran.a1policymanagementservice.repository.PolicyTypes;
29 import org.onap.ccsdk.oran.a1policymanagementservice.repository.Rics;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.stereotype.Component;
34
35 /**
36  * The aim is to collect statistical values from the A1 Policy Management Service.
37  */
38 @Component
39 public class RefreshCounterTask {
40
41     private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
42
43     @Autowired
44     private final Rics rics;
45
46     @Autowired
47     private final PolicyTypes policyTypes;
48
49     @Autowired
50     private final Policies policies;
51
52     @Autowired
53     @Getter(AccessLevel.PUBLIC)
54     private final MeterRegistry meterRegistry;
55
56     @Autowired
57     public RefreshCounterTask(Rics rics, PolicyTypes policyTypes, Policies policies, MeterRegistry meterRegistry) {
58         this.rics = rics;
59         this.policyTypes = policyTypes;
60         this.policies = policies;
61         this.meterRegistry = meterRegistry;
62
63         logger.trace("Counters have been initialized.");
64         meterRegistry.gauge("total_ric_count", rics, Rics::size);
65         meterRegistry.gauge("total_policy_type_count", policyTypes, PolicyTypes::size);
66         meterRegistry.gauge("total_policy_count", policies, Policies::size);
67     }
68
69 }