feat(telemetry): report openclaw and plugin versions separately

- Report remote OpenClaw CLI version as openclaw_version
- Report harborforge-monitor plugin version as plugin_version
- Pass plugin version from plugin runtime to sidecar
- Read live config via api.pluginConfig/api.config helper
This commit is contained in:
zhi
2026-03-20 07:23:18 +00:00
parent 006784db63
commit 040cde8cad
6 changed files with 73 additions and 6 deletions

15
plugin/core/live-config.d.ts vendored Normal file
View File

@@ -0,0 +1,15 @@
export interface HarborForgeMonitorConfig {
enabled?: boolean;
backendUrl?: string;
identifier?: string;
apiKey?: string;
reportIntervalSec?: number;
httpFallbackIntervalSec?: number;
logLevel?: 'debug' | 'info' | 'warn' | 'error';
}
interface OpenClawPluginApiLike {
config?: Record<string, unknown>;
}
export declare function getLivePluginConfig(api: OpenClawPluginApiLike, fallback: HarborForgeMonitorConfig): HarborForgeMonitorConfig;
export {};
//# sourceMappingURL=live-config.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"live-config.d.ts","sourceRoot":"","sources":["live-config.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,wBAAwB;IACvC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;CAChD;AAED,UAAU,qBAAqB;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,qBAAqB,EAC1B,QAAQ,EAAE,wBAAwB,GACjC,wBAAwB,CAqB1B"}

View File

@@ -0,0 +1,23 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getLivePluginConfig = getLivePluginConfig;
function getLivePluginConfig(api, fallback) {
const root = api.config || {};
const plugins = root.plugins || {};
const entries = plugins.entries || {};
const entry = entries['harborforge-monitor'] || {};
const cfg = entry.config || {};
if (Object.keys(cfg).length > 0 || Object.keys(entry).length > 0) {
return {
...fallback,
...cfg,
enabled: typeof cfg.enabled === 'boolean'
? cfg.enabled
: typeof entry.enabled === 'boolean'
? entry.enabled
: fallback.enabled,
};
}
return fallback;
}
//# sourceMappingURL=live-config.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"live-config.js","sourceRoot":"","sources":["live-config.ts"],"names":[],"mappings":";;AAcA,kDAwBC;AAxBD,SAAgB,mBAAmB,CACjC,GAA0B,EAC1B,QAAkC;IAElC,MAAM,IAAI,GAAI,GAAG,CAAC,MAAkC,IAAI,EAAE,CAAC;IAC3D,MAAM,OAAO,GAAI,IAAI,CAAC,OAAmC,IAAI,EAAE,CAAC;IAChE,MAAM,OAAO,GAAI,OAAO,CAAC,OAAmC,IAAI,EAAE,CAAC;IACnE,MAAM,KAAK,GAAI,OAAO,CAAC,qBAAqB,CAA6B,IAAI,EAAE,CAAC;IAChF,MAAM,GAAG,GAAI,KAAK,CAAC,MAAkC,IAAI,EAAE,CAAC;IAE5D,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACjE,OAAO;YACL,GAAG,QAAQ;YACX,GAAG,GAAG;YACN,OAAO,EACL,OAAO,GAAG,CAAC,OAAO,KAAK,SAAS;gBAC9B,CAAC,CAAC,GAAG,CAAC,OAAO;gBACb,CAAC,CAAC,OAAO,KAAK,CAAC,OAAO,KAAK,SAAS;oBAClC,CAAC,CAAC,KAAK,CAAC,OAAO;oBACf,CAAC,CAAC,QAAQ,CAAC,OAAO;SACG,CAAC;IAChC,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC"}

View File

@@ -92,7 +92,7 @@ export default {
HF_MONITOR_HTTP_FALLBACK_INTERVAL: String(live.httpFallbackIntervalSec || 60),
HF_MONITOR_LOG_LEVEL: live.logLevel || 'info',
OPENCLAW_PATH: process.env.OPENCLAW_PATH || join(process.env.HOME || '/root', '.openclaw'),
OPENCLAW_VERSION: api.version || 'unknown',
HF_MONITOR_PLUGIN_VERSION: api.version || 'unknown',
};
sidecar = spawn('node', [serverPath], {

View File

@@ -22,7 +22,7 @@ const CONFIG = {
httpFallbackIntervalSec: parseInt(process.env.HF_MONITOR_HTTP_FALLBACK_INTERVAL || '60', 10),
logLevel: process.env.HF_MONITOR_LOG_LEVEL || 'info',
openclawPath,
openclawVersion: process.env.OPENCLAW_VERSION || 'unknown',
pluginVersion: process.env.HF_MONITOR_PLUGIN_VERSION || 'unknown',
cachePath: process.env.HF_MONITOR_CACHE_PATH || `${openclawPath}/telemetry_cache.json`,
maxCacheSize: parseInt(process.env.HF_MONITOR_MAX_CACHE_SIZE || '100', 10),
};
@@ -40,6 +40,7 @@ let wsConnection = null;
let lastSuccessfulSend = null;
let consecutiveFailures = 0;
let isShuttingDown = false;
let cachedOpenclawVersion = null;
/**
* Collect system metrics
@@ -136,14 +137,33 @@ function parseSizeToGB(size) {
return num;
}
async function resolveOpenclawVersion() {
if (cachedOpenclawVersion) return cachedOpenclawVersion;
try {
const { stdout } = await execAsync('openclaw --version');
const version = stdout.trim();
cachedOpenclawVersion = version || 'unknown';
return cachedOpenclawVersion;
} catch (err) {
log.debug('Failed to resolve OpenClaw version:', err.message);
cachedOpenclawVersion = 'unknown';
return cachedOpenclawVersion;
}
}
/**
* Collect OpenClaw status
*/
async function collectOpenclawStatus() {
try {
const agents = await getOpenclawAgents();
const [agents, openclawVersion] = await Promise.all([
getOpenclawAgents(),
resolveOpenclawVersion(),
]);
return {
version: CONFIG.openclawVersion,
openclawVersion,
pluginVersion: CONFIG.pluginVersion,
agent_count: agents.length,
agents: agents.map(a => ({
id: a.id,
@@ -153,7 +173,12 @@ async function collectOpenclawStatus() {
};
} catch (err) {
log.debug('Failed to collect OpenClaw status:', err.message);
return { version: CONFIG.openclawVersion, agent_count: 0, agents: [] };
return {
openclawVersion: await resolveOpenclawVersion(),
pluginVersion: CONFIG.pluginVersion,
agent_count: 0,
agents: [],
};
}
}
@@ -186,7 +211,8 @@ async function buildPayload() {
identifier: CONFIG.identifier,
timestamp: new Date().toISOString(),
...system,
openclaw_version: openclaw.version,
openclaw_version: openclaw.openclawVersion,
plugin_version: openclaw.pluginVersion,
agents: openclaw.agents,
};
}
@@ -279,6 +305,7 @@ log.info('Config:', {
backendUrl: CONFIG.backendUrl,
reportIntervalSec: CONFIG.reportIntervalSec,
hasApiKey: !!CONFIG.apiKey,
pluginVersion: CONFIG.pluginVersion,
});
if (!CONFIG.apiKey) {