blob: 79921d57e544152837ccbcc3a8e9fbeb2b0b300e [file] [log] [blame]
Jian Li60804322015-12-02 14:46:31 -08001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
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 */
16package org.onosproject.cpman;
17
18import org.apache.felix.scr.annotations.Reference;
19import org.apache.felix.scr.annotations.ReferenceCardinality;
20import org.onosproject.net.DeviceId;
21
22import java.util.Optional;
23
24/**
25 * Default ControlMetricsObserver.
26 */
27public class DefaultControlMetricsObserver implements ControlMetricsObserver {
28
29 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
30 protected ControlPlaneMonitorService controlPlaneMonitorService;
31
32 @Override
33 public void feedMetrics(MetricsAggregator ma, Optional<DeviceId> deviceId) {
34 MetricValue mv = new MetricValue((long) ma.getRate(), (long) ma.getLoad(), (long) ma.getCount());
35 ControlMetric cpm = new ControlMetric(ma.getMetricsType(), mv);
36 controlPlaneMonitorService.updateMetric(cpm, 1, deviceId);
37 }
38}