@openclaw/diagnostics-prometheus 2026.9.5 → 2026.9.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +93 -69
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -4,72 +4,7 @@ import { isDiagnosticsEnabled, normalizeDiagnosticLane, normalizeDiagnosticValue
4
4
  import { asNonNegativeFiniteNumber } from "openclaw/plugin-sdk/number-runtime";
5
5
  import { getPluginRuntimeGatewayRequestScope } from "openclaw/plugin-sdk/plugin-runtime";
6
6
  import { truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime";
7
- //#region extensions/diagnostics-prometheus/src/service.ts
8
- const DURATION_BUCKETS_SECONDS = [
9
- .005,
10
- .01,
11
- .025,
12
- .05,
13
- .1,
14
- .25,
15
- .5,
16
- 1,
17
- 2.5,
18
- 5,
19
- 10,
20
- 30,
21
- 60,
22
- 120,
23
- 300,
24
- 600
25
- ];
26
- const TOKEN_BUCKETS = [
27
- 1,
28
- 4,
29
- 16,
30
- 64,
31
- 256,
32
- 1024,
33
- 4096,
34
- 16384,
35
- 65536,
36
- 262144,
37
- 1048576
38
- ];
39
- const BYTE_BUCKETS = [
40
- 1024,
41
- 4096,
42
- 16384,
43
- 65536,
44
- 262144,
45
- 1048576,
46
- 4194304,
47
- 16777216,
48
- 67108864,
49
- 268435456,
50
- 1073741824,
51
- 4294967296,
52
- 17179869184
53
- ];
54
- const RATIO_BUCKETS = [
55
- .01,
56
- .05,
57
- .1,
58
- .25,
59
- .5,
60
- .75,
61
- 1,
62
- 2,
63
- 4,
64
- 8,
65
- 16
66
- ];
67
- const MAX_PROMETHEUS_SERIES = 2048;
68
- const DROPPED_SERIES_COUNTER_NAME = "openclaw_prometheus_series_dropped_total";
69
- function seconds(ms) {
70
- const value = asNonNegativeFiniteNumber(ms);
71
- return value === void 0 ? void 0 : value / 1e3;
72
- }
7
+ //#region extensions/diagnostics-prometheus/src/prometheus-format.ts
73
8
  function sortedLabels(labels) {
74
9
  const entries = Object.entries(labels);
75
10
  entries.sort(([left], [right]) => left.localeCompare(right));
@@ -96,6 +31,28 @@ function formatPrometheusNumber(value) {
96
31
  if (!Number.isFinite(value)) return "0";
97
32
  return Number.isInteger(value) ? String(value) : String(Number(value.toPrecision(12)));
98
33
  }
34
+ //#endregion
35
+ //#region extensions/diagnostics-prometheus/src/prometheus-metric-store.ts
36
+ const DURATION_BUCKETS_SECONDS = [
37
+ .005,
38
+ .01,
39
+ .025,
40
+ .05,
41
+ .1,
42
+ .25,
43
+ .5,
44
+ 1,
45
+ 2.5,
46
+ 5,
47
+ 10,
48
+ 30,
49
+ 60,
50
+ 120,
51
+ 300,
52
+ 600
53
+ ];
54
+ const MAX_PROMETHEUS_SERIES = 2048;
55
+ const DROPPED_SERIES_COUNTER_NAME = "openclaw_prometheus_series_dropped_total";
99
56
  function createPrometheusMetricStore() {
100
57
  const counters = /* @__PURE__ */ new Map();
101
58
  const gauges = /* @__PURE__ */ new Map();
@@ -132,6 +89,9 @@ function createPrometheusMetricStore() {
132
89
  value
133
90
  });
134
91
  };
92
+ const clearGauges = (name) => {
93
+ for (const key of gauges.keys()) if (key.startsWith(`${name}|`)) gauges.delete(key);
94
+ };
135
95
  const histogram = (name, help, labels, value, buckets = DURATION_BUCKETS_SECONDS) => {
136
96
  if (value === void 0 || !Number.isFinite(value) || value < 0) return;
137
97
  const key = metricKey(name, labels);
@@ -177,11 +137,59 @@ function createPrometheusMetricStore() {
177
137
  return {
178
138
  counter,
179
139
  gauge,
140
+ clearGauges,
180
141
  histogram,
181
142
  reset,
182
143
  snapshot
183
144
  };
184
145
  }
146
+ //#endregion
147
+ //#region extensions/diagnostics-prometheus/src/service.ts
148
+ const TOKEN_BUCKETS = [
149
+ 1,
150
+ 4,
151
+ 16,
152
+ 64,
153
+ 256,
154
+ 1024,
155
+ 4096,
156
+ 16384,
157
+ 65536,
158
+ 262144,
159
+ 1048576
160
+ ];
161
+ const BYTE_BUCKETS = [
162
+ 1024,
163
+ 4096,
164
+ 16384,
165
+ 65536,
166
+ 262144,
167
+ 1048576,
168
+ 4194304,
169
+ 16777216,
170
+ 67108864,
171
+ 268435456,
172
+ 1073741824,
173
+ 4294967296,
174
+ 17179869184
175
+ ];
176
+ const RATIO_BUCKETS = [
177
+ .01,
178
+ .05,
179
+ .1,
180
+ .25,
181
+ .5,
182
+ .75,
183
+ 1,
184
+ 2,
185
+ 4,
186
+ 8,
187
+ 16
188
+ ];
189
+ function seconds(ms) {
190
+ const value = asNonNegativeFiniteNumber(ms);
191
+ return value === void 0 ? void 0 : value / 1e3;
192
+ }
185
193
  function safeErrorMessage(err) {
186
194
  const message = err instanceof Error ? err.message ?? err.name : String(err);
187
195
  return truncateUtf16Safe(redactSensitiveText(message).replaceAll("\0", " ").replace(/[\r\n\t\u2028\u2029]/gu, " "), 500);
@@ -525,14 +533,30 @@ function recordDiagnosticEvent(store, evt, metadata) {
525
533
  trigger: evt.trigger
526
534
  });
527
535
  return;
528
- case "diagnostic.memory.sample":
536
+ case "diagnostic.child_process.spawn":
537
+ store.counter("openclaw_child_process_spawn_total", "Successful child launches through the shared spawn and exec owners.", { family: normalizeDiagnosticValue(evt.family) }, asNonNegativeFiniteNumber(evt.count) ?? 0);
538
+ return;
539
+ case "diagnostic.memory.sample": {
529
540
  for (const [kind, field] of [
530
541
  ["rss", "rssBytes"],
531
542
  ["heap_total", "heapTotalBytes"],
532
- ["heap_used", "heapUsedBytes"]
533
- ]) store.gauge("openclaw_memory_bytes", "Latest process memory usage by memory kind.", { kind }, evt.memory[field]);
543
+ ["heap_used", "heapUsedBytes"],
544
+ ["external", "externalBytes"],
545
+ ["array_buffers", "arrayBuffersBytes"],
546
+ ["worker_heap_total", "workerHeapTotalBytes"],
547
+ ["worker_heap_used", "workerHeapUsedBytes"]
548
+ ]) store.gauge("openclaw_memory_bytes", "Latest process memory usage by memory kind.", { kind }, asNonNegativeFiniteNumber(evt.memory[field]));
549
+ for (const [name, field] of [["openclaw_worker_count", "workerCount"], ["openclaw_worker_heap_sampled_count", "workerHeapSampledCount"]]) store.gauge(name, "Worker isolate counts.", {}, asNonNegativeFiniteNumber(evt.memory[field]));
550
+ const workerHeaps = /* @__PURE__ */ new Map();
551
+ for (const worker of evt.memory.workerHeaps ?? []) {
552
+ const heapUsed = asNonNegativeFiniteNumber(worker.heapUsed);
553
+ if (heapUsed !== void 0) workerHeaps.set(worker.script, (workerHeaps.get(worker.script) ?? 0) + heapUsed);
554
+ }
555
+ store.clearGauges("openclaw_worker_heap_used_bytes");
556
+ for (const [script, heapUsed] of workerHeaps) store.gauge("openclaw_worker_heap_used_bytes", "Latest live Worker heap usage by bounded script basename.", { script }, heapUsed);
534
557
  store.histogram("openclaw_memory_rss_bytes", "RSS memory sample distribution in bytes.", {}, asNonNegativeFiniteNumber(evt.memory.rssBytes), BYTE_BUCKETS);
535
558
  return;
559
+ }
536
560
  case "diagnostic.memory.pressure":
537
561
  store.counter("openclaw_memory_pressure_total", "Memory pressure events by level and reason.", {
538
562
  level: evt.level,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openclaw/diagnostics-prometheus",
3
- "version": "2026.9.5",
3
+ "version": "2026.9.6",
4
4
  "description": "OpenClaw diagnostics Prometheus exporter for runtime metrics.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -18,10 +18,10 @@
18
18
  "minHostVersion": ">=2026.4.25"
19
19
  },
20
20
  "compat": {
21
- "pluginApi": ">=2026.9.5"
21
+ "pluginApi": ">=2026.9.6"
22
22
  },
23
23
  "build": {
24
- "openclawVersion": "2026.9.5"
24
+ "openclawVersion": "2026.9.6"
25
25
  },
26
26
  "release": {
27
27
  "publishToClawHub": true,
@@ -39,7 +39,7 @@
39
39
  "assets/activity.svg"
40
40
  ],
41
41
  "peerDependencies": {
42
- "openclaw": ">=2026.9.5"
42
+ "openclaw": ">=2026.9.6"
43
43
  },
44
44
  "peerDependenciesMeta": {
45
45
  "openclaw": {