diff options
Diffstat (limited to 'core/stats.go')
-rw-r--r-- | core/stats.go | 60 |
1 files changed, 45 insertions, 15 deletions
diff --git a/core/stats.go b/core/stats.go index 3218f1e..4033981 100644 --- a/core/stats.go +++ b/core/stats.go @@ -39,9 +39,11 @@ const ( CounterStatsPrefix = "/err/" - MemoryStatPrefix = "/mem/statseg" - MemoryStats_Total = "total" - MemoryStats_Used = "used" + MemoryStatSegPrefix = "/mem/statseg" + MemoryStatPrefix = "/mem/stat" + MemoryMainPrefix = "/mem/main" + MemoryStats_Total = "total" + MemoryStats_Used = "used" InterfaceStatsPrefix = "/if/" InterfaceStats_Names = InterfaceStatsPrefix + "names" @@ -545,22 +547,50 @@ func (c *StatsConnection) GetBufferStats(bufStats *api.BufferStats) (err error) } func (c *StatsConnection) GetMemoryStats(memStats *api.MemoryStats) (err error) { - if err := c.updateStats(&c.memStatsData, MemoryStatPrefix); err != nil { + if err := c.updateStats(&c.memStatsData, MemoryStatSegPrefix, MemoryStatPrefix, MemoryMainPrefix); err != nil { return err } + convertStats := func(stats []adapter.Counter) api.MemoryCounters { + memUsg := make([]adapter.Counter, 7) + copy(memUsg, stats) + return api.MemoryCounters{ + Total: uint64(memUsg[0]), Used: uint64(memUsg[1]), Free: uint64(memUsg[2]), UsedMMap: uint64(memUsg[3]), + TotalAlloc: uint64(memUsg[4]), FreeChunks: uint64(memUsg[5]), Releasable: uint64(memUsg[6]), + } + } 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 + if strings.Contains(string(stat.Name), MemoryStatSegPrefix) { + _, 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 + } + } else if strings.Contains(string(stat.Name), MemoryStatPrefix) { + if perHeapStats, ok := stat.Data.(adapter.SimpleCounterStat); ok { + if memStats.Stat == nil { + memStats.Stat = make(map[int]api.MemoryCounters) + } + for heap, stats := range perHeapStats { + memStats.Stat[heap] = convertStats(stats) + } + } + } else if strings.Contains(string(stat.Name), MemoryMainPrefix) { + if perHeapStats, ok := stat.Data.(adapter.SimpleCounterStat); ok { + if memStats.Main == nil { + memStats.Main = make(map[int]api.MemoryCounters) + } + for heap, stats := range perHeapStats { + memStats.Main[heap] = convertStats(stats) + } + } } } return nil |