@peers-app/peers-ui 0.34.9 → 0.34.10

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 (77) hide show
  1. package/dist/apps-home/apps-home.js +6 -4
  2. package/dist/components/router.d.ts +1 -1
  3. package/dist/components/router.js +1 -1
  4. package/dist/screens/identity/identity-routes.d.ts +2 -1
  5. package/dist/screens/identity/identity-routes.js +6 -1
  6. package/dist/screens/monitoring/alerts-tab.d.ts +13 -0
  7. package/dist/screens/monitoring/alerts-tab.js +68 -0
  8. package/dist/screens/monitoring/badges.d.ts +25 -0
  9. package/dist/screens/monitoring/badges.js +68 -0
  10. package/dist/screens/monitoring/calls-tab.d.ts +30 -0
  11. package/dist/screens/monitoring/calls-tab.js +104 -0
  12. package/dist/screens/monitoring/charts/chart-math.d.ts +103 -0
  13. package/dist/screens/monitoring/charts/chart-math.js +200 -0
  14. package/dist/screens/monitoring/charts/histogram-chart.d.ts +25 -0
  15. package/dist/screens/monitoring/charts/histogram-chart.js +74 -0
  16. package/dist/screens/monitoring/charts/line-chart.d.ts +33 -0
  17. package/dist/screens/monitoring/charts/line-chart.js +103 -0
  18. package/dist/screens/monitoring/charts/sparkline.d.ts +30 -0
  19. package/dist/screens/monitoring/charts/sparkline.js +61 -0
  20. package/dist/screens/monitoring/charts/use-width.d.ts +9 -0
  21. package/dist/screens/monitoring/charts/use-width.js +31 -0
  22. package/dist/screens/monitoring/definition-forms.d.ts +113 -0
  23. package/dist/screens/monitoring/definition-forms.js +341 -0
  24. package/dist/screens/monitoring/definitions-tab.d.ts +20 -0
  25. package/dist/screens/monitoring/definitions-tab.js +110 -0
  26. package/dist/screens/monitoring/device-picker.d.ts +22 -0
  27. package/dist/screens/monitoring/device-picker.js +29 -0
  28. package/dist/screens/monitoring/form-fields.d.ts +76 -0
  29. package/dist/screens/monitoring/form-fields.js +65 -0
  30. package/dist/screens/monitoring/format.d.ts +51 -0
  31. package/dist/screens/monitoring/format.js +150 -0
  32. package/dist/screens/monitoring/log-lines.d.ts +74 -0
  33. package/dist/screens/monitoring/log-lines.js +138 -0
  34. package/dist/screens/monitoring/log-row.d.ts +12 -0
  35. package/dist/screens/monitoring/log-row.js +23 -0
  36. package/dist/screens/monitoring/logs-tab.d.ts +15 -0
  37. package/dist/screens/monitoring/logs-tab.js +256 -0
  38. package/dist/screens/monitoring/metric-definition-form.d.ts +15 -0
  39. package/dist/screens/monitoring/metric-definition-form.js +50 -0
  40. package/dist/screens/monitoring/metrics-tab.d.ts +37 -0
  41. package/dist/screens/monitoring/metrics-tab.js +149 -0
  42. package/dist/screens/monitoring/monitoring-routes.d.ts +40 -0
  43. package/dist/screens/monitoring/monitoring-routes.js +81 -0
  44. package/dist/screens/monitoring/monitoring-screen.d.ts +17 -0
  45. package/dist/screens/monitoring/monitoring-screen.js +63 -0
  46. package/dist/screens/monitoring/overview-tab.d.ts +33 -0
  47. package/dist/screens/monitoring/overview-tab.js +121 -0
  48. package/dist/screens/monitoring/telemetry-client.d.ts +48 -0
  49. package/dist/screens/monitoring/telemetry-client.js +92 -0
  50. package/dist/screens/monitoring/trigger-form.d.ts +18 -0
  51. package/dist/screens/monitoring/trigger-form.js +71 -0
  52. package/dist/screens/monitoring/use-telemetry.d.ts +39 -0
  53. package/dist/screens/monitoring/use-telemetry.js +120 -0
  54. package/dist/screens/network-viewer/remote-logs-panel.d.ts +1 -1
  55. package/dist/screens/network-viewer/remote-logs-panel.js +5 -3
  56. package/dist/system-apps/index.d.ts +1 -1
  57. package/dist/system-apps/index.js +5 -5
  58. package/dist/system-apps/monitoring.app.d.ts +6 -0
  59. package/dist/system-apps/monitoring.app.js +13 -0
  60. package/dist/tabs-layout/tabs-state.d.ts +4 -2
  61. package/dist/tabs-layout/tabs-state.js +23 -11
  62. package/dist/theme.css +32 -0
  63. package/package.json +3 -3
  64. package/dist/screens/console-logs/console-logs-list.d.ts +0 -2
  65. package/dist/screens/console-logs/console-logs-list.js +0 -284
  66. package/dist/screens/console-logs/follow-newest.d.ts +0 -11
  67. package/dist/screens/console-logs/follow-newest.js +0 -17
  68. package/dist/screens/console-logs/log-display.d.ts +0 -12
  69. package/dist/screens/console-logs/log-display.js +0 -69
  70. package/dist/screens/console-logs/log-filters.d.ts +0 -10
  71. package/dist/screens/console-logs/log-filters.js +0 -8
  72. package/dist/screens/console-logs/mobile-log-card.d.ts +0 -8
  73. package/dist/screens/console-logs/mobile-log-card.js +0 -94
  74. package/dist/screens/console-logs/resizable-table-header.d.ts +0 -14
  75. package/dist/screens/console-logs/resizable-table-header.js +0 -62
  76. package/dist/system-apps/console-logs.app.d.ts +0 -2
  77. package/dist/system-apps/console-logs.app.js +0 -8
