feat: push OpenClaw metadata to Monitor bridge periodically
- MonitorBridgeClient gains pushOpenClawMeta() method for POST /openclaw - OpenClawMeta interface defines version/plugin_version/agents payload - Plugin pushes metadata on gateway_start (delayed 2s) and periodically - Interval aligns with reportIntervalSec (default 30s) - Pushes are non-fatal — plugin continues if Monitor is unreachable - Interval cleanup on gateway_stop - Updated monitor-server-connector-plan.md with new architecture
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
*/
|
||||
import { hostname, freemem, totalmem, uptime, loadavg, platform } from 'os';
|
||||
import { getLivePluginConfig, type HarborForgeMonitorConfig } from './core/live-config';
|
||||
import { MonitorBridgeClient } from './core/monitor-bridge';
|
||||
import { MonitorBridgeClient, type OpenClawMeta } from './core/monitor-bridge';
|
||||
|
||||
interface PluginAPI {
|
||||
logger: {
|
||||
@@ -93,12 +93,56 @@ export default {
|
||||
};
|
||||
}
|
||||
|
||||
// Periodic metadata push interval handle
|
||||
let metaPushInterval: ReturnType<typeof setInterval> | null = null;
|
||||
|
||||
/**
|
||||
* Push OpenClaw metadata to the Monitor bridge.
|
||||
* This enriches Monitor heartbeats with OpenClaw version/plugin/agent info.
|
||||
* Failures are non-fatal — Monitor continues to work without this data.
|
||||
*/
|
||||
async function pushMetaToMonitor() {
|
||||
const bridgeClient = getBridgeClient();
|
||||
if (!bridgeClient) return;
|
||||
|
||||
const meta: OpenClawMeta = {
|
||||
version: api.version || 'unknown',
|
||||
plugin_version: '0.2.0',
|
||||
agents: [], // TODO: populate from api agent list when available
|
||||
};
|
||||
|
||||
const ok = await bridgeClient.pushOpenClawMeta(meta);
|
||||
if (ok) {
|
||||
logger.debug('pushed OpenClaw metadata to Monitor bridge');
|
||||
} else {
|
||||
logger.debug('Monitor bridge unreachable for metadata push (non-fatal)');
|
||||
}
|
||||
}
|
||||
|
||||
api.on('gateway_start', () => {
|
||||
logger.info('HarborForge plugin active');
|
||||
|
||||
// Push metadata to Monitor bridge on startup and periodically.
|
||||
// Interval aligns with typical Monitor heartbeat cycle (30s).
|
||||
// If Monitor bridge is unreachable, pushes silently fail.
|
||||
const live = resolveConfig();
|
||||
const intervalSec = live.reportIntervalSec || 30;
|
||||
|
||||
// Initial push (delayed 2s to let Monitor bridge start)
|
||||
setTimeout(() => pushMetaToMonitor(), 2000);
|
||||
|
||||
metaPushInterval = setInterval(
|
||||
() => pushMetaToMonitor(),
|
||||
intervalSec * 1000,
|
||||
);
|
||||
});
|
||||
|
||||
api.on('gateway_stop', () => {
|
||||
logger.info('HarborForge plugin stopping');
|
||||
if (metaPushInterval) {
|
||||
clearInterval(metaPushInterval);
|
||||
metaPushInterval = null;
|
||||
}
|
||||
});
|
||||
|
||||
// Tool: plugin status
|
||||
|
||||
Reference in New Issue
Block a user