- Proper modular structure: src/commands/ + src/lib/ - Autocomplete for /logs and /restart (live container names) - All metrics queries run in parallel (Promise.all) - Multi-stage Docker build (builder + production) - TypeScript type check as CI job before docker build Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
19 lines
695 B
TypeScript
19 lines
695 B
TypeScript
const BASE = process.env.PROMETHEUS_URL ?? 'http://prometheus:9090';
|
|
|
|
interface PromResponse {
|
|
status: string;
|
|
data: { result: Array<{ value: [number, string] }> };
|
|
}
|
|
|
|
/** Run an instant query and return the scalar value, or null on error. */
|
|
export async function scalar(q: string): Promise<number | null> {
|
|
try {
|
|
const url = `${BASE}/api/v1/query?query=${encodeURIComponent(q)}`;
|
|
const res = await fetch(url, { signal: AbortSignal.timeout(6_000) });
|
|
const json = await res.json() as PromResponse;
|
|
if (json.status === 'success' && json.data.result.length > 0) {
|
|
return parseFloat(json.data.result[0].value[1]);
|
|
}
|
|
} catch { /* unreachable */ }
|
|
return null;
|
|
}
|