forked from mtusi2026/mtusi2026lab7
84 lines
2.6 KiB
TypeScript
84 lines
2.6 KiB
TypeScript
import { writeFile } from "node:fs/promises";
|
|
import { resolve } from "node:path";
|
|
import { root } from "./runtime";
|
|
const metrics = [
|
|
["Requests / second", "sum(rate(http_requests[1m]))"],
|
|
[
|
|
"HTTP p50 seconds",
|
|
"histogram_quantile(0.50,sum by (le)(rate(http_duration_bucket[1m])))",
|
|
],
|
|
[
|
|
"HTTP p99 seconds",
|
|
"histogram_quantile(0.99,sum by (le)(rate(http_duration_bucket[1m])))",
|
|
],
|
|
[
|
|
"HTTP server error ratio",
|
|
'(sum(rate(http_requests{status_class="5xx"}[1m])) or vector(0)) / clamp_min(sum(rate(http_requests[1m])),0.001)',
|
|
],
|
|
[
|
|
"HTTP p95 seconds",
|
|
"histogram_quantile(0.95,sum by (le)(rate(http_duration_bucket[1m])))",
|
|
],
|
|
["Jobs by outcome", "sum by (outcome)(rate(jobs_processed[1m]))"],
|
|
[
|
|
"Job duration p95 seconds",
|
|
"histogram_quantile(0.95,sum by(le)(rate(job_duration_bucket[1m])))",
|
|
],
|
|
[
|
|
"Time to ready p95 seconds",
|
|
"histogram_quantile(0.95,sum by(le)(rate(time_to_ready_bucket[1m])))",
|
|
],
|
|
["Oldest unfinished job seconds", "max(queue_oldest_age_seconds)"],
|
|
["Unfinished jobs", "max(queue_depth)"],
|
|
["Worker busy", "sum(worker_busy)"],
|
|
[
|
|
"Worker capacity",
|
|
"sum((worker_capacity and (timestamp(worker_capacity) > time()-10)))",
|
|
],
|
|
[
|
|
"Database observer up",
|
|
"min((database_observer_up and (timestamp(database_observer_up) > time()-10)))",
|
|
],
|
|
["Database pool used", "sum(db_pool_used)"],
|
|
["Database pending acquires", "sum(db_pool_pending_acquires)"],
|
|
[
|
|
"Database pool capacity",
|
|
"sum((db_pool_capacity and (timestamp(db_pool_capacity)>time()-10)))",
|
|
],
|
|
[
|
|
"Ready within 10 seconds",
|
|
"max(ready_slo_timely_10s) / clamp_min(max(ready_slo_matured_10s),1)",
|
|
],
|
|
[
|
|
"Ready within 30 seconds",
|
|
"max(ready_slo_timely_30s) / clamp_min(max(ready_slo_matured_30s),1)",
|
|
],
|
|
[
|
|
"Ready within 300 seconds",
|
|
"max(ready_slo_timely_300s) / clamp_min(max(ready_slo_matured_300s),1)",
|
|
],
|
|
];
|
|
const dashboard = {
|
|
uid: "messenger-security",
|
|
title: "Messenger lab7 security and pipeline",
|
|
schemaVersion: 39,
|
|
version: 1,
|
|
editable: false,
|
|
time: { from: "now-15m", to: "now" },
|
|
refresh: "5s",
|
|
panels: metrics.map(([title, expr], i) => ({
|
|
id: i + 1,
|
|
title,
|
|
type: "timeseries",
|
|
datasource: { type: "prometheus", uid: "prometheus" },
|
|
gridPos: { x: (i % 2) * 12, y: Math.floor(i / 2) * 8, w: 12, h: 8 },
|
|
targets: [{ refId: "A", expr }],
|
|
fieldConfig: { defaults: {}, overrides: [] },
|
|
options: { legend: { displayMode: "list", placement: "bottom" } },
|
|
})),
|
|
};
|
|
await writeFile(
|
|
resolve(root, "infra/grafana/dashboards/messenger.json"),
|
|
JSON.stringify(dashboard, null, 2) + "\n",
|
|
);
|