blob: fdc8cc0d8cf8116d4dc5a7871553dcb2498ee5b5 [file] [log] [blame]
amit.ghosh6ab2a982022-09-15 21:04:53 +02001/*
2 * Copyright 2018-present Open Networking Foundation
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 stats
17
18import (
19 "context"
20 "time"
21)
22
23type CollectorName string
24
25const (
26 OltAdapter CollectorName = "adapter_olt"
27 OnuAdapter CollectorName = "adapter_onu"
28 VCore CollectorName = "rw_core"
29)
30
31func (s CollectorName) String() string {
32 switch s {
33 case OltAdapter:
34 return "adapter_olt"
35 case OnuAdapter:
36 return "adapter_onu"
37 case VCore:
38 return "rw_core"
39 }
40 return "unknown"
41}
42
43type StatsManager interface {
44 // Start starts the statistics manager with name and makes the collected stats available at port p.
45 Start(ctx context.Context, p int, name CollectorName)
46
47 //CountForDevice counts the number of times the counterName happens for device devId with serial number sn. Each call to Count increments it by one.
48 CountForDevice(devId, sn string, counterName DeviceCounter)
49
50 //AddForDevice adds val to counter.
51 AddForDevice(devId, sn string, counter DeviceCounter, val float64)
52
53 //CollectDurationForDevice calculates the duration from startTime to time.Now() for device devID with serial number sn.
54 CollectDurationForDevice(devID, sn string, dName NonDeviceDuration, startTime time.Time)
55
56 //Count counts the number of times the counterName happens. Each call to Count increments it by one.
57 Count(counter NonDeviceCounter)
58
59 //Add adds val to counter.
60 Add(counter NonDeviceCounter, val float64)
61
62 //CollectDuration calculates the duration from startTime to time.Now().
63 CollectDuration(dName NonDeviceDuration, startTime time.Time)
64}
65
66type NullStatsServer struct {
67}
68
69func (n *NullStatsServer) Start(ctx context.Context, p int, name CollectorName) {}
70func (n *NullStatsServer) CountForDevice(devId, sn string, counterName DeviceCounter) {}
71func (n *NullStatsServer) AddForDevice(devId, sn string, counter DeviceCounter, val float64) {}
72func (n *NullStatsServer) CollectDurationForDevice(devID, sn string, dName NonDeviceDuration, startTime time.Time) {
73}
74func (n *NullStatsServer) Count(counter NonDeviceCounter) {}
75func (n *NullStatsServer) Add(counter NonDeviceCounter, val float64) {}
76func (n *NullStatsServer) CollectDuration(dName NonDeviceDuration, startTime time.Time) {}