summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorOndrej Fabry <ofabry@cisco.com>2019-04-18 02:25:34 +0200
committerOndrej Fabry <ofabry@cisco.com>2019-04-18 02:25:34 +0200
commitcca1d2b85f68ec11d5131dc53313f250391818a3 (patch)
treea805c32ec5afb7c00b01f1560aee2a3d1432716d /core
parente24215b47ad5cd6599973c3a76a375b99ad75d44 (diff)
Add buffer pool stats
Change-Id: I15d1df825b4d4fc760da83d9c878a621936bb6fa Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
Diffstat (limited to 'core')
-rw-r--r--core/stats.go50
1 files changed, 47 insertions, 3 deletions
diff --git a/core/stats.go b/core/stats.go
index 48b516c..e935888 100644
--- a/core/stats.go
+++ b/core/stats.go
@@ -2,6 +2,7 @@ package core
import (
"fmt"
+ "path"
"strings"
"sync/atomic"
@@ -10,8 +11,6 @@ import (
)
const (
- CounterStatsPrefix = "/err/"
-
SystemStatsPrefix = "/sys/"
SystemStats_VectorRate = SystemStatsPrefix + "vector_rate"
SystemStats_InputRate = SystemStatsPrefix + "input_rate"
@@ -26,6 +25,13 @@ const (
NodeStats_Calls = NodeStatsPrefix + "calls"
NodeStats_Suspends = NodeStatsPrefix + "suspends"
+ BufferStatsPrefix = "/buffer-pools/"
+ BufferStats_Cached = "cached"
+ BufferStats_Used = "used"
+ BufferStats_Available = "available"
+
+ CounterStatsPrefix = "/err/"
+
InterfaceStatsPrefix = "/if/"
InterfaceStats_Names = InterfaceStatsPrefix + "names"
InterfaceStats_Drops = InterfaceStatsPrefix + "drops"
@@ -45,12 +51,13 @@ const (
InterfaceStats_TxMulticast = InterfaceStatsPrefix + "tx-multicast"
InterfaceStats_TxBroadcast = InterfaceStatsPrefix + "tx-broadcast"
- NetworkStatsPrefix = "/net/"
// TODO: network stats
+ NetworkStatsPrefix = "/net/"
NetworkStats_RouteTo = NetworkStatsPrefix + "route/to"
NetworkStats_RouteVia = NetworkStatsPrefix + "route/via"
NetworkStats_MRoute = NetworkStatsPrefix + "mroute"
NetworkStats_Adjacency = NetworkStatsPrefix + "adjacency"
+ NetworkStats_Punt = NetworkStatsPrefix + "punt"
)
type StatsConnection struct {
@@ -188,6 +195,7 @@ func (c *StatsConnection) GetNodeStats() (*api.NodeStats, error) {
}
nodeStats := &api.NodeStats{}
+
var setPerNode = func(perNode []uint64, fn func(c *api.NodeCounters, v uint64)) {
if nodeStats.Nodes == nil {
nodeStats.Nodes = make([]api.NodeCounters, len(perNode))
@@ -387,6 +395,42 @@ func (c *StatsConnection) GetInterfaceStats() (*api.InterfaceStats, error) {
return ifStats, nil
}
+// GetBufferStats retrieves VPP buffer pools stats.
+func (c *StatsConnection) GetBufferStats() (*api.BufferStats, error) {
+ stats, err := c.statsClient.DumpStats(BufferStatsPrefix)
+ if err != nil {
+ return nil, err
+ }
+
+ bufStats := &api.BufferStats{
+ Buffer: map[string]api.BufferPool{},
+ }
+
+ for _, stat := range stats {
+ d, f := path.Split(stat.Name)
+ d = strings.TrimSuffix(d, "/")
+
+ name := strings.TrimPrefix(d, BufferStatsPrefix)
+ b, ok := bufStats.Buffer[name]
+ if !ok {
+ b.PoolName = name
+ }
+
+ switch f {
+ case BufferStats_Cached:
+ b.Cached = scalarStatToFloat64(stat.Data)
+ case BufferStats_Used:
+ b.Used = scalarStatToFloat64(stat.Data)
+ case BufferStats_Available:
+ b.Available = scalarStatToFloat64(stat.Data)
+ }
+
+ bufStats.Buffer[name] = b
+ }
+
+ return bufStats, nil
+}
+
func scalarStatToFloat64(stat adapter.Stat) float64 {
if s, ok := stat.(adapter.ScalarStat); ok {
return float64(s)