summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorOndrej Fabry <ofabry@cisco.com>2019-04-11 10:59:49 +0200
committerOndrej Fabry <ofabry@cisco.com>2019-04-11 10:59:49 +0200
commitdf1b888a2bfadefadc7dbfce59d34f811ff002ec (patch)
tree054ac4d90c744b867255e8e88ac0c38bd46e8d64 /core
parent3dc9b9885e3d7041a7c349185dc88f3bed50be6d (diff)
Add support for names vector and fill name in interface/node stats
Change-Id: I3a6bcb635701c0f00e47d04fce2113e1ac23b67b Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
Diffstat (limited to 'core')
-rw-r--r--core/stats.go35
1 files changed, 34 insertions, 1 deletions
diff --git a/core/stats.go b/core/stats.go
index 26b9bc9..4cbd9f2 100644
--- a/core/stats.go
+++ b/core/stats.go
@@ -1,6 +1,7 @@
package core
import (
+ "fmt"
"strings"
"sync/atomic"
@@ -19,12 +20,14 @@ const (
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"
@@ -42,7 +45,8 @@ const (
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"
@@ -200,6 +204,20 @@ func (c *StatsConnection) GetNodeStats() (*api.NodeStats, error) {
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
@@ -230,6 +248,7 @@ func (c *StatsConnection) GetInterfaceStats() (*api.InterfaceStats, error) {
}
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))
@@ -246,6 +265,20 @@ func (c *StatsConnection) GetInterfaceStats() (*api.InterfaceStats, error) {
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