UNPKG

agentic-qe

Version:

Agentic Quality Engineering Fleet System - AI-driven quality management platform

147 lines 5.89 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.MetricsStream = exports.MonitorExport = void 0; const fs = __importStar(require("fs/promises")); class MonitorExport { constructor(dataDir) { this.templates = new Map(); this.dataDir = dataDir; this.hostname = require('os').hostname(); } async initialize() { await fs.mkdir(this.dataDir, { recursive: true }); } registerTemplate(name, template) { this.templates.set(name, template); } async export(metrics, format) { switch (format) { case 'prometheus': return this.exportPrometheus(metrics); case 'influxdb': return this.exportInfluxDB(metrics); case 'json': return this.exportJSON(metrics); case 'csv': return this.exportCSV(metrics); default: return this.exportCustom(metrics, format); } } exportPrometheus(metrics) { const lines = []; const timestamp = Date.now(); // CPU metrics lines.push('# HELP cpu_usage_percent CPU usage percentage'); lines.push('# TYPE cpu_usage_percent gauge'); const cpuAvg = this.average(metrics.cpu); lines.push(`cpu_usage_percent{host="${this.hostname}"} ${cpuAvg.toFixed(2)} ${timestamp}`); // Memory metrics lines.push('# HELP memory_usage_percent Memory usage percentage'); lines.push('# TYPE memory_usage_percent gauge'); const memAvg = this.average(metrics.memory); lines.push(`memory_usage_percent{host="${this.hostname}"} ${memAvg.toFixed(2)} ${timestamp}`); // Network metrics lines.push('# HELP network_usage_mbps Network usage in Mbps'); lines.push('# TYPE network_usage_mbps gauge'); const netAvg = this.average(metrics.network); lines.push(`network_usage_mbps{host="${this.hostname}"} ${netAvg.toFixed(2)} ${timestamp}`); return lines.join('\n'); } exportInfluxDB(metrics) { const lines = []; const timestamp = Date.now() * 1000000; // InfluxDB uses nanoseconds const cpuAvg = this.average(metrics.cpu); lines.push(`cpu,host=${this.hostname} value=${cpuAvg.toFixed(2)} ${timestamp}`); const memAvg = this.average(metrics.memory); lines.push(`memory,host=${this.hostname} value=${memAvg.toFixed(2)} ${timestamp}`); const netAvg = this.average(metrics.network); lines.push(`network,host=${this.hostname} value=${netAvg.toFixed(2)} ${timestamp}`); return lines.join('\n'); } exportJSON(metrics) { return JSON.stringify(metrics, null, 2); } exportCSV(metrics) { const lines = ['timestamp,metric,value']; const timestamp = metrics.timestamp; metrics.cpu.forEach((value, i) => { lines.push(`${timestamp + i * 1000},cpu,${value}`); }); metrics.memory.forEach((value, i) => { lines.push(`${timestamp + i * 1000},memory,${value}`); }); metrics.network.forEach((value, i) => { lines.push(`${timestamp + i * 1000},network,${value}`); }); return lines.join('\n'); } exportCustom(metrics, templateName) { const template = this.templates.get(templateName); if (!template) { throw new Error(`Template not found: ${templateName}`); } let output = template; output = output.replace('{cpu}', this.average(metrics.cpu).toFixed(1)); output = output.replace('{memory}', this.average(metrics.memory).toFixed(1)); output = output.replace('{network}', this.average(metrics.network).toFixed(1)); output = output.replace('{timestamp}', metrics.timestamp.toString()); return output; } async exportToFile(metrics, filePath, format) { const output = await this.export(metrics, format); await fs.writeFile(filePath, output, 'utf-8'); } async createStream(format) { return new MetricsStream(this, format); } average(values) { return values.reduce((a, b) => a + b, 0) / values.length; } } exports.MonitorExport = MonitorExport; class MetricsStream { constructor(exporter, format) { this.buffer = []; this.bytesWritten = 0; this.exporter = exporter; this.format = format; } async write(metrics) { const output = await this.exporter.export(metrics, this.format); this.buffer.push(output); this.bytesWritten += Buffer.byteLength(output, 'utf-8'); } async end() { // Finalize stream this.buffer = []; } getBuffer() { return [...this.buffer]; } } exports.MetricsStream = MetricsStream; //# sourceMappingURL=export.js.map