fix: use runtime API for version and agent list instead of subprocess
Use api.runtime.version for openclaw version and api.runtime.config.loadConfig() for agent list. Eliminates the periodic openclaw agents list subprocess that caused high CPU usage.
This commit is contained in:
@@ -14,7 +14,7 @@
|
|||||||
import { hostname, freemem, totalmem, uptime, loadavg, platform } from 'os';
|
import { hostname, freemem, totalmem, uptime, loadavg, platform } from 'os';
|
||||||
import { getPluginConfig } from './core/config';
|
import { getPluginConfig } from './core/config';
|
||||||
import { MonitorBridgeClient, type OpenClawMeta } from './core/monitor-bridge';
|
import { MonitorBridgeClient, type OpenClawMeta } from './core/monitor-bridge';
|
||||||
import { listOpenClawAgents } from './core/openclaw-agents';
|
import type { OpenClawAgentInfo } from './core/openclaw-agents';
|
||||||
import { registerGatewayStartHook } from './hooks/gateway-start';
|
import { registerGatewayStartHook } from './hooks/gateway-start';
|
||||||
import { registerGatewayStopHook } from './hooks/gateway-stop';
|
import { registerGatewayStopHook } from './hooks/gateway-stop';
|
||||||
import {
|
import {
|
||||||
@@ -32,6 +32,12 @@ interface PluginAPI {
|
|||||||
warn: (...args: any[]) => void;
|
warn: (...args: any[]) => void;
|
||||||
};
|
};
|
||||||
version?: string;
|
version?: string;
|
||||||
|
runtime?: {
|
||||||
|
version?: string;
|
||||||
|
config?: {
|
||||||
|
loadConfig?: () => any;
|
||||||
|
};
|
||||||
|
};
|
||||||
config?: Record<string, unknown>;
|
config?: Record<string, unknown>;
|
||||||
pluginConfig?: Record<string, unknown>;
|
pluginConfig?: Record<string, unknown>;
|
||||||
on: (event: string, handler: () => void) => void;
|
on: (event: string, handler: () => void) => void;
|
||||||
@@ -96,7 +102,7 @@ export default {
|
|||||||
avg15: load[2],
|
avg15: load[2],
|
||||||
},
|
},
|
||||||
openclaw: {
|
openclaw: {
|
||||||
version: process.env.OPENCLAW_SERVICE_VERSION || api.version || 'unknown',
|
version: api.runtime?.version || api.version || 'unknown',
|
||||||
pluginVersion: '0.3.1', // Bumped for PLG-CAL-004
|
pluginVersion: '0.3.1', // Bumped for PLG-CAL-004
|
||||||
},
|
},
|
||||||
timestamp: new Date().toISOString(),
|
timestamp: new Date().toISOString(),
|
||||||
@@ -118,10 +124,21 @@ export default {
|
|||||||
const bridgeClient = getBridgeClient();
|
const bridgeClient = getBridgeClient();
|
||||||
if (!bridgeClient) return;
|
if (!bridgeClient) return;
|
||||||
|
|
||||||
|
let agentNames: string[] = [];
|
||||||
|
try {
|
||||||
|
const cfg = api.runtime?.config?.loadConfig?.();
|
||||||
|
const agentsList = cfg?.agents?.list;
|
||||||
|
if (Array.isArray(agentsList)) {
|
||||||
|
agentNames = agentsList
|
||||||
|
.map((a: any) => typeof a === 'string' ? a : a?.name)
|
||||||
|
.filter(Boolean);
|
||||||
|
}
|
||||||
|
} catch { /* non-fatal */ }
|
||||||
|
|
||||||
const meta: OpenClawMeta = {
|
const meta: OpenClawMeta = {
|
||||||
version: process.env.OPENCLAW_SERVICE_VERSION || api.version || 'unknown',
|
version: api.runtime?.version || api.version || 'unknown',
|
||||||
plugin_version: '0.3.1',
|
plugin_version: '0.3.1',
|
||||||
agents: await listOpenClawAgents(logger),
|
agents: agentNames.map(name => ({ name })),
|
||||||
};
|
};
|
||||||
|
|
||||||
const ok = await bridgeClient.pushOpenClawMeta(meta);
|
const ok = await bridgeClient.pushOpenClawMeta(meta);
|
||||||
|
|||||||
Reference in New Issue
Block a user