blob: d4b7ac4e1ef1b16183f242fae0501895bd7cd34e [file] [log] [blame]
Jian Li60804322015-12-02 14:46:31 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Jian Li60804322015-12-02 14:46:31 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain 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,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Jian Li6b86a762016-01-29 09:30:40 -080016package org.onosproject.cpman.impl;
Jian Li60804322015-12-02 14:46:31 -080017
18import org.apache.felix.scr.annotations.Reference;
19import org.apache.felix.scr.annotations.ReferenceCardinality;
Jian Li6b86a762016-01-29 09:30:40 -080020import org.onosproject.cpman.ControlMetric;
21import org.onosproject.cpman.ControlPlaneMonitorService;
22import org.onosproject.cpman.MetricValue;
Jian Li60804322015-12-02 14:46:31 -080023import org.onosproject.net.DeviceId;
24
25import java.util.Optional;
26
27/**
28 * Default ControlMetricsObserver.
29 */
30public class DefaultControlMetricsObserver implements ControlMetricsObserver {
31
32 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
33 protected ControlPlaneMonitorService controlPlaneMonitorService;
34
35 @Override
36 public void feedMetrics(MetricsAggregator ma, Optional<DeviceId> deviceId) {
Jian Lic132c112016-01-28 20:27:34 -080037 MetricValue mv = new MetricValue.Builder()
38 .rate(ma.getRate())
39 .count(ma.getCount())
40 .load(ma.getLoad())
41 .add();
Jian Lie044d1a2016-01-25 09:01:20 -080042 ControlMetric cm = new ControlMetric(ma.getMetricsType(), mv);
43 controlPlaneMonitorService.updateMetric(cm, 1, deviceId);
44 }
45
46 @Override
47 public void feedMetrics(MetricsAggregator ma, String resourceName) {
Jian Lic132c112016-01-28 20:27:34 -080048 MetricValue mv = new MetricValue.Builder()
49 .rate(ma.getRate())
50 .count(ma.getCount())
51 .load(ma.getLoad())
52 .add();
Jian Lie044d1a2016-01-25 09:01:20 -080053 ControlMetric cm = new ControlMetric(ma.getMetricsType(), mv);
54 controlPlaneMonitorService.updateMetric(cm, 1, resourceName);
Jian Li60804322015-12-02 14:46:31 -080055 }
56}