collectd: fix memory stat collection configuration
https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v1/memory.html#usage-in-bytes says this is the most efficient approach for v1. It says RSS+CACHE(+SWAP) is the more accurate value. Elsewhere in the note in https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v1/memory.html#stat-file, it says "‘rss + mapped_file” will give you resident set size of cgroup." Overall, it's not clear how to compute the values so we just use the file. https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html is better. https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html#memory says the values are separated out.
This commit is contained in:
+11
-5
@@ -6,12 +6,15 @@ exports = module.exports = {
|
||||
|
||||
const assert = require('assert'),
|
||||
BoxError = require('./boxerror.js'),
|
||||
fs = require('fs'),
|
||||
safe = require('safetydance'),
|
||||
superagent = require('superagent'),
|
||||
debug = require('debug')('box:graphs');
|
||||
superagent = require('superagent');
|
||||
|
||||
const GRAPHITE_RENDER_URL = 'http://127.0.0.1:8417/graphite-web/render';
|
||||
|
||||
// https://rootlesscontaine.rs/getting-started/common/cgroup2/#checking-whether-cgroup-v2-is-already-enabled
|
||||
const CGROUP_VERSION = fs.existsSync('/sys/fs/cgroup/cgroup.controllers') ? '2' : '1';
|
||||
|
||||
async function getByAppId(appId, fromMinutes, noNullPoints) {
|
||||
assert.strictEqual(typeof appId, 'string');
|
||||
assert.strictEqual(typeof fromMinutes, 'number');
|
||||
@@ -19,14 +22,17 @@ async function getByAppId(appId, fromMinutes, noNullPoints) {
|
||||
|
||||
const timeBucketSize = fromMinutes > (24 * 60) ? (6*60) : 5;
|
||||
|
||||
debug(`getByAppId: ${appId} from ${fromMinutes}`);
|
||||
|
||||
const memoryQuery = {
|
||||
target: `summarize(sum(collectd.localhost.table-${appId}-memory.gauge-rss, collectd.localhost.table-${appId}-memory.gauge-swap), "${timeBucketSize}min", "avg")`,
|
||||
target: null, // filled below
|
||||
format: 'json',
|
||||
from: `-${fromMinutes}min`,
|
||||
until: 'now'
|
||||
};
|
||||
if (CGROUP_VERSION === '1') {
|
||||
memoryQuery.target = `summarize(collectd.localhost.table-${appId}-memory.gauge-memsw_usage_in_bytes, "${timeBucketSize}min", "avg")`;
|
||||
} else {
|
||||
memoryQuery.target = `summarize(sum(collectd.localhost.table-${appId}-memory.gauge-memory_current, collectd.localhost.table-${appId}-memory.gauge-memory_swap_current), "${timeBucketSize}min", "avg")`;
|
||||
}
|
||||
if (noNullPoints) memoryQuery.noNullPoints = true;
|
||||
|
||||
const [memoryError, memoryResponse] = await safe(superagent.get(GRAPHITE_RENDER_URL)
|
||||
|
||||
Reference in New Issue
Block a user