Add resident memory and heap size metrics

Implement the default resident memory and heap size metrics.
This commit is contained in:
Hornwitser committed 2020-04-09 16:17:38 +02:00
1 parent e908c5069b
commit 56488b2c2d
2 files changed
+60

No files matched your search

+20
View File
@@ -409,6 +409,26 @@ defaultCollectors.processCpuSecondsTotal = new Gauge(
},
);
defaultCollectors.processResidentMemoryBytes = new Gauge(
'process_resident_memory_bytes',
"Resident memory size in bytes.",
{
callback: function() {
this.set(process.memoryUsage().rss);
},
},
);
defaultCollectors.processHeapBytes = new Gauge(
'process_heap_bytes',
"Process heap size in bytes.",
{
callback: function() {
this.set(process.memoryUsage().heapUsed);
},
},
);
defaultCollectors.processStartTimeSeconds = new Gauge(
'process_start_time_seconds',
"Start time of the process since unix epoch in seconds."
+40
View File
@@ -419,6 +419,46 @@ describe("lib/prometheus", function() {
);
});
});
describe("processResidentMemoryBytes", function() {
it("should give a low value", async function() {
let results = []
let collector = prometheus.defaultCollectors.processResidentMemoryBytes;
for await (let result of collector.collect()) {
results.push(result);
}
assert(
results.length == 1,
"collector did not give exactly one result"
);
let value = results[0].samples.get('')
assert(
value < 200e6 && value > 0,
`resident memory is not between 0 and 200 MB (${value})`
);
});
});
describe("processHeapBytes", function() {
it("should give a low value", async function() {
let results = []
let collector = prometheus.defaultCollectors.processHeapBytes;
for await (let result of collector.collect()) {
results.push(result);
}
assert(
results.length == 1,
"collector did not give exactly one result"
);
let value = results[0].samples.get('')
assert(
value < 200e6 && value > 0,
`heap is not between 0 and 200 MB (${value})`
);
});
});
});
describe("exposition()", function() {