import (
"errors"
- "fmt"
)
const (
// StatType represents type of stat directory and simply
// defines what type of stat data is stored in the stat entry.
-type StatType int
+type StatType string
const (
- _ StatType = 0
- ScalarIndex StatType = 1
- SimpleCounterVector StatType = 2
- CombinedCounterVector StatType = 3
- ErrorIndex StatType = 4
- NameVector StatType = 5
- Empty StatType = 6
+ Unknown StatType = "UnknownStatType"
+ ScalarIndex StatType = "ScalarIndex"
+ SimpleCounterVector StatType = "SimpleCounterVector"
+ CombinedCounterVector StatType = "CombinedCounterVector"
+ ErrorIndex StatType = "ErrorIndex"
+ NameVector StatType = "NameVector"
+ Empty StatType = "Empty"
+ Symlink StatType = "Symlink"
)
-func (d StatType) String() string {
- switch d {
- case ScalarIndex:
- return "ScalarIndex"
- case SimpleCounterVector:
- return "SimpleCounterVector"
- case CombinedCounterVector:
- return "CombinedCounterVector"
- case ErrorIndex:
- return "ErrorIndex"
- case NameVector:
- return "NameVector"
- case Empty:
- return "Empty"
- }
- return fmt.Sprintf("UnknownStatType(%d)", d)
-}
-
// StatDir defines directory of stats entries created by PrepareDir.
type StatDir struct {
Epoch int64
// is defined by Type.
type StatEntry struct {
StatIdentifier
- Type StatType
- Data Stat
+ Type StatType
+ Data Stat
+ Symlink bool
}
// Counter represents simple counter with single value, which is usually packet count.
// IsZero returns true if all of its values equal to zero.
IsZero() bool
+ // Type returns underlying type of a stat
+ Type() StatType
+
// isStat is intentionally unexported to limit implementations of interface to this package,
isStat()
}
// ErrorStat represents stat for ErrorIndex. The array represents workers.
type ErrorStat []Counter
-// SimpleCounterStat represents stat for SimpleCounterVector.
+// SimpleCounterStat represents indexed stat for SimpleCounterVector.
// The outer array represents workers and the inner array represents interface/node/.. indexes.
// Values should be aggregated per interface/node for every worker.
// ReduceSimpleCounterStatIndex can be used to reduce specific index.
type SimpleCounterStat [][]Counter
-// CombinedCounterStat represents stat for CombinedCounterVector.
+// CombinedCounterStat represents indexed stat for CombinedCounterVector.
// The outer array represents workers and the inner array represents interface/node/.. indexes.
// Values should be aggregated per interface/node for every worker.
// ReduceCombinedCounterStatIndex can be used to reduce specific index.
func (s ScalarStat) IsZero() bool {
return s == 0
}
+
+func (s ScalarStat) Type() StatType {
+ return ScalarIndex
+}
+
func (s ErrorStat) IsZero() bool {
if s == nil {
return true
}
return true
}
+
+func (s ErrorStat) Type() StatType {
+ return ErrorIndex
+}
+
func (s SimpleCounterStat) IsZero() bool {
if s == nil {
return true
}
return true
}
+
+func (s SimpleCounterStat) Type() StatType {
+ return SimpleCounterVector
+}
+
func (s CombinedCounterStat) IsZero() bool {
if s == nil {
return true
}
return true
}
+
+func (s CombinedCounterStat) Type() StatType {
+ return CombinedCounterVector
+}
+
func (s NameStat) IsZero() bool {
if s == nil {
return true
}
return true
}
+
+func (s NameStat) Type() StatType {
+ return NameVector
+}
+
func (s EmptyStat) IsZero() bool {
return true
}
+func (s EmptyStat) Type() StatType {
+ return Empty
+}
+
// ReduceSimpleCounterStatIndex returns reduced SimpleCounterStat s for index i.
func ReduceSimpleCounterStatIndex(s SimpleCounterStat, i int) uint64 {
var val uint64