const (
_ StatType = 0
- ScalarIndex = 1
- SimpleCounterVector = 2
- CombinedCounterVector = 3
- ErrorIndex = 4
+ ScalarIndex StatType = 1
+ SimpleCounterVector StatType = 2
+ CombinedCounterVector StatType = 3
+ ErrorIndex StatType = 4
+ NameVector StatType = 5
)
func (d StatType) String() string {
return "CombinedCounterVector"
case ErrorIndex:
return "ErrorIndex"
+ case NameVector:
+ return "NameVector"
}
return fmt.Sprintf("UnknownStatType(%d)", d)
}
Bytes Counter
}
+// Name represents string value stored under name vector.
+type Name string
+
// ScalarStat represents stat for ScalarIndex.
type ScalarStat float64
// Values should be aggregated per interface/node for every worker.
type CombinedCounterStat [][]CombinedCounter
+// NameStat represents stat for NameVector.
+type NameStat []Name
+
// Data represents some type of stat which is usually defined by StatType.
type Stat interface {
// isStat is unexported to limit implementations of Data interface to this package,
func (ErrorStat) isStat() {}
func (SimpleCounterStat) isStat() {}
func (CombinedCounterStat) isStat() {}
+func (NameStat) isStat() {}
}
static uint32_t*
-govpp_stat_segment_ls(uint8_t ** pattern)
+govpp_stat_segment_ls(uint8_t **pattern)
{
return stat_segment_ls(pattern);
}
return data->combined_counter_vec[index][index2].bytes;
}
+static uint8_t**
+govpp_stat_segment_data_get_name_vector(stat_segment_data_t *data)
+{
+ return data->name_vector;
+}
+
+static char*
+govpp_stat_segment_data_get_name_vector_index(stat_segment_data_t *data, int index)
+{
+ return data->name_vector[index];
+}
+
static void
govpp_stat_segment_data_free(stat_segment_data_t *data)
{
}
stat.Data = adapter.CombinedCounterStat(vector)
+ case adapter.NameVector:
+ length := int(C.govpp_stat_segment_vec_len(unsafe.Pointer(C.govpp_stat_segment_data_get_name_vector(&v))))
+ var vector []adapter.Name
+ for k := 0; k < length; k++ {
+ s := C.govpp_stat_segment_data_get_name_vector_index(&v, C.int(k))
+ if s == nil {
+ continue
+ }
+ vector = append(vector, adapter.Name(C.GoString(s)))
+ }
+ stat.Data = adapter.NameStat(vector)
+
default:
- fmt.Fprintf(os.Stderr, "invalid stat type: %v (%d)", typ, typ)
+ fmt.Fprintf(os.Stderr, "invalid stat type: %v (%v)\n", typ, name)
continue
}
package core
import (
+ "fmt"
"strings"
"sync/atomic"
SystemStats_Heartbeat = SystemStatsPrefix + "heartbeat"
NodeStatsPrefix = "/sys/node/"
+ NodeStats_Names = NodeStatsPrefix + "names"
NodeStats_Clocks = NodeStatsPrefix + "clocks"
NodeStats_Vectors = NodeStatsPrefix + "vectors"
NodeStats_Calls = NodeStatsPrefix + "calls"
NodeStats_Suspends = NodeStatsPrefix + "suspends"
InterfaceStatsPrefix = "/if/"
+ InterfaceStats_Names = InterfaceStatsPrefix + "names"
InterfaceStats_Drops = InterfaceStatsPrefix + "drops"
InterfaceStats_Punt = InterfaceStatsPrefix + "punt"
InterfaceStats_IP4 = InterfaceStatsPrefix + "ip4"
InterfaceStats_TxMulticast = InterfaceStatsPrefix + "tx-multicast"
InterfaceStats_TxBroadcast = InterfaceStatsPrefix + "tx-broadcast"
- NetworkStatsPrefix = "/net/"
+ NetworkStatsPrefix = "/net/"
+ // TODO: network stats
NetworkStats_RouteTo = NetworkStatsPrefix + "route/to"
NetworkStats_RouteVia = NetworkStatsPrefix + "route/via"
NetworkStats_MRoute = NetworkStatsPrefix + "mroute"
for _, stat := range stats {
switch stat.Name {
+ case NodeStats_Names:
+ if names, ok := stat.Data.(adapter.NameStat); !ok {
+ return nil, fmt.Errorf("invalid stat type for %s", stat.Name)
+ } else {
+ if nodeStats.Nodes == nil {
+ nodeStats.Nodes = make([]api.NodeCounters, len(names))
+ for i := range names {
+ nodeStats.Nodes[i].NodeIndex = uint32(i)
+ }
+ }
+ for i, name := range names {
+ nodeStats.Nodes[i].NodeName = string(name)
+ }
+ }
case NodeStats_Clocks:
setPerNode(reduceSimpleCounterStat(stat.Data), func(c *api.NodeCounters, v uint64) {
c.Clocks = v
}
ifStats := &api.InterfaceStats{}
+
var setPerIf = func(perIf []uint64, fn func(c *api.InterfaceCounters, v uint64)) {
if ifStats.Interfaces == nil {
ifStats.Interfaces = make([]api.InterfaceCounters, len(perIf))
for _, stat := range stats {
switch stat.Name {
+ case InterfaceStats_Names:
+ if names, ok := stat.Data.(adapter.NameStat); !ok {
+ return nil, fmt.Errorf("invalid stat type for %s", stat.Name)
+ } else {
+ if ifStats.Interfaces == nil {
+ ifStats.Interfaces = make([]api.InterfaceCounters, len(names))
+ for i := range names {
+ ifStats.Interfaces[i].InterfaceIndex = uint32(i)
+ }
+ }
+ for i, name := range names {
+ ifStats.Interfaces[i].InterfaceName = string(name)
+ }
+ }
case InterfaceStats_Drops:
setPerIf(reduceSimpleCounterStat(stat.Data), func(c *api.InterfaceCounters, v uint64) {
c.Drops = v