Skip to content

Commit 6c0555d

Browse files
committed
Update 'GetMemory' regex
* VPP show memory regex now works correctly * Command extended with 'verbose' to match VPPTop requirements Signed-off-by: Vladimir Lavor <[email protected]>
1 parent bdb6a98 commit 6c0555d

File tree

8 files changed

+115
-76
lines changed

8 files changed

+115
-76
lines changed

examples/vpp_stats/main.go

+20
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ func (p *StatsExamplePlugin) processStats() {
125125
errors = append(errors, fmt.Errorf("eroror retireving threads: %v", err))
126126
}
127127

128+
memoryInfo, err := p.handler.GetMemory(context.Background())
129+
fmt.Printf("mem %v, err %v", memoryInfo, err)
130+
if err != nil {
131+
errors = append(errors, fmt.Errorf("eroror retireving memory info: %v", err))
132+
}
133+
128134
// print all errors and return if there is any
129135
if len(errors) != 0 {
130136
for _, err := range errors {
@@ -140,6 +146,7 @@ func (p *StatsExamplePlugin) processStats() {
140146
printRuntimeInfo(runtimeInfo)
141147
printBufferInfo(bufferInfo)
142148
printThreadsInfo(threadsInfo)
149+
printMemoryInfo(memoryInfo)
143150
}
144151

145152
func printIfStats(ifStats *api.InterfaceStats) {
@@ -213,3 +220,16 @@ Thread name: %s (ID %d)
213220
`, thread.Name, thread.ID, thread.Type, thread.PID, thread.Core, thread.CPUID, thread.CPUSocket)
214221
}
215222
}
223+
224+
func printMemoryInfo(memoryInfo *vppcalls.MemoryInfo) {
225+
for _, thread := range memoryInfo.GetThreads() {
226+
fmt.Printf(`
227+
Thread %d %s
228+
size %d, %d pages, page size %d
229+
total: %d, used: %d, free: %d, trimmable: %d
230+
free chunks %d free fastbin blks %d
231+
max total allocated %d
232+
`, thread.ID, thread.Name, thread.Size, thread.Pages, thread.PageSize, thread.Total, thread.Used,
233+
thread.Free, thread.Trimmable, thread.FreeChunks, thread.FreeFastbinBlks, thread.MaxTotalAlloc)
234+
}
235+
}

plugins/telemetry/prometheus.go

+18-14
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,16 @@ const (
5454
memoryThreadLabel = "thread"
5555
memoryThreadIDLabel = "threadID"
5656

57-
memoryObjectsMetric = "objects"
58-
memoryUsedMetric = "used"
59-
memoryTotalMetric = "total"
60-
memoryFreeMetric = "free"
61-
memoryReclaimedMetric = "reclaimed"
62-
memoryOverheadMetric = "overhead"
63-
memorySizeMetric = "size"
64-
memoryPagesMetric = "pages"
57+
memoryObjectsMetric = "objects"
58+
memoryUsedMetric = "used"
59+
memoryTotalMetric = "total"
60+
memoryFreeMetric = "free"
61+
memoryTrimmableMetric = "trimmable"
62+
memoryFreeChunksMetric = "free_chunks"
63+
memoryFreeFastbinBlksMetric = "free_fastbin_blks"
64+
memoryMaxTotalAlloc = "max_total_allocated"
65+
memorySizeMetric = "size"
66+
memoryPagesMetric = "pages"
6567
)
6668

6769
// Buffers metrics
@@ -181,7 +183,6 @@ func (p *Plugin) registerPrometheus() error {
181183
agentLabel: p.ServiceLabel.GetAgentLabel(),
182184
},
183185
}, []string{runtimeItemLabel, runtimeThreadLabel, runtimeThreadIDLabel})
184-
185186
}
186187

187188
// register created vectors to prometheus
@@ -201,10 +202,12 @@ func (p *Plugin) registerPrometheus() error {
201202
{memoryUsedMetric, "Used memory"},
202203
{memoryTotalMetric, "Total memory"},
203204
{memoryFreeMetric, "Free memory"},
204-
{memoryReclaimedMetric, "Reclaimed memory"},
205-
{memoryOverheadMetric, "Overhead"},
206205
{memorySizeMetric, "Size"},
207206
{memoryPagesMetric, "Pages"},
207+
{memoryTrimmableMetric, "Trimmable"},
208+
{memoryFreeChunksMetric, "Free Chunks"},
209+
{memoryFreeFastbinBlksMetric, "Free Fastbin Bulks"},
210+
{memoryMaxTotalAlloc, "Max Total Allocations"},
208211
} {
209212
name := metric[0]
210213
p.memoryGaugeVecs[name] = prometheus.NewGaugeVec(prometheus.GaugeOpts{
@@ -443,14 +446,15 @@ func (p *Plugin) updatePrometheus(ctx context.Context) {
443446
}
444447
}
445448

446-
stats.metrics[memoryObjectsMetric].Set(float64(thread.Objects))
447449
stats.metrics[memoryUsedMetric].Set(float64(thread.Used))
448450
stats.metrics[memoryTotalMetric].Set(float64(thread.Total))
449451
stats.metrics[memoryFreeMetric].Set(float64(thread.Free))
450-
stats.metrics[memoryReclaimedMetric].Set(float64(thread.Reclaimed))
451-
stats.metrics[memoryOverheadMetric].Set(float64(thread.Overhead))
452452
stats.metrics[memorySizeMetric].Set(float64(thread.Size))
453453
stats.metrics[memoryPagesMetric].Set(float64(thread.Pages))
454+
stats.metrics[memoryTrimmableMetric].Set(float64(thread.Trimmable))
455+
stats.metrics[memoryFreeChunksMetric].Set(float64(thread.FreeChunks))
456+
stats.metrics[memoryFreeFastbinBlksMetric].Set(float64(thread.FreeFastbinBlks))
457+
stats.metrics[memoryMaxTotalAlloc].Set(float64(thread.MaxTotalAlloc))
454458
}
455459
}
456460
}

plugins/telemetry/vppcalls/telemetry_handler_api.go

+12-11
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,18 @@ func (i *MemoryInfo) GetThreads() []MemoryThread {
5555

5656
// MemoryThread represents single thread memory counters
5757
type MemoryThread struct {
58-
ID uint `json:"id"`
59-
Name string `json:"name"`
60-
Size uint64 `json:"size"`
61-
Objects uint64 `json:"objects"`
62-
Used uint64 `json:"used"`
63-
Total uint64 `json:"total"`
64-
Free uint64 `json:"free"`
65-
Reclaimed uint64 `json:"reclaimed"`
66-
Overhead uint64 `json:"overhead"`
67-
Pages uint64 `json:"pages"`
68-
PageSize uint64 `json:"page_size"`
58+
ID uint `json:"id"`
59+
Name string `json:"name"`
60+
Size uint64 `json:"size"`
61+
Pages uint64 `json:"pages"`
62+
PageSize uint64 `json:"page_size"`
63+
Total uint64 `json:"total"`
64+
Used uint64 `json:"used"`
65+
Free uint64 `json:"free"`
66+
Trimmable uint64 `json:"trimmable"`
67+
FreeChunks uint64 `json:"free_chunks"`
68+
FreeFastbinBlks uint64 `json:"free_fastbin_blks"`
69+
MaxTotalAlloc uint64 `json:"max_total_allocated"`
6970
}
7071

7172
// NodeCounterInfo contains node counters info.

plugins/telemetry/vppcalls/telemetry_stats.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ func (h *TelemetryStats) GetMemory(ctx context.Context) (*MemoryInfo, error) {
6161
if h.telemetryAPI == nil {
6262
return nil, fmt.Errorf("`GetMemory` unavailable, telemetry handler was not provided")
6363
}
64-
// todo failing, temporary disabled
65-
// return h.telemetryAPI.GetMemory(ctx)
66-
return nil, nil
64+
return h.telemetryAPI.GetMemory(ctx)
6765
}
6866

6967
// GetThreads retrieves `show threads` info.

plugins/telemetry/vppcalls/vpp1908/telemetry_vppcalls.go

+16-12
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,14 @@ var (
3737
`virtual memory start 0x[0-9a-f]+, size ([\dkmg\.]+), ([\dkmg\.]+) pages, page size ([\dkmg\.]+)\s+` +
3838
`(?:page information not available.*\s+)*` +
3939
`(?:(?:\s+(?:numa [\d]+|not mapped|unknown): [\dkmg\.]+ pages, [\dkmg\.]+\s+)*\s+)*` +
40-
`\s+total: ([\dkmgKMG\.]+), used: ([\dkmgKMG\.]+), free: ([\dkmgKMG\.]+), trimmable: ([\dkmgKMG\.]+)`,
40+
`\s+total: ([\dkmgKMG\.]+), used: ([\dkmgKMG\.]+), free: ([\dkmgKMG\.]+), trimmable: ([\dkmgKMG\.]+)\s+` +
41+
`free chunks (\d+)\s+free fastbin blks (\d+)\s+max total allocated\s+([\dkmgKMG\.]+)`,
4142
)
4243
)
4344

4445
// GetMemory retrieves `show memory` info.
4546
func (h *TelemetryHandler) GetMemory(ctx context.Context) (*vppcalls.MemoryInfo, error) {
46-
input, err := h.vpe.RunCli(context.TODO(), "show memory main-heap")
47+
input, err := h.vpe.RunCli(context.TODO(), "show memory main-heap verbose")
4748
if err != nil {
4849
return nil, err
4950
}
@@ -57,23 +58,26 @@ func (h *TelemetryHandler) GetMemory(ctx context.Context) (*vppcalls.MemoryInfo,
5758
var threads []vppcalls.MemoryThread
5859
for _, matches := range threadMatches {
5960
fields := matches[1:]
60-
if len(fields) != 9 {
61+
if len(fields) != 12 {
6162
return nil, fmt.Errorf("invalid memory data %v for thread: %q", fields, matches[0])
6263
}
6364
id, err := strconv.ParseUint(fields[0], 10, 64)
6465
if err != nil {
6566
return nil, err
6667
}
6768
thread := &vppcalls.MemoryThread{
68-
ID: uint(id),
69-
Name: fields[1],
70-
Size: strToUint64(fields[2]),
71-
Pages: strToUint64(fields[3]),
72-
PageSize: strToUint64(fields[4]),
73-
Total: strToUint64(fields[5]),
74-
Used: strToUint64(fields[6]),
75-
Free: strToUint64(fields[7]),
76-
Reclaimed: strToUint64(fields[8]),
69+
ID: uint(id),
70+
Name: fields[1],
71+
Size: strToUint64(fields[2]),
72+
Pages: strToUint64(fields[3]),
73+
PageSize: strToUint64(fields[4]),
74+
Total: strToUint64(fields[5]),
75+
Used: strToUint64(fields[6]),
76+
Free: strToUint64(fields[7]),
77+
Trimmable: strToUint64(fields[8]),
78+
FreeChunks: strToUint64(fields[9]),
79+
FreeFastbinBlks: strToUint64(fields[10]),
80+
MaxTotalAlloc: strToUint64(fields[11]),
7781
}
7882
threads = append(threads, *thread)
7983
}

plugins/telemetry/vppcalls/vpp2001/telemetry_vppcalls.go

+16-12
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,14 @@ var (
3737
`virtual memory start 0x[0-9a-f]+, size ([\dkmg\.]+), ([\dkmg\.]+) pages, page size ([\dkmg\.]+)\s+` +
3838
`(?:page information not available.*\s+)*` +
3939
`(?:(?:\s+(?:numa [\d]+|not mapped|unknown): [\dkmg\.]+ pages, [\dkmg\.]+\s+)*\s+)*` +
40-
`\s+total: ([\dkmgKMG\.]+), used: ([\dkmgKMG\.]+), free: ([\dkmgKMG\.]+), trimmable: ([\dkmgKMG\.]+)`,
40+
`\s+total: ([\dkmgKMG\.]+), used: ([\dkmgKMG\.]+), free: ([\dkmgKMG\.]+), trimmable: ([\dkmgKMG\.]+)\s+` +
41+
`free chunks (\d+)\s+free fastbin blks (\d+)\s+max total allocated\s+([\dkmgKMG\.]+)`,
4142
)
4243
)
4344

4445
// GetMemory retrieves `show memory` info.
4546
func (h *TelemetryHandler) GetMemory(ctx context.Context) (*vppcalls.MemoryInfo, error) {
46-
input, err := h.vpe.RunCli(context.TODO(), "show memory main-heap")
47+
input, err := h.vpe.RunCli(context.TODO(), "show memory main-heap verbose")
4748
if err != nil {
4849
return nil, err
4950
}
@@ -57,23 +58,26 @@ func (h *TelemetryHandler) GetMemory(ctx context.Context) (*vppcalls.MemoryInfo,
5758
var threads []vppcalls.MemoryThread
5859
for _, matches := range threadMatches {
5960
fields := matches[1:]
60-
if len(fields) != 9 {
61+
if len(fields) != 12 {
6162
return nil, fmt.Errorf("invalid memory data %v for thread: %q", fields, matches[0])
6263
}
6364
id, err := strconv.ParseUint(fields[0], 10, 64)
6465
if err != nil {
6566
return nil, err
6667
}
6768
thread := &vppcalls.MemoryThread{
68-
ID: uint(id),
69-
Name: fields[1],
70-
Size: strToUint64(fields[2]),
71-
Pages: strToUint64(fields[3]),
72-
PageSize: strToUint64(fields[4]),
73-
Total: strToUint64(fields[5]),
74-
Used: strToUint64(fields[6]),
75-
Free: strToUint64(fields[7]),
76-
Reclaimed: strToUint64(fields[8]),
69+
ID: uint(id),
70+
Name: fields[1],
71+
Size: strToUint64(fields[2]),
72+
Pages: strToUint64(fields[3]),
73+
PageSize: strToUint64(fields[4]),
74+
Total: strToUint64(fields[5]),
75+
Used: strToUint64(fields[6]),
76+
Free: strToUint64(fields[7]),
77+
Trimmable: strToUint64(fields[8]),
78+
FreeChunks: strToUint64(fields[9]),
79+
FreeFastbinBlks: strToUint64(fields[10]),
80+
MaxTotalAlloc: strToUint64(fields[11]),
7781
}
7882
threads = append(threads, *thread)
7983
}

plugins/telemetry/vppcalls/vpp2005/telemetry_vppcalls.go

+16-12
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,14 @@ var (
3737
`virtual memory start 0x[0-9a-f]+, size ([\dkmg\.]+), ([\dkmg\.]+) pages, page size ([\dkmg\.]+)\s+` +
3838
`(?:page information not available.*\s+)*` +
3939
`(?:(?:\s+(?:numa [\d]+|not mapped|unknown): [\dkmg\.]+ pages, [\dkmg\.]+\s+)*\s+)*` +
40-
`\s+total: ([\dkmgKMG\.]+), used: ([\dkmgKMG\.]+), free: ([\dkmgKMG\.]+), trimmable: ([\dkmgKMG\.]+)`,
40+
`\s+total: ([\dkmgKMG\.]+), used: ([\dkmgKMG\.]+), free: ([\dkmgKMG\.]+), trimmable: ([\dkmgKMG\.]+)\s+` +
41+
`free chunks (\d+)\s+free fastbin blks (\d+)\s+max total allocated\s+([\dkmgKMG\.]+)`,
4142
)
4243
)
4344

4445
// GetMemory retrieves `show memory` info.
4546
func (h *TelemetryHandler) GetMemory(ctx context.Context) (*vppcalls.MemoryInfo, error) {
46-
input, err := h.vpe.RunCli(context.TODO(), "show memory main-heap")
47+
input, err := h.vpe.RunCli(context.TODO(), "show memory main-heap verbose")
4748
if err != nil {
4849
return nil, err
4950
}
@@ -57,23 +58,26 @@ func (h *TelemetryHandler) GetMemory(ctx context.Context) (*vppcalls.MemoryInfo,
5758
var threads []vppcalls.MemoryThread
5859
for _, matches := range threadMatches {
5960
fields := matches[1:]
60-
if len(fields) != 9 {
61+
if len(fields) != 12 {
6162
return nil, fmt.Errorf("invalid memory data %v for thread: %q", fields, matches[0])
6263
}
6364
id, err := strconv.ParseUint(fields[0], 10, 64)
6465
if err != nil {
6566
return nil, err
6667
}
6768
thread := &vppcalls.MemoryThread{
68-
ID: uint(id),
69-
Name: fields[1],
70-
Size: strToUint64(fields[2]),
71-
Pages: strToUint64(fields[3]),
72-
PageSize: strToUint64(fields[4]),
73-
Total: strToUint64(fields[5]),
74-
Used: strToUint64(fields[6]),
75-
Free: strToUint64(fields[7]),
76-
Reclaimed: strToUint64(fields[8]),
69+
ID: uint(id),
70+
Name: fields[1],
71+
Size: strToUint64(fields[2]),
72+
Pages: strToUint64(fields[3]),
73+
PageSize: strToUint64(fields[4]),
74+
Total: strToUint64(fields[5]),
75+
Used: strToUint64(fields[6]),
76+
Free: strToUint64(fields[7]),
77+
Trimmable: strToUint64(fields[8]),
78+
FreeChunks: strToUint64(fields[9]),
79+
FreeFastbinBlks: strToUint64(fields[10]),
80+
MaxTotalAlloc: strToUint64(fields[11]),
7781
}
7882
threads = append(threads, *thread)
7983
}

plugins/telemetry/vppcalls/vpp2009/telemetry_vppcalls.go

+16-12
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,14 @@ var (
3737
`virtual memory start 0x[0-9a-f]+, size ([\dkmg\.]+), ([\dkmg\.]+) pages, page size ([\dkmg\.]+)\s+` +
3838
`(?:page information not available.*\s+)*` +
3939
`(?:(?:\s+(?:numa [\d]+|not mapped|unknown): [\dkmg\.]+ pages, [\dkmg\.]+\s+)*\s+)*` +
40-
`\s+total: ([\dkmgKMG\.]+), used: ([\dkmgKMG\.]+), free: ([\dkmgKMG\.]+), trimmable: ([\dkmgKMG\.]+)`,
40+
`\s+total: ([\dkmgKMG\.]+), used: ([\dkmgKMG\.]+), free: ([\dkmgKMG\.]+), trimmable: ([\dkmgKMG\.]+)\s+` +
41+
`free chunks (\d+)\s+free fastbin blks (\d+)\s+max total allocated\s+([\dkmgKMG\.]+)`,
4142
)
4243
)
4344

4445
// GetMemory retrieves `show memory` info.
4546
func (h *TelemetryHandler) GetMemory(ctx context.Context) (*vppcalls.MemoryInfo, error) {
46-
input, err := h.vpe.RunCli(context.TODO(), "show memory main-heap")
47+
input, err := h.vpe.RunCli(context.TODO(), "show memory main-heap verbose")
4748
if err != nil {
4849
return nil, err
4950
}
@@ -57,23 +58,26 @@ func (h *TelemetryHandler) GetMemory(ctx context.Context) (*vppcalls.MemoryInfo,
5758
var threads []vppcalls.MemoryThread
5859
for _, matches := range threadMatches {
5960
fields := matches[1:]
60-
if len(fields) != 9 {
61+
if len(fields) != 12 {
6162
return nil, fmt.Errorf("invalid memory data %v for thread: %q", fields, matches[0])
6263
}
6364
id, err := strconv.ParseUint(fields[0], 10, 64)
6465
if err != nil {
6566
return nil, err
6667
}
6768
thread := &vppcalls.MemoryThread{
68-
ID: uint(id),
69-
Name: fields[1],
70-
Size: strToUint64(fields[2]),
71-
Pages: strToUint64(fields[3]),
72-
PageSize: strToUint64(fields[4]),
73-
Total: strToUint64(fields[5]),
74-
Used: strToUint64(fields[6]),
75-
Free: strToUint64(fields[7]),
76-
Reclaimed: strToUint64(fields[8]),
69+
ID: uint(id),
70+
Name: fields[1],
71+
Size: strToUint64(fields[2]),
72+
Pages: strToUint64(fields[3]),
73+
PageSize: strToUint64(fields[4]),
74+
Total: strToUint64(fields[5]),
75+
Used: strToUint64(fields[6]),
76+
Free: strToUint64(fields[7]),
77+
Trimmable: strToUint64(fields[8]),
78+
FreeChunks: strToUint64(fields[9]),
79+
FreeFastbinBlks: strToUint64(fields[10]),
80+
MaxTotalAlloc: strToUint64(fields[11]),
7781
}
7882
threads = append(threads, *thread)
7983
}

0 commit comments

Comments
 (0)