amit.ghosh | 6ab2a98 | 2022-09-15 21:04:53 +0200 | [diff] [blame] | 1 | /* |
Joey Armstrong | 7f8436c | 2023-07-09 20:23:27 -0400 | [diff] [blame] | 2 | * Copyright 2018-2023 Open Networking Foundation (ONF) and the ONF Contributors |
amit.ghosh | 6ab2a98 | 2022-09-15 21:04:53 +0200 | [diff] [blame] | 3 | |
Joey Armstrong | 7f8436c | 2023-07-09 20:23:27 -0400 | [diff] [blame] | 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 |
amit.ghosh | 6ab2a98 | 2022-09-15 21:04:53 +0200 | [diff] [blame] | 7 | |
Joey Armstrong | 7f8436c | 2023-07-09 20:23:27 -0400 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
amit.ghosh | 6ab2a98 | 2022-09-15 21:04:53 +0200 | [diff] [blame] | 9 | |
Joey Armstrong | 7f8436c | 2023-07-09 20:23:27 -0400 | [diff] [blame] | 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. |
amit.ghosh | 6ab2a98 | 2022-09-15 21:04:53 +0200 | [diff] [blame] | 15 | */ |
| 16 | package stats |
| 17 | |
| 18 | import ( |
| 19 | "context" |
| 20 | "time" |
| 21 | ) |
| 22 | |
| 23 | type CollectorName string |
| 24 | |
| 25 | const ( |
| 26 | OltAdapter CollectorName = "adapter_olt" |
| 27 | OnuAdapter CollectorName = "adapter_onu" |
| 28 | VCore CollectorName = "rw_core" |
| 29 | ) |
| 30 | |
| 31 | func (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 | |
| 43 | type 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 | |
| 66 | type NullStatsServer struct { |
| 67 | } |
| 68 | |
| 69 | func (n *NullStatsServer) Start(ctx context.Context, p int, name CollectorName) {} |
| 70 | func (n *NullStatsServer) CountForDevice(devId, sn string, counterName DeviceCounter) {} |
| 71 | func (n *NullStatsServer) AddForDevice(devId, sn string, counter DeviceCounter, val float64) {} |
| 72 | func (n *NullStatsServer) CollectDurationForDevice(devID, sn string, dName NonDeviceDuration, startTime time.Time) { |
| 73 | } |
| 74 | func (n *NullStatsServer) Count(counter NonDeviceCounter) {} |
| 75 | func (n *NullStatsServer) Add(counter NonDeviceCounter, val float64) {} |
| 76 | func (n *NullStatsServer) CollectDuration(dName NonDeviceDuration, startTime time.Time) {} |