@@ -0,0 +1,256 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FOLLOW_MS = void 0;
4
+ exports.LogsTab = LogsTab;
5
+ const jsx_runtime_1 = require("react/jsx-runtime");
6
+ const peers_sdk_1 = require("@peers-app/peers-sdk");
7
+ const react_1 = require("react");
8
+ const badges_1 = require("./badges");
9
+ const form_fields_1 = require("./form-fields");
10
+ const format_1 = require("./format");
11
+ const log_lines_1 = require("./log-lines");
12
+ const log_row_1 = require("./log-row");
13
+ const telemetry_client_1 = require("./telemetry-client");
14
+ /** How often the section asks for new lines while following: this device, and another. */
15
+ exports.FOLLOW_MS = { local: 2_000, remote: 5_000 };
16
+ const EMPTY = { lines: [], hasOlder: false };
17
+ /** How close to the bottom, in pixels, still counts as reading the newest lines. */
18
+ const AT_NEWEST_PX = 40;
19
+ /**
20
+ * Logs: a device's stored lines, oldest at the top and newest at the bottom. It follows new lines
21
+ * (by cursor) until paused, keeps the reader's place while they scroll back, and filters by level
22
+ * (several at once), words, source, package, group, process, event and trace. Paging back pauses
23
+ * following and keeps the cap by letting the newest lines go; Follow then starts again from the
24
+ * newest. If the opening read fails, following tries it again each tick. Clearing deletes this
25
+ * device's lines only.
26
+ */
27
+ function LogsTab(props) {
28
+ const { deviceId, traceId } = props.location;
29
+ const [filters, setFilters] = (0, react_1.useState)(() => (0, log_lines_1.emptyLogFilters)(traceId));
30
+ const [searchDraft, setSearchDraft] = (0, react_1.useState)("");
31
+ const [showFilters, setShowFilters] = (0, react_1.useState)(!!traceId);
32
+ const [following, setFollowing] = (0, react_1.useState)(true);
33
+ /** Following is paused because older lines were loaded. */
34
+ const [readingOlder, setReadingOlder] = (0, react_1.useState)(false);
35
+ /** Bumped to read the newest page again. */
36
+ const [reload, setReload] = (0, react_1.useState)(0);
37
+ const [loaded, setLoaded] = (0, react_1.useState)(EMPTY);
38
+ const [ready, setReady] = (0, react_1.useState)(false);
39
+ const [loadingOlder, setLoadingOlder] = (0, react_1.useState)(false);
40
+ const [error, setError] = (0, react_1.useState)();
41
+ const generation = (0, react_1.useRef)(0);
42
+ const loadedRef = (0, react_1.useRef)(loaded);
43
+ const scrollRef = (0, react_1.useRef)(null);
44
+ const atNewest = (0, react_1.useRef)(true);
45
+ const pending = (0, react_1.useRef)(null);
46
+ // The route's trace is the trace filter.
47
+ (0, react_1.useEffect)(() => {
48
+ setFilters((prev) => prev.traceId === (traceId ?? "") ? prev : { ...prev, traceId: traceId ?? "" });
49
+ if (traceId)
50
+ setShowFilters(true);
51
+ }, [traceId]);
52
+ // Search as the person stops typing.
53
+ (0, react_1.useEffect)(() => {
54
+ const timer = setTimeout(() => setFilters((prev) => prev.search === searchDraft ? prev : { ...prev, search: searchDraft }), 300);
55
+ return () => clearTimeout(timer);
56
+ }, [searchDraft]);
57
+ const apply = (kind, next) => {
58
+ const element = scrollRef.current;
59
+ const oldest = loadedRef.current.lines[0]?.logId;
60
+ const row = kind === "older" ? element?.querySelector(`[data-log-id="${oldest}"]`) : null;
61
+ pending.current = {
62
+ kind,
63
+ height: element?.scrollHeight ?? 0,
64
+ anchor: element && row && oldest !== undefined
65
+ ? { logId: oldest, top: topWithin(row, element) }
66
+ : undefined,
67
+ };
68
+ loadedRef.current = next;
69
+ setLoaded(next);
70
+ };
71
+ /** Read the newest page and start the view over from it. */
72
+ const readNewest = async (id) => {
73
+ const telemetry = await (0, telemetry_client_1.getTelemetry)(deviceId);
74
+ if (id !== generation.current)
75
+ return;
76
+ const page = await telemetry.tools.readLogs({
77
+ ...(0, log_lines_1.toReadLogsInput)(filters),
78
+ limit: log_lines_1.LOG_PAGE_SIZE,
79
+ });
80
+ if (id !== generation.current)
81
+ return;
82
+ setError(undefined);
83
+ apply("reset", (0, log_lines_1.addOlder)(EMPTY, page.lines, page.hasMore));
84
+ setReady(true);
85
+ };
86
+ // A new device or filter, or Follow after paging back, starts over from the newest lines.
87
+ (0, react_1.useEffect)(() => {
88
+ const id = ++generation.current;
89
+ setReady(false);
90
+ setError(undefined);
91
+ apply("reset", EMPTY);
92
+ if (readingOlder) {
93
+ setReadingOlder(false);
94
+ setFollowing(true);
95
+ }
96
+ readNewest(id).catch((cause) => {
97
+ if (id === generation.current)
98
+ setError(cause);
99
+ });
100
+ return () => {
101
+ generation.current++;
102
+ };
103
+ }, [deviceId, filters, reload]);
104
+ // Until the opening read succeeds, following tries it again each tick (a phone asleep at open).
105
+ const openFailed = !ready && error !== undefined;
106
+ // Follow one page per tick. A delayed transport may become ready after Pause or navigation.
107
+ (0, react_1.useEffect)(() => {
108
+ if (!following || (!ready && !openFailed))
109
+ return;
110
+ let running = false;
111
+ const tick = async () => {
112
+ const id = generation.current;
113
+ try {
114
+ if (!ready) {
115
+ await readNewest(id);
116
+ return;
117
+ }
118
+ const telemetry = await (0, telemetry_client_1.getTelemetry)(deviceId);
119
+ if (!running ||
120
+ id !== generation.current ||
121
+ (typeof document !== "undefined" && document.hidden))
122
+ return;
123
+ const page = await telemetry.tools.readLogs({
124
+ ...(0, log_lines_1.toReadLogsInput)(filters),
125
+ after: (0, log_lines_1.newestLogId)(loadedRef.current) ?? 0,
126
+ limit: 500,
127
+ });
128
+ if (!running || id !== generation.current)
129
+ return;
130
+ setError(undefined);
131
+ if (page.lines.length)
132
+ apply("newer", (0, log_lines_1.addNewer)(loadedRef.current, page.lines));
133
+ }
134
+ catch (cause) {
135
+ if (running && id === generation.current)
136
+ setError(cause);
137
+ }
138
+ finally {
139
+ running = false;
140
+ }
141
+ };
142
+ const timer = setInterval(() => {
143
+ if (running || (typeof document !== "undefined" && document.hidden))
144
+ return;
145
+ running = true;
146
+ void tick();
147
+ }, (0, telemetry_client_1.isThisDevice)(deviceId) ? exports.FOLLOW_MS.local : exports.FOLLOW_MS.remote);
148
+ return () => {
149
+ clearInterval(timer);
150
+ running = false;
151
+ };
152
+ }, [following, ready, openFailed, deviceId, filters]);
153
+ // Keep the reader's place: at the newest end it stays there; loading older lines doesn't jump.
154
+ (0, react_1.useLayoutEffect)(() => {
155
+ const element = scrollRef.current;
156
+ const change = pending.current;
157
+ pending.current = null;
158
+ if (!element || !change)
159
+ return;
160
+ if (change.kind === "older") {
161
+ // Keep the line that was oldest where it was; newest lines may have gone from the bottom.
162
+ const row = change.anchor
163
+ ? element.querySelector(`[data-log-id="${change.anchor.logId}"]`)
164
+ : null;
165
+ element.scrollTop +=
166
+ row && change.anchor
167
+ ? topWithin(row, element) - change.anchor.top
168
+ : element.scrollHeight - change.height;
169
+ }
170
+ else if (change.kind === "reset" || atNewest.current) {
171
+ element.scrollTop = element.scrollHeight;
172
+ }
173
+ }, [loaded]);
174
+ const loadOlder = async () => {
175
+ const oldest = loaded.lines[0]?.logId;
176
+ if (oldest === undefined)
177
+ return;
178
+ const id = generation.current;
179
+ // Following would let the older lines go again; it waits until the reader asks for it.
180
+ setFollowing(false);
181
+ setReadingOlder(true);
182
+ setLoadingOlder(true);
183
+ try {
184
+ const telemetry = await (0, telemetry_client_1.getTelemetry)(deviceId);
185
+ if (id !== generation.current)
186
+ return;
187
+ const page = await telemetry.tools.readLogs({
188
+ ...(0, log_lines_1.toReadLogsInput)(filters),
189
+ before: oldest,
190
+ limit: log_lines_1.LOG_PAGE_SIZE,
191
+ });
192
+ if (id === generation.current) {
193
+ setError(undefined);
194
+ apply("older", (0, log_lines_1.addOlder)(loadedRef.current, page.lines, page.hasMore));
195
+ }
196
+ }
197
+ catch (cause) {
198
+ if (id === generation.current)
199
+ setError(cause);
200
+ }
201
+ finally {
202
+ setLoadingOlder(false);
203
+ }
204
+ };
205
+ const clear = async () => {
206
+ if (!confirm("Delete every log line stored on this device? Metrics stay."))
207
+ return;
208
+ try {
209
+ await (await (0, telemetry_client_1.getTelemetry)()).tools.clearLogs({});
210
+ generation.current++;
211
+ setReady(true);
212
+ setError(undefined);
213
+ apply("reset", EMPTY);
214
+ if (readingOlder) {
215
+ setReadingOlder(false);
216
+ setFollowing(true);
217
+ }
218
+ }
219
+ catch (cause) {
220
+ alert(`Couldn't clear the logs: ${(0, telemetry_client_1.errorText)(cause)}`);
221
+ }
222
+ };
223
+ const setField = (key) => (value) => setFilters((prev) => ({ ...prev, [key]: value }));
224
+ const toggleLevel = (level) => setFilters((prev) => ({
225
+ ...prev,
226
+ levels: prev.levels.includes(level)
227
+ ? prev.levels.filter((l) => l !== level)
228
+ : [...prev.levels, level],
229
+ }));
230
+ const setTrace = (id) => props.navigate({ section: "logs", traceId: id || undefined });
231
+ const follow = () => {
232
+ // Back from older lines, or after a failed opening read: read the newest page now.
233
+ if (readingOlder || openFailed)
234
+ setReload((n) => n + 1);
235
+ setReadingOlder(false);
236
+ setFollowing(true);
237
+ };
238
+ const fieldCount = (0, log_lines_1.countFieldFilters)(filters);
239
+ return ((0, jsx_runtime_1.jsxs)("div", { className: "d-flex flex-column", style: { height: "max(360px, calc(100dvh - 210px))" }, children: [(0, jsx_runtime_1.jsxs)("div", { className: "d-flex flex-wrap align-items-center gap-2 mb-2", children: [(0, jsx_runtime_1.jsx)("fieldset", { className: "btn-group btn-group-sm", "aria-label": "Levels", children: peers_sdk_1.LOG_LEVELS.map((level) => ((0, jsx_runtime_1.jsx)("button", { type: "button", className: `btn ${filters.levels.includes(level) ? "btn-secondary" : "btn-outline-secondary"}`, "aria-pressed": filters.levels.includes(level), onClick: () => toggleLevel(level), children: level }, level))) }), (0, jsx_runtime_1.jsx)("input", { type: "search", className: "form-control form-control-sm", style: { maxWidth: 260 }, placeholder: "Search the text", "aria-label": "Search the text", value: searchDraft, onChange: (event) => setSearchDraft(event.target.value) }), (0, jsx_runtime_1.jsxs)("button", { type: "button", className: `btn btn-sm ${showFilters ? "btn-secondary" : "btn-outline-secondary"}`, "aria-expanded": showFilters, onClick: () => setShowFilters((value) => !value), children: [(0, jsx_runtime_1.jsx)("i", { className: "bi bi-funnel me-1", "aria-hidden": "true" }), "Filters", fieldCount ? ` (${fieldCount})` : ""] }), (0, jsx_runtime_1.jsxs)("button", { type: "button", className: `btn btn-sm ms-auto ${following ? "btn-outline-primary" : "btn-primary"}`, "aria-pressed": !following, onClick: () => (following ? setFollowing(false) : follow()), children: [(0, jsx_runtime_1.jsx)("i", { className: `bi ${following ? "bi-pause-fill" : "bi-play-fill"} me-1`, "aria-hidden": "true" }), following ? "Pause" : "Follow"] })] }), showFilters ? ((0, jsx_runtime_1.jsxs)("div", { className: "row g-2 mb-2", children: [(0, jsx_runtime_1.jsx)(form_fields_1.FilterInput, { id: "log-sources", label: "Source", value: filters.sources, onChange: setField("sources"), placeholder: "Mesh, Sync" }), (0, jsx_runtime_1.jsx)(form_fields_1.FilterInput, { id: "log-packages", label: "Package id", value: filters.packageIds, onChange: setField("packageIds") }), (0, jsx_runtime_1.jsx)(form_fields_1.FilterInput, { id: "log-groups", label: "Group id", value: filters.groupIds, onChange: setField("groupIds") }), (0, jsx_runtime_1.jsx)(form_fields_1.FilterInput, { id: "log-processes", label: "Process", value: filters.processes, onChange: setField("processes"), placeholder: "electron, ui, worker" }), (0, jsx_runtime_1.jsx)(form_fields_1.FilterInput, { id: "log-events", label: "Event", value: filters.events, onChange: setField("events"), placeholder: "sync.finished" }), (0, jsx_runtime_1.jsx)(form_fields_1.FilterInput, { id: "log-trace", label: "Trace", value: filters.traceId, onChange: (value) => setTrace(value.trim()) })] })) : null, filters.traceId ? ((0, jsx_runtime_1.jsxs)("div", { className: "small mb-2 d-flex align-items-center gap-2", children: [(0, jsx_runtime_1.jsx)("span", { className: "text-body-secondary", children: "Lines in trace" }), (0, jsx_runtime_1.jsx)("code", { children: filters.traceId }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-link btn-sm p-0", onClick: () => props.navigate({ section: "calls", traceId: filters.traceId }), children: "Its calls" }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-link btn-sm p-0", onClick: () => setTrace(""), children: "Clear" })] })) : null, error ? ((0, jsx_runtime_1.jsx)("div", { className: "alert alert-warning small py-2 mb-2", children: (0, telemetry_client_1.describeTelemetryError)(error) })) : null, (0, jsx_runtime_1.jsxs)("div", { ref: scrollRef, className: "flex-grow-1 overflow-auto border rounded bg-body", style: { minHeight: 0 }, onScroll: (event) => {
240
+ const element = event.currentTarget;
241
+ atNewest.current =
242
+ element.scrollHeight - element.scrollTop - element.clientHeight <= AT_NEWEST_PX;
243
+ }, "data-testid": "log-lines", children: [loaded.hasOlder ? ((0, jsx_runtime_1.jsx)("div", { className: "text-center py-2", children: (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-link btn-sm", onClick: () => void loadOlder(), disabled: loadingOlder, children: loadingOlder ? "Loading…" : "Load older lines" }) })) : ready && !error && loaded.lines.length > 0 ? ((0, jsx_runtime_1.jsx)("div", { className: "text-center small text-body-secondary py-2", children: "The oldest stored line" })) : null, !ready && !error ? (0, jsx_runtime_1.jsx)("div", { className: "p-3 text-body-secondary", children: "Loading\u2026" }) : null, ready && !error && loaded.lines.length === 0 ? ((0, jsx_runtime_1.jsxs)("div", { className: "p-4 text-center text-body-secondary", children: [(0, jsx_runtime_1.jsx)("i", { className: "bi bi-inbox d-block fs-2 mb-1", "aria-hidden": "true" }), "No lines match."] })) : null, (0, jsx_runtime_1.jsx)("div", { style: {
244
+ visibility: error && !(0, telemetry_client_1.isThisDevice)(deviceId) && (0, telemetry_client_1.classifyTelemetryError)(error) === "unreachable"
245
+ ? "hidden"
246
+ : undefined,
247
+ }, children: loaded.lines.map((line) => ((0, jsx_runtime_1.jsx)(log_row_1.LogRow, { line: line, onTrace: setTrace }, line.logId))) }), loaded.hasNewer ? ((0, jsx_runtime_1.jsx)("div", { className: "text-center py-2", children: (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-link btn-sm", onClick: follow, children: "Back to the newest lines" }) })) : null] }), (0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center gap-2 pt-2 small text-body-secondary", children: [(0, jsx_runtime_1.jsxs)("span", { children: [(0, format_1.formatNumber)(loaded.lines.length), " line", loaded.lines.length === 1 ? "" : "s", " loaded \u00B7", " ", following
248
+ ? "following new lines"
249
+ : readingOlder
250
+ ? "paused while you read older lines"
251
+ : "paused"] }), filters.levels.length ? ((0, jsx_runtime_1.jsx)("span", { className: "d-flex gap-1", children: filters.levels.map((level) => ((0, jsx_runtime_1.jsx)(badges_1.LevelBadge, { level: level }, level))) })) : null, (0, telemetry_client_1.isThisDevice)(deviceId) ? ((0, jsx_runtime_1.jsxs)("button", { type: "button", className: "btn btn-outline-danger btn-sm ms-auto", onClick: () => void clear(), children: [(0, jsx_runtime_1.jsx)("i", { className: "bi bi-trash me-1", "aria-hidden": "true" }), "Clear"] })) : null] })] }));
252
+ }
253
+ /** How far down a scrolled view an element sits, in pixels. */
254
+ function topWithin(element, view) {
255
+ return element.getBoundingClientRect().top - view.getBoundingClientRect().top;
256
+ }
@@ -0,0 +1,15 @@
1
+ import { type IMetricDefinition } from "@peers-app/peers-sdk";
2
+ /** Props for {@link MetricDefinitionForm}. */
3
+ export interface MetricDefinitionFormProps {
4
+ /** The definition to edit; omit to create one. */
5
+ definition?: IMetricDefinition;
6
+ /** Called once it's saved, with its id. */
7
+ onSaved: (metricId: string) => void;
8
+ onCancel: () => void;
9
+ }
10
+ /**
11
+ * Create or edit one of the user's metric definitions: which log lines it selects and what it
12
+ * measures. It's saved on this device and syncs to the user's other devices, where each computes it
13
+ * from its own lines. A save the device refuses shows the reason as the device words it.
14
+ */
15
+ export declare function MetricDefinitionForm(props: MetricDefinitionFormProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MetricDefinitionForm = MetricDefinitionForm;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const peers_sdk_1 = require("@peers-app/peers-sdk");
6
+ const react_1 = require("react");
7
+ const definition_forms_1 = require("./definition-forms");
8
+ const form_fields_1 = require("./form-fields");
9
+ const telemetry_client_1 = require("./telemetry-client");
10
+ const KINDS = [
11
+ { value: "count", label: "Count: how many lines match (or the sum of a value)" },
12
+ { value: "distribution", label: "Distribution: a value's percentiles" },
13
+ { value: "gauge", label: "Gauge: a value's level" },
14
+ ];
15
+ /**
16
+ * Create or edit one of the user's metric definitions: which log lines it selects and what it
17
+ * measures. It's saved on this device and syncs to the user's other devices, where each computes it
18
+ * from its own lines. A save the device refuses shows the reason as the device words it.
19
+ */
20
+ function MetricDefinitionForm(props) {
21
+ const editing = !!props.definition;
22
+ const [form, setForm] = (0, react_1.useState)(() => props.definition ? (0, definition_forms_1.metricDefinitionToForm)(props.definition) : (0, definition_forms_1.emptyMetricForm)());
23
+ const [error, setError] = (0, react_1.useState)();
24
+ const [saving, setSaving] = (0, react_1.useState)(false);
25
+ const set = (key) => (value) => setForm((prev) => ({ ...prev, [key]: value }));
26
+ const save = async () => {
27
+ const built = (0, definition_forms_1.toMetricDefinition)(form);
28
+ if (built.error !== undefined) {
29
+ setError(built.error);
30
+ return;
31
+ }
32
+ setSaving(true);
33
+ setError(undefined);
34
+ try {
35
+ const telemetry = await (0, telemetry_client_1.getTelemetry)();
36
+ const result = await telemetry.tools.saveMetricDefinition({ definition: built.definition });
37
+ props.onSaved(result.metricId);
38
+ }
39
+ catch (cause) {
40
+ setError((0, telemetry_client_1.errorText)(cause));
41
+ }
42
+ finally {
43
+ setSaving(false);
44
+ }
45
+ };
46
+ return ((0, jsx_runtime_1.jsxs)("form", { className: "card card-body mb-3", "aria-label": editing ? `Edit metric ${form.metricId}` : "New metric", onSubmit: (event) => {
47
+ event.preventDefault();
48
+ void save();
49
+ }, children: [(0, jsx_runtime_1.jsx)("h2", { className: "h6", children: editing ? `Edit ${form.metricId}` : "New metric" }), (0, jsx_runtime_1.jsxs)("div", { className: "row g-2", children: [(0, jsx_runtime_1.jsx)("div", { className: "col-md-6", children: (0, jsx_runtime_1.jsx)(form_fields_1.TextField, { id: "metric-id", label: "Metric id", value: form.metricId, onChange: set("metricId"), disabled: editing, monospace: true, placeholder: "backup.duration", hint: "Dotted and lowercase." }) }), (0, jsx_runtime_1.jsx)("div", { className: "col-md-6", children: (0, jsx_runtime_1.jsx)(form_fields_1.TextField, { id: "metric-unit", label: "Unit", value: form.unit, onChange: set("unit"), placeholder: "ms, bytes, items" }) })] }), (0, jsx_runtime_1.jsx)(form_fields_1.TextField, { id: "metric-description", label: "Description", value: form.description, onChange: set("description") }), (0, jsx_runtime_1.jsx)(form_fields_1.SelectField, { id: "metric-kind", label: "Kind", value: form.kind, options: KINDS, onChange: set("kind") }), (0, jsx_runtime_1.jsx)("h3", { className: "h6 small text-body-secondary mt-2", children: "Lines it reads" }), (0, jsx_runtime_1.jsxs)("div", { className: "row g-2", children: [(0, jsx_runtime_1.jsx)("div", { className: "col-md-6", children: (0, jsx_runtime_1.jsx)(form_fields_1.TextField, { id: "metric-event", label: "Event", value: form.event, onChange: set("event"), monospace: true, placeholder: "sync.finished" }) }), (0, jsx_runtime_1.jsx)("div", { className: "col-md-6", children: (0, jsx_runtime_1.jsx)(form_fields_1.TextField, { id: "metric-source", label: "Source", value: form.source, onChange: set("source"), placeholder: "Mesh" }) }), (0, jsx_runtime_1.jsx)("div", { className: "col-md-6", children: (0, jsx_runtime_1.jsx)(form_fields_1.TextField, { id: "metric-package", label: "Package id", value: form.packageId, onChange: set("packageId"), monospace: true }) }), (0, jsx_runtime_1.jsx)("div", { className: "col-md-6", children: (0, jsx_runtime_1.jsx)(form_fields_1.TextField, { id: "metric-process", label: "Process", value: form.process, onChange: set("process"), placeholder: "electron, pwa, worker" }) })] }), (0, jsx_runtime_1.jsxs)("fieldset", { className: "mb-2", children: [(0, jsx_runtime_1.jsx)("legend", { className: "form-label small mb-1", children: "Levels" }), (0, jsx_runtime_1.jsx)("div", { className: "d-flex flex-wrap gap-3", children: peers_sdk_1.LOG_LEVELS.map((level) => ((0, jsx_runtime_1.jsx)(form_fields_1.CheckField, { id: `metric-level-${level}`, label: level, checked: form.levels.includes(level), onChange: (checked) => set("levels")(checked ? [...form.levels, level] : form.levels.filter((l) => l !== level)) }, level))) })] }), (0, jsx_runtime_1.jsx)(form_fields_1.TextAreaField, { id: "metric-where", label: "Where (every path equals its value)", value: form.where, onChange: set("where"), placeholder: "failure.stage = dial\nretry = true", hint: 'One "path = value" per line. Paths read the data logged with a line, or $level, $source, $packageId, $groupId, $process, $event.' }), (0, jsx_runtime_1.jsx)(form_fields_1.TextField, { id: "metric-has", label: "Has (every path is present)", value: form.has, onChange: set("has"), monospace: true, placeholder: "durationMs, groupId" }), (0, jsx_runtime_1.jsxs)("div", { className: "row g-2", children: [(0, jsx_runtime_1.jsx)("div", { className: "col-md-4", children: (0, jsx_runtime_1.jsx)(form_fields_1.TextField, { id: "metric-prefix", label: "Text starts with", value: form.messagePrefix, onChange: set("messagePrefix") }) }), (0, jsx_runtime_1.jsx)("div", { className: "col-md-4", children: (0, jsx_runtime_1.jsx)(form_fields_1.TextField, { id: "metric-contains", label: "Text contains", value: form.messageContains, onChange: set("messageContains") }) }), (0, jsx_runtime_1.jsx)("div", { className: "col-md-4", children: (0, jsx_runtime_1.jsx)(form_fields_1.TextField, { id: "metric-pattern", label: "Text pattern", value: form.messagePattern, onChange: set("messagePattern"), monospace: true, placeholder: "took (?<ms>\\d+)ms", hint: "A regular expression; its named groups are $match.<name> paths." }) })] }), (0, jsx_runtime_1.jsx)("h3", { className: "h6 small text-body-secondary mt-2", children: "What it measures" }), (0, jsx_runtime_1.jsxs)("div", { className: "row g-2", children: [(0, jsx_runtime_1.jsx)("div", { className: "col-md-6", children: (0, jsx_runtime_1.jsx)(form_fields_1.TextField, { id: "metric-value", label: "Value path", value: form.value, onChange: set("value"), monospace: true, placeholder: "durationMs", hint: "Needed for distributions and gauges; a count sums it when given." }) }), (0, jsx_runtime_1.jsx)("div", { className: "col-md-6", children: (0, jsx_runtime_1.jsx)(form_fields_1.TextField, { id: "metric-labels", label: "Split into series by", value: form.labels, onChange: set("labels"), monospace: true, placeholder: "$groupId, failure.reason", hint: "Up to four paths." }) })] }), (0, jsx_runtime_1.jsx)(form_fields_1.CheckField, { id: "metric-disabled", label: "Off (kept, but not computed)", checked: form.disabled, onChange: set("disabled") }), error ? ((0, jsx_runtime_1.jsx)("div", { className: "alert alert-danger small py-2", role: "alert", children: error })) : null, (0, jsx_runtime_1.jsxs)("div", { className: "d-flex gap-2", children: [(0, jsx_runtime_1.jsx)("button", { type: "submit", className: "btn btn-primary btn-sm", disabled: saving, children: saving ? "Saving…" : "Save" }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-outline-secondary btn-sm", onClick: props.onCancel, children: "Cancel" }), (0, jsx_runtime_1.jsx)("span", { className: "small text-body-secondary align-self-center ms-auto", children: "Syncs to your other devices." })] })] }));
50
+ }
@@ -0,0 +1,37 @@
1
+ import { type MetricKind, type MetricStat } from "@peers-app/peers-sdk";
2
+ import type { MonitoringSectionProps } from "./monitoring-screen";
3
+ /** The ranges the explorer offers, and their length. */
4
+ export declare const METRIC_RANGES: readonly [{
5
+ readonly id: "1h";
6
+ readonly label: "1 hour";
7
+ readonly ms: 3600000;
8
+ }, {
9
+ readonly id: "6h";
10
+ readonly label: "6 hours";
11
+ readonly ms: number;
12
+ }, {
13
+ readonly id: "24h";
14
+ readonly label: "24 hours";
15
+ readonly ms: number;
16
+ }, {
17
+ readonly id: "7d";
18
+ readonly label: "7 days";
19
+ readonly ms: number;
20
+ }, {
21
+ readonly id: "30d";
22
+ readonly label: "30 days";
23
+ readonly ms: number;
24
+ }];
25
+ /**
26
+ * The statistics that mean something for a kind of metric, the default first: a count's lines
27
+ * (or summed values), a distribution's percentiles, a gauge's level.
28
+ *
29
+ * @param kind - The metric's kind.
30
+ */
31
+ export declare function statsForKind(kind: MetricKind | undefined): MetricStat[];
32
+ /**
33
+ * Metrics: pick one of the device's metrics, a statistic, a label to split it by and a range, and
34
+ * see it over time as a chart or a table, with the range's histogram for a distribution.
35
+ * `calls.duration` leaves out Monitoring's own reads unless asked for, as the Overview does.
36
+ */
37
+ export declare function MetricsTab(props: MonitoringSectionProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.METRIC_RANGES = void 0;
4
+ exports.statsForKind = statsForKind;
5
+ exports.MetricsTab = MetricsTab;
6
+ const jsx_runtime_1 = require("react/jsx-runtime");
7
+ const peers_sdk_1 = require("@peers-app/peers-sdk");
8
+ const react_1 = require("react");
9
+ const badges_1 = require("./badges");
10
+ const chart_math_1 = require("./charts/chart-math");
11
+ const histogram_chart_1 = require("./charts/histogram-chart");
12
+ const line_chart_1 = require("./charts/line-chart");
13
+ const form_fields_1 = require("./form-fields");
14
+ const format_1 = require("./format");
15
+ const telemetry_client_1 = require("./telemetry-client");
16
+ const use_telemetry_1 = require("./use-telemetry");
17
+ /** The ranges the explorer offers, and their length. */
18
+ exports.METRIC_RANGES = [
19
+ { id: "1h", label: "1 hour", ms: 3_600_000 },
20
+ { id: "6h", label: "6 hours", ms: 6 * 3_600_000 },
21
+ { id: "24h", label: "24 hours", ms: 24 * 3_600_000 },
22
+ { id: "7d", label: "7 days", ms: 7 * 24 * 3_600_000 },
23
+ { id: "30d", label: "30 days", ms: 30 * 24 * 3_600_000 },
24
+ ];
25
+ /**
26
+ * The statistics that mean something for a kind of metric, the default first: a count's lines
27
+ * (or summed values), a distribution's percentiles, a gauge's level.
28
+ *
29
+ * @param kind - The metric's kind.
30
+ */
31
+ function statsForKind(kind) {
32
+ switch (kind) {
33
+ case "distribution":
34
+ return ["p95", "p50", "p90", "p99", "avg", "min", "max", "count"];
35
+ case "gauge":
36
+ return ["avg", "last", "min", "max"];
37
+ default:
38
+ return ["count", "sum"];
39
+ }
40
+ }
41
+ /** The columns the table view shows for a kind, besides the chosen statistic. */
42
+ function tableStats(kind) {
43
+ switch (kind) {
44
+ case "distribution":
45
+ return ["count", "avg", "p50", "p95", "p99", "max"];
46
+ case "gauge":
47
+ return ["count", "avg", "min", "max", "last"];
48
+ default:
49
+ return ["count", "sum"];
50
+ }
51
+ }
52
+ const STAT_LABELS = {
53
+ count: "Count",
54
+ sum: "Sum",
55
+ avg: "Average",
56
+ min: "Minimum",
57
+ max: "Maximum",
58
+ last: "Last",
59
+ p50: "p50 (median)",
60
+ p90: "p90",
61
+ p95: "p95",
62
+ p99: "p99",
63
+ };
64
+ /**
65
+ * Metrics: pick one of the device's metrics, a statistic, a label to split it by and a range, and
66
+ * see it over time as a chart or a table, with the range's histogram for a distribution.
67
+ * `calls.duration` leaves out Monitoring's own reads unless asked for, as the Overview does.
68
+ */
69
+ function MetricsTab(props) {
70
+ const deviceId = props.location.deviceId;
71
+ const metrics = (0, use_telemetry_1.useTelemetryRead)(deviceId, async (telemetry) => (await telemetry.tools.listMetrics({})).metrics, []);
72
+ const list = (0, react_1.useMemo)(() => [...(metrics.data ?? [])].sort((a, b) => a.metricId.localeCompare(b.metricId)), [metrics.data]);
73
+ const metricId = props.location.metricId ?? list[0]?.metricId;
74
+ const info = list.find((m) => m.metricId === metricId);
75
+ const stats = statsForKind(info?.kind);
76
+ const [chosenStat, setStat] = (0, react_1.useState)();
77
+ const stat = chosenStat && stats.includes(chosenStat) ? chosenStat : stats[0];
78
+ const [groupByChoice, setGroupBy] = (0, react_1.useState)("");
79
+ const groupBy = info?.labelNames.includes(groupByChoice) ? groupByChoice : "";
80
+ const [range, setRange] = (0, react_1.useState)("24h");
81
+ const [view, setView] = (0, react_1.useState)("chart");
82
+ const [includeOwnReads, setIncludeOwnReads] = (0, react_1.useState)(false);
83
+ const hasOwnReads = metricId === peers_sdk_1.CALL_DURATION_METRIC;
84
+ const excludeOwnReads = hasOwnReads && !includeOwnReads;
85
+ // Series keep their colors across refreshes, the switch and the table view; a new metric or
86
+ // split starts over.
87
+ const colorSlots = (0, react_1.useRef)({ chart: "", slots: new Map() });
88
+ const chart = `${metricId}:${groupBy}`;
89
+ if (colorSlots.current.chart !== chart)
90
+ colorSlots.current = { chart, slots: new Map() };
91
+ const query = (0, use_telemetry_1.useTelemetryRead)(deviceId, async (telemetry) => {
92
+ if (!info)
93
+ return undefined;
94
+ const to = Date.now();
95
+ const span = exports.METRIC_RANGES.find((r) => r.id === range)?.ms ?? exports.METRIC_RANGES[2].ms;
96
+ return telemetry.tools.queryMetric({
97
+ metricId: info.metricId,
98
+ from: to - span,
99
+ to,
100
+ groupBy: groupBy ? [groupBy] : undefined,
101
+ exclude: excludeOwnReads ? telemetry_client_1.OWN_READS : undefined,
102
+ stats: [...new Set([stat, ...tableStats(info?.kind)])],
103
+ histogram: info?.kind === "distribution",
104
+ });
105
+ }, [metricId, stat, groupBy, range, info?.kind, excludeOwnReads]);
106
+ const refresh = () => {
107
+ metrics.refresh();
108
+ query.refresh();
109
+ };
110
+ if (!metrics.data && metrics.error) {
111
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: "d-flex justify-content-end mb-2", children: (0, jsx_runtime_1.jsx)(form_fields_1.RefreshButton, { onClick: refresh, loading: metrics.loading }) }), (0, jsx_runtime_1.jsx)("div", { className: "alert alert-warning", children: (0, telemetry_client_1.describeTelemetryError)(metrics.error) })] }));
112
+ }
113
+ if (!metrics.data)
114
+ return (0, jsx_runtime_1.jsx)("div", { className: "text-body-secondary", children: "Loading\u2026" });
115
+ if (list.length === 0)
116
+ return (0, jsx_runtime_1.jsx)("p", { className: "text-body-secondary", children: "This device has no metrics yet." });
117
+ const formatStat = (value) => stat === "count" ? (0, format_1.formatNumber)(value) : (0, format_1.formatValue)(value, info?.unit);
118
+ return ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsxs)("div", { className: "d-flex flex-wrap gap-2 align-items-end mb-3", children: [(0, jsx_runtime_1.jsx)(Field, { label: "Metric", htmlFor: "metric-pick", children: (0, jsx_runtime_1.jsxs)("select", { id: "metric-pick", className: "form-select form-select-sm", value: metricId, onChange: (event) => props.navigate({ section: "metrics", metricId: event.target.value }), children: [!info && metricId ? (0, jsx_runtime_1.jsx)("option", { value: metricId, children: metricId }) : null, list.map((metric) => ((0, jsx_runtime_1.jsx)("option", { value: metric.metricId, children: metric.metricId }, metric.metricId)))] }) }), (0, jsx_runtime_1.jsx)(Field, { label: "Statistic", htmlFor: "metric-stat", children: (0, jsx_runtime_1.jsx)("select", { id: "metric-stat", className: "form-select form-select-sm", value: stat, onChange: (e) => setStat(e.target.value), children: stats.map((s) => ((0, jsx_runtime_1.jsx)("option", { value: s, children: STAT_LABELS[s] }, s))) }) }), (0, jsx_runtime_1.jsx)(Field, { label: "Split by", htmlFor: "metric-group", children: (0, jsx_runtime_1.jsxs)("select", { id: "metric-group", className: "form-select form-select-sm", value: groupBy, onChange: (e) => setGroupBy(e.target.value), disabled: !info?.labelNames.length, children: [(0, jsx_runtime_1.jsx)("option", { value: "", children: "Nothing (all together)" }), info?.labelNames.map((name) => ((0, jsx_runtime_1.jsx)("option", { value: name, children: name }, name)))] }) }), hasOwnReads ? ((0, jsx_runtime_1.jsx)(form_fields_1.OwnReadsSwitch, { id: "metric-own-reads", className: "align-self-end pb-1", checked: includeOwnReads, onChange: setIncludeOwnReads })) : null, (0, jsx_runtime_1.jsx)("fieldset", { className: "btn-group btn-group-sm", "aria-label": "Range", children: exports.METRIC_RANGES.map((r) => ((0, jsx_runtime_1.jsx)("button", { type: "button", className: `btn ${range === r.id ? "btn-primary" : "btn-outline-secondary"}`, "aria-pressed": range === r.id, onClick: () => setRange(r.id), children: r.id }, r.id))) }), (0, jsx_runtime_1.jsxs)("fieldset", { className: "btn-group btn-group-sm ms-auto", "aria-label": "View", children: [(0, jsx_runtime_1.jsxs)("button", { type: "button", className: `btn ${view === "chart" ? "btn-secondary" : "btn-outline-secondary"}`, "aria-pressed": view === "chart", onClick: () => setView("chart"), children: [(0, jsx_runtime_1.jsx)("i", { className: "bi bi-graph-up me-1", "aria-hidden": "true" }), "Chart"] }), (0, jsx_runtime_1.jsxs)("button", { type: "button", className: `btn ${view === "table" ? "btn-secondary" : "btn-outline-secondary"}`, "aria-pressed": view === "table", onClick: () => setView("table"), children: [(0, jsx_runtime_1.jsx)("i", { className: "bi bi-table me-1", "aria-hidden": "true" }), "Table"] })] }), (0, jsx_runtime_1.jsx)(form_fields_1.RefreshButton, { onClick: refresh, loading: metrics.loading || query.loading, readAt: query.readAt })] }), info ? ((0, jsx_runtime_1.jsx)(MetricSummary, { info: info })) : ((0, jsx_runtime_1.jsxs)("p", { className: "text-body-secondary", children: ["This device has no metric named ", (0, jsx_runtime_1.jsx)("code", { children: metricId }), "."] })), query.error && !query.data ? ((0, jsx_runtime_1.jsx)("div", { className: "alert alert-warning", children: (0, telemetry_client_1.describeTelemetryError)(query.error) })) : null, query.data && query.data.metricId === metricId ? ((0, jsx_runtime_1.jsxs)("div", { style: { opacity: query.loading ? 0.6 : 1, transition: "opacity 150ms" }, children: [view === "chart" ? ((0, jsx_runtime_1.jsx)(MetricChart, { colorSlots: colorSlots.current, result: query.data, stat: stat, label: `${metricId} ${STAT_LABELS[stat]}`, formatValue: formatStat })) : ((0, jsx_runtime_1.jsx)(MetricTable, { result: query.data, stats: [...new Set([stat, ...tableStats(info?.kind)])], unit: info?.unit })), view === "chart" && query.data.histogram?.length ? ((0, jsx_runtime_1.jsxs)("div", { className: "mt-4", children: [(0, jsx_runtime_1.jsx)("h2", { className: "h6", children: "Distribution over the range" }), (0, jsx_runtime_1.jsx)(histogram_chart_1.HistogramChart, { bins: query.data.histogram, formatValue: (v) => (0, format_1.formatValue)(v, info?.unit), label: `${metricId} histogram` })] })) : null] })) : query.loading ? ((0, jsx_runtime_1.jsx)("div", { className: "text-body-secondary", children: "Loading\u2026" })) : null] }));
119
+ }
120
+ function Field(props) {
121
+ return ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("label", { htmlFor: props.htmlFor, className: "form-label small text-body-secondary mb-1", children: props.label }), props.children] }));
122
+ }
123
+ function MetricSummary(props) {
124
+ const { info } = props;
125
+ return ((0, jsx_runtime_1.jsxs)("div", { className: "small text-body-secondary mb-3 d-flex flex-wrap gap-2 align-items-center", children: [(0, jsx_runtime_1.jsx)(badges_1.OriginBadge, { origin: info.origin, packageId: info.originPackageId }), (0, jsx_runtime_1.jsx)("span", { children: info.description }), (0, jsx_runtime_1.jsxs)("span", { children: ["\u00B7 ", info.kind, info.unit ? ` in ${info.unit}` : "", " \u00B7 ", (0, format_1.formatNumber)(info.series), " series \u00B7 last value", " ", (0, format_1.formatAgo)(info.lastAt)] }), info.stoppedReason ? ((0, jsx_runtime_1.jsxs)("span", { className: "text-warning-emphasis", children: [(0, jsx_runtime_1.jsx)("i", { className: "bi bi-exclamation-triangle-fill me-1", "aria-hidden": "true" }), "Switched off: ", info.stoppedReason] })) : null] }));
126
+ }
127
+ /** The chart, with each series keeping the color it was given in `colorSlots`. */
128
+ function MetricChart(props) {
129
+ const data = (0, chart_math_1.toTimeSeries)(props.result, props.stat);
130
+ if (data.series.length === 0)
131
+ return (0, jsx_runtime_1.jsx)("p", { className: "text-body-secondary", children: "No values in this range." });
132
+ const drawn = data.series.slice(0, chart_math_1.MAX_CHART_SERIES);
133
+ const slots = (0, chart_math_1.assignColorSlots)(props.colorSlots.slots, drawn.map((s) => s.key));
134
+ props.colorSlots.slots = slots;
135
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(line_chart_1.LineChart, { times: data.times, series: drawn.map((s) => ({ ...s, slot: slots.get(s.key) ?? 0 })), formatValue: props.formatValue, label: props.label }), data.series.length > chart_math_1.MAX_CHART_SERIES ? ((0, jsx_runtime_1.jsxs)("p", { className: "small text-body-secondary mt-2 mb-0", children: ["The ", chart_math_1.MAX_CHART_SERIES, " largest of ", data.series.length, " series are drawn."] })) : null, (0, jsx_runtime_1.jsxs)("p", { className: "small text-body-secondary mt-1 mb-0", children: ["By ", props.result.resolution, "."] })] }));
136
+ }
137
+ const MAX_TABLE_ROWS = 500;
138
+ /** Every bucket and group, newest first. */
139
+ function MetricTable(props) {
140
+ const rows = [...props.result.points].sort((a, b) => b.start - a.start);
141
+ const grouped = rows.some((p) => Object.keys(p.group).length > 0);
142
+ if (rows.length === 0)
143
+ return (0, jsx_runtime_1.jsx)("p", { className: "text-body-secondary", children: "No values in this range." });
144
+ return ((0, jsx_runtime_1.jsxs)("div", { className: "table-responsive", children: [(0, jsx_runtime_1.jsxs)("table", { className: "table table-sm table-hover small", style: { fontVariantNumeric: "tabular-nums" }, children: [(0, jsx_runtime_1.jsx)("thead", { children: (0, jsx_runtime_1.jsxs)("tr", { children: [(0, jsx_runtime_1.jsxs)("th", { children: ["Time (", props.result.resolution, ")"] }), grouped ? (0, jsx_runtime_1.jsx)("th", { children: "Series" }) : null, props.stats.map((s) => ((0, jsx_runtime_1.jsx)("th", { className: "text-end", children: STAT_LABELS[s] }, s)))] }) }), (0, jsx_runtime_1.jsx)("tbody", { children: rows.slice(0, MAX_TABLE_ROWS).map((point) => ((0, jsx_runtime_1.jsxs)("tr", { children: [(0, jsx_runtime_1.jsx)("td", { className: "text-nowrap", children: new Date(point.start).toLocaleString() }), grouped ? ((0, jsx_runtime_1.jsx)("td", { children: Object.entries(point.group)
145
+ .map(([name, value]) => `${name}=${value}`)
146
+ .join(", ") })) : null, props.stats.map((s) => ((0, jsx_runtime_1.jsx)("td", { className: "text-end", children: s === "count"
147
+ ? (0, format_1.formatNumber)((0, chart_math_1.statOf)(point, s))
148
+ : (0, format_1.formatValue)((0, chart_math_1.statOf)(point, s), props.unit) }, s)))] }, `${point.start}:${JSON.stringify(point.group)}`))) })] }), rows.length > MAX_TABLE_ROWS ? ((0, jsx_runtime_1.jsxs)("p", { className: "small text-body-secondary", children: ["The newest ", MAX_TABLE_ROWS, " of ", rows.length, " rows."] })) : null] }));
149
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Monitoring app routes: `monitoring/<section>`, with the device, trace and metric being looked at
3
+ * in the query, so a link opens the same view and every section keeps the chosen device.
4
+ *
5
+ * `console-logs`, Console Logs' old path, opens the Logs section (see `canonicalizeRoute`).
6
+ */
7
+ /** Top-level Monitoring path. Opening it lands on Overview. */
8
+ export declare const MONITORING_APP_PATH = "monitoring";
9
+ /** The path Console Logs had, rewritten to {@link MONITORING_LOGS_PATH}. */
10
+ export declare const LEGACY_CONSOLE_LOGS_PATH = "console-logs";
11
+ /** Monitoring's sections, in sidebar order. */
12
+ export declare const MONITORING_SECTIONS: readonly ["overview", "metrics", "alerts", "definitions", "logs", "calls"];
13
+ /** One of Monitoring's sections. */
14
+ export type MonitoringSectionId = (typeof MONITORING_SECTIONS)[number];
15
+ /** The Logs section's path, where `console-logs` lands. */
16
+ export declare const MONITORING_LOGS_PATH = "monitoring/logs";
17
+ /** Where in Monitoring a route points. */
18
+ export interface IMonitoringLocation {
19
+ section: MonitoringSectionId;
20
+ /** The device being looked at; omitted for this device. */
21
+ deviceId?: string;
22
+ /** A trace the Logs and Calls sections are narrowed to. */
23
+ traceId?: string;
24
+ /** The metric the Metrics section opens on. */
25
+ metricId?: string;
26
+ }
27
+ /**
28
+ * Read a Monitoring route.
29
+ *
30
+ * @param raw - A route, with or without a leading `#` and a query.
31
+ * @returns Where it points, or `undefined` when it isn't a Monitoring route.
32
+ */
33
+ export declare function parseMonitoringLocation(raw: string | null | undefined): IMonitoringLocation | undefined;
34
+ /**
35
+ * Build a Monitoring route.
36
+ *
37
+ * @param location - The section, and the device, trace and metric to keep.
38
+ * @returns A route such as `monitoring/logs?device=…&trace=…`.
39
+ */
40
+ export declare function monitoringPath(location: IMonitoringLocation): string;