diff options
author | 2020-10-29 12:56:24 +0100 | |
---|---|---|
committer | 2020-10-30 12:39:24 +0000 | |
commit | b74e3b37479a7fa763bed1f2c76de612ee51dcbc (patch) | |
tree | 3a632ae21f54ba41a480b27d97c7332240ff257c /core/stats.go | |
parent | 0f46871b4cc45f2c3bd5bdb0aa0f7615795a2c6d (diff) |
Stats API: added GetMemory()
Retrieved numbers relate to the statseg heap.
Change-Id: I72750183db3524481918c71c993b39e65c28ddb6
Signed-off-by: Vladimir Lavor <vlavor@cisco.com>
Diffstat (limited to 'core/stats.go')
-rw-r--r-- | core/stats.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/core/stats.go b/core/stats.go index cd93cc1..f2da494 100644 --- a/core/stats.go +++ b/core/stats.go @@ -39,6 +39,10 @@ const ( CounterStatsPrefix = "/err/" + MemoryStatPrefix = "/mem/statseg" + MemoryStats_Total = "total" + MemoryStats_Used = "used" + InterfaceStatsPrefix = "/if/" InterfaceStats_Names = InterfaceStatsPrefix + "names" InterfaceStats_Drops = InterfaceStatsPrefix + "drops" @@ -80,6 +84,7 @@ type StatsConnection struct { ifaceStatsData *adapter.StatDir sysStatsData *adapter.StatDir bufStatsData *adapter.StatDir + memStatsData *adapter.StatDir } func newStatsConnection(stats adapter.StatsAPI) *StatsConnection { @@ -471,3 +476,25 @@ func (c *StatsConnection) GetBufferStats(bufStats *api.BufferStats) (err error) return nil } + +func (c *StatsConnection) GetMemoryStats(memStats *api.MemoryStats) (err error) { + if err := c.updateStats(&c.memStatsData, MemoryStatPrefix); err != nil { + return err + } + + for _, stat := range c.memStatsData.Entries { + _, f := path.Split(string(stat.Name)) + var val float64 + m, ok := stat.Data.(adapter.ScalarStat) + if ok { + val = float64(m) + } + switch f { + case MemoryStats_Total: + memStats.Total = val + case MemoryStats_Used: + memStats.Used = val + } + } + return nil +} |