1 // Copyright (c) 2019 Cisco and/or its affiliates.
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at:
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
23 // DefaultStatsSocket defines a default socket file path for VPP stats API.
24 DefaultStatsSocket = "/run/vpp/stats.sock"
28 ErrStatDirBusy = errors.New("stat dir busy")
29 ErrStatDumpBusy = errors.New("stat dump busy")
32 // StatsAPI provides connection to VPP stats API.
33 type StatsAPI interface {
34 // Connect establishes client connection to the stats API.
37 // Disconnect terminates client connection.
40 // ListStats lists names for all stats.
41 ListStats(patterns ...string) (statNames []string, err error)
43 // DumpStats dumps all stat entries.
44 DumpStats(patterns ...string) ([]*StatEntry, error)
47 // StatType represents type of stat directory and simply
48 // defines what type of stat data is stored in the stat entry.
53 ScalarIndex StatType = 1
54 SimpleCounterVector StatType = 2
55 CombinedCounterVector StatType = 3
56 ErrorIndex StatType = 4
57 NameVector StatType = 5
60 func (d StatType) String() string {
64 case SimpleCounterVector:
65 return "SimpleCounterVector"
66 case CombinedCounterVector:
67 return "CombinedCounterVector"
73 return fmt.Sprintf("UnknownStatType(%d)", d)
76 // StatEntry represents single stat entry. The type of stat stored in Data
77 // is defined by Type.
78 type StatEntry struct {
84 // Counter represents simple counter with single value.
87 // CombinedCounter represents counter with two values, for packet count and bytes count.
88 type CombinedCounter struct {
93 // Name represents string value stored under name vector.
96 // ScalarStat represents stat for ScalarIndex.
97 type ScalarStat float64
99 // ErrorStat represents stat for ErrorIndex.
100 type ErrorStat Counter
102 // SimpleCounterStat represents stat for SimpleCounterVector.
103 // The outer array represents workers and the inner array represents interface/node/.. indexes.
104 // Values should be aggregated per interface/node for every worker.
105 type SimpleCounterStat [][]Counter
107 // CombinedCounterStat represents stat for CombinedCounterVector.
108 // The outer array represents workers and the inner array represents interface/node/.. indexes.
109 // Values should be aggregated per interface/node for every worker.
110 type CombinedCounterStat [][]CombinedCounter
112 // NameStat represents stat for NameVector.
115 // Data represents some type of stat which is usually defined by StatType.
116 type Stat interface {
117 // isStat is unexported to limit implementations of Data interface to this package,
121 func (ScalarStat) isStat() {}
122 func (ErrorStat) isStat() {}
123 func (SimpleCounterStat) isStat() {}
124 func (CombinedCounterStat) isStat() {}
125 func (NameStat) isStat() {}