Further work
CI / test (push) Successful in 1m7s
Release rolling / release (push) Successful in 7m8s

This commit is contained in:
Raven Scott
2026-07-21 12:33:03 -04:00
parent ac4718cb66
commit 98a5f6fdfc
2 changed files with 22 additions and 13 deletions
+9 -1
View File
@@ -25,6 +25,14 @@ import logger from '../../utils/logger.js'
const log = logger.child('cgroups')
const HOST_CPUS = (() => {
try {
return os.cpus().length || 1
} catch {
return 1
}
})()
export function isCgroupsEnabled() {
const v = process.env.PEARDATA_CGROUPS
if (v === '0' || v === 'off' || v === 'false') return false
@@ -241,7 +249,7 @@ export class CgroupsCollector extends EventEmitter {
const ts = Date.now()
const dtSec = this.lastTs ? (ts - this.lastTs) / 1000 : this.intervalMs / 1000
this.lastTs = ts
const ncpu = os.cpus().length || 1
const ncpu = HOST_CPUS
/** @type {Array<{ chart: string, context: string, ts: number, values: object }>} */
const batch = []
+13 -12
View File
@@ -30,18 +30,18 @@ export function isProcessCollectorEnabled() {
return os.platform() === 'linux'
}
function topN() {
const n = Number(process.env.PEARDATA_PROCESSES_TOP)
return Number.isFinite(n) && n > 0 ? Math.min(32, Math.floor(n)) : 8
}
function hostCpus() {
const HOST_CPUS = (() => {
try {
return os.cpus().length || 1
} catch {
return 1
}
}
})()
const PROC_LIMIT = (() => {
const n = Number(process.env.PEARDATA_PROCESSES_TOP)
return Number.isFinite(n) && n > 0 ? Math.min(32, Math.floor(n)) : 8
})()
function sanitizeDim(name) {
const s = String(name || 'unknown')
@@ -68,6 +68,7 @@ export function listProcStats() {
}
procTickCount = (procTickCount + 1) % PROC_EXTRA_TICK
const readExtra = procTickCount === 0
if (readExtra) PROC_EXTRA_CACHE.clear()
/** @type {Array<{ pid: number, name: string, utime: number, stime: number, rssPages: number, threads: number, readBytes: number|null, writeBytes: number|null }>} */
const out = []
@@ -141,7 +142,7 @@ function pageSize() {
* @param {'cpu'|'rss'|'io'|'threads'} kind
*/
function registerTopChart(names, kind) {
const dims = [...new Set(names)].slice(0, topN()).map((id) => ({
const dims = [...new Set(names)].slice(0, PROC_LIMIT).map((id) => ({
id,
name: id,
algorithm: 'absolute',
@@ -211,7 +212,7 @@ function registerTopChart(names, kind) {
export class ProcessCollector extends EventEmitter {
constructor(opts = {}) {
super()
this.intervalMs = opts.intervalMs || Number(process.env.PEARDATA_SAMPLE_MS) || SAMPLE_INTERVAL_MS
this.intervalMs = opts.intervalMs || Number(process.env.PEARDATA_PROCESSES_MS) || Number(process.env.PEARDATA_SAMPLE_MS) || SAMPLE_INTERVAL_MS
this._timer = null
/** @type {Map<number, { ticks: number, wallMs: number, name: string, readBytes: number, writeBytes: number }>|null} */
this._prev = null
@@ -221,7 +222,7 @@ export class ProcessCollector extends EventEmitter {
start() {
if (this._timer) return
this._pageBytes = pageSize()
log.info('Process top-N collector started', { top: topN() })
log.info('Process top-N collector started', { top: PROC_LIMIT })
this._tick()
this._timer = setInterval(() => this._tick(), this.intervalMs)
if (typeof this._timer.unref === 'function') this._timer.unref()
@@ -240,8 +241,8 @@ export class ProcessCollector extends EventEmitter {
if (!procs) return
const ts = Date.now()
const wallMs = ts
const ncpu = hostCpus()
const limit = topN()
const ncpu = HOST_CPUS
const limit = PROC_LIMIT
/** @type {Map<string, number>} */
const cpuByName = new Map()