From d03809c8519980146678134b3350d92e6cd89bce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kawa=20Acikgo=CC=88z?= <kawa.acikgoez@open-xchange.com> Date: Fri, 29 Sep 2023 11:30:50 +0200 Subject: [PATCH] Add: redis memory gauge --- src/cache.js | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/cache.js b/src/cache.js index eee5712..aa6bf69 100644 --- a/src/cache.js +++ b/src/cache.js @@ -47,6 +47,35 @@ export const versionCountGauge = new Gauge({ } }) +export const usedMemoryGauge = new Gauge({ + name: 'redis_used_ram', + help: 'Total used memory in human readable units and as a percentage (RSS / total memory)', + labelNames: ['memory_type'], + async collect () { + redis.client.info('memory', (err, result) => { + if (err) { + throw err + } + + // Parse the result + const infoLines = result.split('\r\n') + const memoryInfo = {} + + for (const line of infoLines) { + const [key, value] = line.split(':') + if (key && value) { + memoryInfo[key] = value + } + } + const usedMemoryRSS = parseFloat(memoryInfo.used_memory_rss) + const memoryTotal = parseFloat(memoryInfo.total_system_memory) + + this.set({ memory_type: 'usedMemoryRSSHuman' }, usedMemoryRSS) + this.set({ memory_type: 'totalUsedMemoryPercentage' }, usedMemoryRSS / memoryTotal) + }) + } +}) + export function set (key, value, timeout) { logger.debug(`[Cache] Set ${key}`) if (cache[key] === value) return @@ -62,7 +91,6 @@ export async function clear () { } fileCacheSizeGauge.reset() } - export async function get (key, fallback) { if (cache[key]) { logger.debug(`[Cache] Resolve from memory: ${key}`) -- GitLab