Merge "Introduce StatsAPI and it's initial implementation"
[govpp.git] / adapter / stats_api.go
1 package adapter
2
3 // StatsAPI provides connection to VPP stats API.
4 type StatsAPI interface {
5         // Connect establishes client connection to the stats API.
6         Connect() error
7
8         // Disconnect terminates client connection.
9         Disconnect() error
10
11         // ListStats lists names for all stats.
12         ListStats(patterns ...string) (statNames []string, err error)
13
14         // DumpStats dumps all stat entries.
15         DumpStats(patterns ...string) ([]*StatEntry, error)
16 }
17
18 // StatType represents type of stat directory and simply
19 // defines what type of stat data is stored in the stat entry.
20 type StatType int
21
22 const (
23         _ StatType = iota
24         ScalarIndex
25         SimpleCounterVector
26         CombinedCounterVector
27         ErrorIndex
28 )
29
30 func (d StatType) String() string {
31         switch d {
32         case ScalarIndex:
33                 return "ScalarIndex"
34         case SimpleCounterVector:
35                 return "SimpleCounterVector"
36         case CombinedCounterVector:
37                 return "CombinedCounterVector"
38         case ErrorIndex:
39                 return "ErrorIndex"
40         }
41         return "UnknownStatType"
42 }
43
44 // StatEntry represents single stat entry. The type of stat stored in Data
45 // is defined by Type.
46 type StatEntry struct {
47         Name string
48         Type StatType
49         Data Stat
50 }
51
52 // Counter represents simple counter with single value.
53 type Counter uint64
54
55 // CombinedCounter represents counter with two values, for packet count and bytes count.
56 type CombinedCounter struct {
57         Packets Counter
58         Bytes   Counter
59 }
60
61 // ScalarStat represents stat for ScalarIndex.
62 type ScalarStat float64
63
64 // ErrorStat represents stat for ErrorIndex.
65 type ErrorStat uint64
66
67 // SimpleCounterStat represents stat for SimpleCounterVector.
68 // The outer array represents workers and the inner array represents sw_if_index.
69 // Values should be aggregated per interface for every worker.
70 type SimpleCounterStat [][]Counter
71
72 // CombinedCounterStat represents stat for CombinedCounterVector.
73 // The outer array represents workers and the inner array represents sw_if_index.
74 // Values should be aggregated per interface for every worker.
75 type CombinedCounterStat [][]CombinedCounter
76
77 // Data represents some type of stat which is usually defined by StatType.
78 type Stat interface {
79         // isStat is unexported to limit implementations of Data interface to this package,
80         isStat()
81 }
82
83 func (ScalarStat) isStat()          {}
84 func (ErrorStat) isStat()           {}
85 func (SimpleCounterStat) isStat()   {}
86 func (CombinedCounterStat) isStat() {}