@peers-app/peers-ui 0.34.9 → 0.34.11
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.
- package/dist/apps-home/apps-home.js +6 -4
- package/dist/components/router.d.ts +1 -1
- package/dist/components/router.js +1 -1
- package/dist/screens/identity/identity-routes.d.ts +2 -1
- package/dist/screens/identity/identity-routes.js +6 -1
- package/dist/screens/monitoring/alerts-tab.d.ts +13 -0
- package/dist/screens/monitoring/alerts-tab.js +68 -0
- package/dist/screens/monitoring/badges.d.ts +25 -0
- package/dist/screens/monitoring/badges.js +68 -0
- package/dist/screens/monitoring/calls-tab.d.ts +30 -0
- package/dist/screens/monitoring/calls-tab.js +104 -0
- package/dist/screens/monitoring/charts/chart-math.d.ts +103 -0
- package/dist/screens/monitoring/charts/chart-math.js +200 -0
- package/dist/screens/monitoring/charts/histogram-chart.d.ts +25 -0
- package/dist/screens/monitoring/charts/histogram-chart.js +74 -0
- package/dist/screens/monitoring/charts/line-chart.d.ts +33 -0
- package/dist/screens/monitoring/charts/line-chart.js +103 -0
- package/dist/screens/monitoring/charts/sparkline.d.ts +30 -0
- package/dist/screens/monitoring/charts/sparkline.js +61 -0
- package/dist/screens/monitoring/charts/use-width.d.ts +9 -0
- package/dist/screens/monitoring/charts/use-width.js +31 -0
- package/dist/screens/monitoring/definition-forms.d.ts +113 -0
- package/dist/screens/monitoring/definition-forms.js +341 -0
- package/dist/screens/monitoring/definitions-tab.d.ts +20 -0
- package/dist/screens/monitoring/definitions-tab.js +110 -0
- package/dist/screens/monitoring/device-picker.d.ts +23 -0
- package/dist/screens/monitoring/device-picker.js +30 -0
- package/dist/screens/monitoring/devices-tab.d.ts +6 -0
- package/dist/screens/monitoring/devices-tab.js +74 -0
- package/dist/screens/monitoring/form-fields.d.ts +76 -0
- package/dist/screens/monitoring/form-fields.js +65 -0
- package/dist/screens/monitoring/format.d.ts +51 -0
- package/dist/screens/monitoring/format.js +150 -0
- package/dist/screens/monitoring/log-lines.d.ts +74 -0
- package/dist/screens/monitoring/log-lines.js +138 -0
- package/dist/screens/monitoring/log-row.d.ts +12 -0
- package/dist/screens/monitoring/log-row.js +23 -0
- package/dist/screens/monitoring/logs-tab.d.ts +15 -0
- package/dist/screens/monitoring/logs-tab.js +256 -0
- package/dist/screens/monitoring/metric-definition-form.d.ts +15 -0
- package/dist/screens/monitoring/metric-definition-form.js +50 -0
- package/dist/screens/monitoring/metrics-tab.d.ts +37 -0
- package/dist/screens/monitoring/metrics-tab.js +149 -0
- package/dist/screens/monitoring/monitored-devices.d.ts +84 -0
- package/dist/screens/monitoring/monitored-devices.js +193 -0
- package/dist/screens/monitoring/monitoring-routes.d.ts +40 -0
- package/dist/screens/monitoring/monitoring-routes.js +82 -0
- package/dist/screens/monitoring/monitoring-screen.d.ts +18 -0
- package/dist/screens/monitoring/monitoring-screen.js +71 -0
- package/dist/screens/monitoring/overview-tab.d.ts +51 -0
- package/dist/screens/monitoring/overview-tab.js +136 -0
- package/dist/screens/monitoring/telemetry-client.d.ts +48 -0
- package/dist/screens/monitoring/telemetry-client.js +92 -0
- package/dist/screens/monitoring/trigger-form.d.ts +18 -0
- package/dist/screens/monitoring/trigger-form.js +71 -0
- package/dist/screens/monitoring/use-telemetry.d.ts +37 -0
- package/dist/screens/monitoring/use-telemetry.js +119 -0
- package/dist/screens/network-viewer/remote-logs-panel.d.ts +1 -1
- package/dist/screens/network-viewer/remote-logs-panel.js +5 -3
- package/dist/system-apps/index.d.ts +1 -1
- package/dist/system-apps/index.js +5 -5
- package/dist/system-apps/monitoring.app.d.ts +6 -0
- package/dist/system-apps/monitoring.app.js +13 -0
- package/dist/tabs-layout/tabs-state.d.ts +4 -2
- package/dist/tabs-layout/tabs-state.js +23 -11
- package/dist/theme.css +32 -0
- package/package.json +3 -3
- package/dist/screens/console-logs/console-logs-list.d.ts +0 -2
- package/dist/screens/console-logs/console-logs-list.js +0 -284
- package/dist/screens/console-logs/follow-newest.d.ts +0 -11
- package/dist/screens/console-logs/follow-newest.js +0 -17
- package/dist/screens/console-logs/log-display.d.ts +0 -12
- package/dist/screens/console-logs/log-display.js +0 -69
- package/dist/screens/console-logs/log-filters.d.ts +0 -10
- package/dist/screens/console-logs/log-filters.js +0 -8
- package/dist/screens/console-logs/mobile-log-card.d.ts +0 -8
- package/dist/screens/console-logs/mobile-log-card.js +0 -94
- package/dist/screens/console-logs/resizable-table-header.d.ts +0 -14
- package/dist/screens/console-logs/resizable-table-header.js +0 -62
- package/dist/system-apps/console-logs.app.d.ts +0 -2
- package/dist/system-apps/console-logs.app.js +0 -8
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { type IDevice } from "@peers-app/peers-sdk";
|
|
2
|
+
/** A device Monitoring can read: one of the user's own, or another user's that lets them. */
|
|
3
|
+
export interface IMonitoredDevice {
|
|
4
|
+
deviceId: string;
|
|
5
|
+
/**
|
|
6
|
+
* What Monitoring calls it: the device's name, or for another user's device
|
|
7
|
+
* "<their name> · <device name>". Empty for this device when it has no name yet.
|
|
8
|
+
*/
|
|
9
|
+
name: string;
|
|
10
|
+
isThisDevice: boolean;
|
|
11
|
+
/** Another user's device, which answered this user's System Telemetry call. */
|
|
12
|
+
isOthers?: boolean;
|
|
13
|
+
/** When one of the user's own devices last connected to this one. */
|
|
14
|
+
lastSeen?: Date;
|
|
15
|
+
}
|
|
16
|
+
/** Another user's device that's connected now and lets this user read its telemetry. */
|
|
17
|
+
export interface IReadableDevice {
|
|
18
|
+
deviceId: string;
|
|
19
|
+
userId: string;
|
|
20
|
+
/** Its user's name, as this device knows them. */
|
|
21
|
+
userName?: string;
|
|
22
|
+
/** The name the device reports. */
|
|
23
|
+
deviceName?: string;
|
|
24
|
+
}
|
|
25
|
+
/** A device's own name: the one given here, or else the one it reports. */
|
|
26
|
+
export declare function ownDeviceName(device: Pick<IDevice, "name" | "reportedName">): string;
|
|
27
|
+
/**
|
|
28
|
+
* Another user's device as Monitoring names it: "Blair · Laptop", or just "Kitchen" when the
|
|
29
|
+
* device is named after its user or has no name of its own.
|
|
30
|
+
*
|
|
31
|
+
* @param device - The device, with its user's name and its own.
|
|
32
|
+
*/
|
|
33
|
+
export declare function othersDeviceLabel(device: Pick<IReadableDevice, "deviceId" | "userName" | "deviceName">): string;
|
|
34
|
+
/**
|
|
35
|
+
* The devices Monitoring lists: this one first, then the user's others by name, then other
|
|
36
|
+
* users' devices that let them read their telemetry, by name.
|
|
37
|
+
*
|
|
38
|
+
* @param input.thisDeviceId - This device's id.
|
|
39
|
+
* @param input.userId - The signed-in user.
|
|
40
|
+
* @param input.rows - The personal Devices table: the user's own devices, and names for others'.
|
|
41
|
+
* @param input.others - Other users' devices that answered.
|
|
42
|
+
*/
|
|
43
|
+
export declare function buildMonitoredDevices(input: {
|
|
44
|
+
thisDeviceId: string | undefined;
|
|
45
|
+
userId: string;
|
|
46
|
+
rows: IDevice[];
|
|
47
|
+
others: IReadableDevice[];
|
|
48
|
+
}): IMonitoredDevice[];
|
|
49
|
+
/**
|
|
50
|
+
* A promise that rejects with "did not answer within …" when `promise` takes longer than `ms`.
|
|
51
|
+
* The wording reads as an unreachable device ({@link classifyTelemetryError}).
|
|
52
|
+
*
|
|
53
|
+
* @param promise - The call.
|
|
54
|
+
* @param ms - How long to wait.
|
|
55
|
+
*/
|
|
56
|
+
export declare function withTimeout<T>(promise: Promise<T>, ms: number): Promise<T>;
|
|
57
|
+
/** How long an answer about another user's device is reused before it's asked again. */
|
|
58
|
+
export declare const PROBE_TTL_MS: number;
|
|
59
|
+
/**
|
|
60
|
+
* Whether another user's device lets this user read its telemetry: it answers System Telemetry's
|
|
61
|
+
* `status`, or says it runs a Peers version without it, which it only says once the call is
|
|
62
|
+
* allowed. A yes or no is kept for {@link PROBE_TTL_MS}, and calls made meanwhile share it; a
|
|
63
|
+
* device that didn't answer is asked again next time.
|
|
64
|
+
*
|
|
65
|
+
* @param deviceId - The device.
|
|
66
|
+
* @param fresh - Ask again, even if it answered recently.
|
|
67
|
+
*/
|
|
68
|
+
export declare function canReadTelemetry(deviceId: string, fresh?: boolean): Promise<boolean>;
|
|
69
|
+
/** Forget every answer {@link canReadTelemetry} kept (for tests). */
|
|
70
|
+
export declare function resetTelemetryProbes(): void;
|
|
71
|
+
/**
|
|
72
|
+
* Other users' devices connected to this one that let this user read their telemetry. Only
|
|
73
|
+
* connected devices are asked, so a device that's offline, or reached only through the mesh, is
|
|
74
|
+
* left out until it connects. Empty when this device can't list its connections.
|
|
75
|
+
*
|
|
76
|
+
* Once `signal` is aborted, the pass stops waiting for the host link, lists no connections, and
|
|
77
|
+
* asks no device it hasn't asked yet. A question already on its way finishes, since another
|
|
78
|
+
* caller may be waiting on the same answer.
|
|
79
|
+
*
|
|
80
|
+
* @param userId - The signed-in user, whose own devices are left out.
|
|
81
|
+
* @param fresh - Ask every device again.
|
|
82
|
+
* @param signal - Ends the pass (Monitoring closed, or a newer pass started).
|
|
83
|
+
*/
|
|
84
|
+
export declare function readableOthersDevices(userId: string, fresh?: boolean, signal?: AbortSignal): Promise<IReadableDevice[]>;
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PROBE_TTL_MS = void 0;
|
|
4
|
+
exports.ownDeviceName = ownDeviceName;
|
|
5
|
+
exports.othersDeviceLabel = othersDeviceLabel;
|
|
6
|
+
exports.buildMonitoredDevices = buildMonitoredDevices;
|
|
7
|
+
exports.withTimeout = withTimeout;
|
|
8
|
+
exports.canReadTelemetry = canReadTelemetry;
|
|
9
|
+
exports.resetTelemetryProbes = resetTelemetryProbes;
|
|
10
|
+
exports.readableOthersDevices = readableOthersDevices;
|
|
11
|
+
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
12
|
+
const telemetry_client_1 = require("./telemetry-client");
|
|
13
|
+
/** A device's own name: the one given here, or else the one it reports. */
|
|
14
|
+
function ownDeviceName(device) {
|
|
15
|
+
return device.name || device.reportedName || "";
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Another user's device as Monitoring names it: "Blair · Laptop", or just "Kitchen" when the
|
|
19
|
+
* device is named after its user or has no name of its own.
|
|
20
|
+
*
|
|
21
|
+
* @param device - The device, with its user's name and its own.
|
|
22
|
+
*/
|
|
23
|
+
function othersDeviceLabel(device) {
|
|
24
|
+
const user = device.userName?.trim();
|
|
25
|
+
const name = device.deviceName?.trim();
|
|
26
|
+
if (user && name && name.toLowerCase() !== user.toLowerCase())
|
|
27
|
+
return `${user} · ${name}`;
|
|
28
|
+
return user || name || device.deviceId;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The devices Monitoring lists: this one first, then the user's others by name, then other
|
|
32
|
+
* users' devices that let them read their telemetry, by name.
|
|
33
|
+
*
|
|
34
|
+
* @param input.thisDeviceId - This device's id.
|
|
35
|
+
* @param input.userId - The signed-in user.
|
|
36
|
+
* @param input.rows - The personal Devices table: the user's own devices, and names for others'.
|
|
37
|
+
* @param input.others - Other users' devices that answered.
|
|
38
|
+
*/
|
|
39
|
+
function buildMonitoredDevices(input) {
|
|
40
|
+
const { thisDeviceId = "", userId, rows, others } = input;
|
|
41
|
+
const byName = (a, b) => a.name.localeCompare(b.name);
|
|
42
|
+
const mine = rows.filter((row) => row.userId === userId);
|
|
43
|
+
const thisRow = mine.find((row) => row.deviceId === thisDeviceId);
|
|
44
|
+
const own = mine
|
|
45
|
+
.filter((row) => row.deviceId !== thisDeviceId)
|
|
46
|
+
.map((row) => ({
|
|
47
|
+
deviceId: row.deviceId,
|
|
48
|
+
name: ownDeviceName(row) || row.deviceId,
|
|
49
|
+
isThisDevice: false,
|
|
50
|
+
lastSeen: row.lastSeen,
|
|
51
|
+
}))
|
|
52
|
+
.sort(byName);
|
|
53
|
+
const listed = new Set([thisDeviceId, ...own.map((device) => device.deviceId)]);
|
|
54
|
+
const known = new Map(rows.map((row) => [row.deviceId, row]));
|
|
55
|
+
const theirs = others
|
|
56
|
+
.filter((device) => device.userId !== userId && !listed.has(device.deviceId))
|
|
57
|
+
.map((device) => {
|
|
58
|
+
const row = known.get(device.deviceId);
|
|
59
|
+
return {
|
|
60
|
+
deviceId: device.deviceId,
|
|
61
|
+
name: othersDeviceLabel({
|
|
62
|
+
...device,
|
|
63
|
+
deviceName: device.deviceName || (row ? ownDeviceName(row) : undefined),
|
|
64
|
+
}),
|
|
65
|
+
isThisDevice: false,
|
|
66
|
+
isOthers: true,
|
|
67
|
+
};
|
|
68
|
+
})
|
|
69
|
+
.sort(byName);
|
|
70
|
+
return [
|
|
71
|
+
{ deviceId: thisDeviceId, name: thisRow ? ownDeviceName(thisRow) : "", isThisDevice: true },
|
|
72
|
+
...own,
|
|
73
|
+
...theirs,
|
|
74
|
+
];
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* A promise that rejects with "did not answer within …" when `promise` takes longer than `ms`.
|
|
78
|
+
* The wording reads as an unreachable device ({@link classifyTelemetryError}).
|
|
79
|
+
*
|
|
80
|
+
* @param promise - The call.
|
|
81
|
+
* @param ms - How long to wait.
|
|
82
|
+
*/
|
|
83
|
+
function withTimeout(promise, ms) {
|
|
84
|
+
let timer;
|
|
85
|
+
const timeout = new Promise((_, reject) => {
|
|
86
|
+
timer = setTimeout(() => reject(new Error(`did not answer within ${Math.round(ms / 1000)} seconds`)), ms);
|
|
87
|
+
});
|
|
88
|
+
return Promise.race([promise, timeout]).finally(() => clearTimeout(timer));
|
|
89
|
+
}
|
|
90
|
+
/** How long an answer about another user's device is reused before it's asked again. */
|
|
91
|
+
exports.PROBE_TTL_MS = 10 * 60_000;
|
|
92
|
+
/** How long another user's device has to answer before it's left out this time. */
|
|
93
|
+
const PROBE_TIMEOUT_MS = 8_000;
|
|
94
|
+
const probes = new Map();
|
|
95
|
+
/**
|
|
96
|
+
* Whether another user's device lets this user read its telemetry: it answers System Telemetry's
|
|
97
|
+
* `status`, or says it runs a Peers version without it, which it only says once the call is
|
|
98
|
+
* allowed. A yes or no is kept for {@link PROBE_TTL_MS}, and calls made meanwhile share it; a
|
|
99
|
+
* device that didn't answer is asked again next time.
|
|
100
|
+
*
|
|
101
|
+
* @param deviceId - The device.
|
|
102
|
+
* @param fresh - Ask again, even if it answered recently.
|
|
103
|
+
*/
|
|
104
|
+
async function canReadTelemetry(deviceId, fresh = false) {
|
|
105
|
+
const cached = probes.get(deviceId);
|
|
106
|
+
if (!fresh && cached && Date.now() - cached.at < exports.PROBE_TTL_MS) {
|
|
107
|
+
return (await cached.result) === "readable";
|
|
108
|
+
}
|
|
109
|
+
const entry = { at: Date.now(), result: probe(deviceId) };
|
|
110
|
+
probes.set(deviceId, entry);
|
|
111
|
+
const result = await entry.result;
|
|
112
|
+
if (result === "unknown" && probes.get(deviceId) === entry)
|
|
113
|
+
probes.delete(deviceId);
|
|
114
|
+
return result === "readable";
|
|
115
|
+
}
|
|
116
|
+
async function probe(deviceId) {
|
|
117
|
+
try {
|
|
118
|
+
await withTimeout((0, telemetry_client_1.getTelemetry)(deviceId).then((telemetry) => telemetry.tools.status({})), PROBE_TIMEOUT_MS);
|
|
119
|
+
return "readable";
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
switch ((0, telemetry_client_1.classifyTelemetryError)(error)) {
|
|
123
|
+
case "unavailable":
|
|
124
|
+
return "readable";
|
|
125
|
+
case "denied":
|
|
126
|
+
return "denied";
|
|
127
|
+
default:
|
|
128
|
+
return "unknown";
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/** Forget every answer {@link canReadTelemetry} kept (for tests). */
|
|
133
|
+
function resetTelemetryProbes() {
|
|
134
|
+
probes.clear();
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Other users' devices connected to this one that let this user read their telemetry. Only
|
|
138
|
+
* connected devices are asked, so a device that's offline, or reached only through the mesh, is
|
|
139
|
+
* left out until it connects. Empty when this device can't list its connections.
|
|
140
|
+
*
|
|
141
|
+
* Once `signal` is aborted, the pass stops waiting for the host link, lists no connections, and
|
|
142
|
+
* asks no device it hasn't asked yet. A question already on its way finishes, since another
|
|
143
|
+
* caller may be waiting on the same answer.
|
|
144
|
+
*
|
|
145
|
+
* @param userId - The signed-in user, whose own devices are left out.
|
|
146
|
+
* @param fresh - Ask every device again.
|
|
147
|
+
* @param signal - Ends the pass (Monitoring closed, or a newer pass started).
|
|
148
|
+
*/
|
|
149
|
+
async function readableOthersDevices(userId, fresh = false, signal) {
|
|
150
|
+
let connections;
|
|
151
|
+
try {
|
|
152
|
+
const transport = await (0, peers_sdk_1.waitForHostContractTransport)({ timeoutMs: 10_000, signal });
|
|
153
|
+
if (signal?.aborted)
|
|
154
|
+
return [];
|
|
155
|
+
connections = await listConnections(transport);
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
return [];
|
|
159
|
+
}
|
|
160
|
+
if (signal?.aborted)
|
|
161
|
+
return [];
|
|
162
|
+
const candidates = new Map();
|
|
163
|
+
for (const connection of connections) {
|
|
164
|
+
if (connection.userId === userId || candidates.has(connection.deviceId))
|
|
165
|
+
continue;
|
|
166
|
+
candidates.set(connection.deviceId, {
|
|
167
|
+
deviceId: connection.deviceId,
|
|
168
|
+
userId: connection.userId,
|
|
169
|
+
userName: connection.userName,
|
|
170
|
+
deviceName: connection.deviceName,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
const answers = await Promise.all([...candidates.values()].map(async (device) => ({
|
|
174
|
+
device,
|
|
175
|
+
readable: await canReadTelemetry(device.deviceId, fresh),
|
|
176
|
+
})));
|
|
177
|
+
return answers.filter((answer) => answer.readable).map((answer) => answer.device);
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* This device's connections, asked through a consumer of Network Diagnostics' tools alone. The
|
|
181
|
+
* shared consumer (`getNetworkDiagnosticsConsumer`) also subscribes to the diagnostics `status`
|
|
182
|
+
* and reads it as it loads, which a closed Monitoring can't stop, and keeps that subscription
|
|
183
|
+
* until the host link changes. This one makes the single call, then lets go.
|
|
184
|
+
*/
|
|
185
|
+
async function listConnections(transport) {
|
|
186
|
+
const diagnostics = (0, peers_sdk_1.createContractConsumer)({ ...(0, peers_sdk_1.getNetworkDiagnosticsContractDefinition)(), observables: [] }, transport);
|
|
187
|
+
try {
|
|
188
|
+
return (await diagnostics.tools.getConnections()).connections;
|
|
189
|
+
}
|
|
190
|
+
finally {
|
|
191
|
+
diagnostics.dispose();
|
|
192
|
+
}
|
|
193
|
+
}
|
|
@@ -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", "devices", "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;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Monitoring app routes: `monitoring/<section>`, with the device, trace and metric being looked at
|
|
4
|
+
* in the query, so a link opens the same view and every section keeps the chosen device.
|
|
5
|
+
*
|
|
6
|
+
* `console-logs`, Console Logs' old path, opens the Logs section (see `canonicalizeRoute`).
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.MONITORING_LOGS_PATH = exports.MONITORING_SECTIONS = exports.LEGACY_CONSOLE_LOGS_PATH = exports.MONITORING_APP_PATH = void 0;
|
|
10
|
+
exports.parseMonitoringLocation = parseMonitoringLocation;
|
|
11
|
+
exports.monitoringPath = monitoringPath;
|
|
12
|
+
/** Top-level Monitoring path. Opening it lands on Overview. */
|
|
13
|
+
exports.MONITORING_APP_PATH = "monitoring";
|
|
14
|
+
/** The path Console Logs had, rewritten to {@link MONITORING_LOGS_PATH}. */
|
|
15
|
+
exports.LEGACY_CONSOLE_LOGS_PATH = "console-logs";
|
|
16
|
+
/** Monitoring's sections, in sidebar order. */
|
|
17
|
+
exports.MONITORING_SECTIONS = [
|
|
18
|
+
"overview",
|
|
19
|
+
"devices",
|
|
20
|
+
"metrics",
|
|
21
|
+
"alerts",
|
|
22
|
+
"definitions",
|
|
23
|
+
"logs",
|
|
24
|
+
"calls",
|
|
25
|
+
];
|
|
26
|
+
/** The Logs section's path, where `console-logs` lands. */
|
|
27
|
+
exports.MONITORING_LOGS_PATH = `${exports.MONITORING_APP_PATH}/logs`;
|
|
28
|
+
const SECTIONS = new Set(exports.MONITORING_SECTIONS);
|
|
29
|
+
/**
|
|
30
|
+
* Read a Monitoring route.
|
|
31
|
+
*
|
|
32
|
+
* @param raw - A route, with or without a leading `#` and a query.
|
|
33
|
+
* @returns Where it points, or `undefined` when it isn't a Monitoring route.
|
|
34
|
+
*/
|
|
35
|
+
function parseMonitoringLocation(raw) {
|
|
36
|
+
const text = (raw ?? "").trim().replace(/^\/?#/, "");
|
|
37
|
+
const queryIndex = text.indexOf("?");
|
|
38
|
+
const pathname = (queryIndex >= 0 ? text.slice(0, queryIndex) : text)
|
|
39
|
+
.replace(/^\/+|\/+$/g, "")
|
|
40
|
+
.toLowerCase();
|
|
41
|
+
const query = new URLSearchParams(queryIndex >= 0 ? text.slice(queryIndex + 1) : "");
|
|
42
|
+
const parts = pathname.split("/").filter(Boolean);
|
|
43
|
+
let section;
|
|
44
|
+
if (parts[0] === exports.LEGACY_CONSOLE_LOGS_PATH) {
|
|
45
|
+
section = "logs";
|
|
46
|
+
}
|
|
47
|
+
else if (parts[0] === exports.MONITORING_APP_PATH) {
|
|
48
|
+
section = SECTIONS.has(parts[1] ?? "") ? parts[1] : "overview";
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
const location = { section };
|
|
54
|
+
const deviceId = query.get("device")?.trim();
|
|
55
|
+
const traceId = query.get("trace")?.trim();
|
|
56
|
+
const metricId = query.get("metric")?.trim();
|
|
57
|
+
if (deviceId)
|
|
58
|
+
location.deviceId = deviceId;
|
|
59
|
+
if (traceId)
|
|
60
|
+
location.traceId = traceId;
|
|
61
|
+
if (metricId)
|
|
62
|
+
location.metricId = metricId;
|
|
63
|
+
return location;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Build a Monitoring route.
|
|
67
|
+
*
|
|
68
|
+
* @param location - The section, and the device, trace and metric to keep.
|
|
69
|
+
* @returns A route such as `monitoring/logs?device=…&trace=…`.
|
|
70
|
+
*/
|
|
71
|
+
function monitoringPath(location) {
|
|
72
|
+
const query = new URLSearchParams();
|
|
73
|
+
if (location.deviceId)
|
|
74
|
+
query.set("device", location.deviceId);
|
|
75
|
+
if (location.traceId)
|
|
76
|
+
query.set("trace", location.traceId);
|
|
77
|
+
if (location.metricId)
|
|
78
|
+
query.set("metric", location.metricId);
|
|
79
|
+
const queryString = query.toString();
|
|
80
|
+
const path = `${exports.MONITORING_APP_PATH}/${location.section}`;
|
|
81
|
+
return queryString ? `${path}?${queryString}` : path;
|
|
82
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type IMonitoringLocation, type MonitoringSectionId } from "./monitoring-routes";
|
|
2
|
+
/** What every section gets: where it is, and a way to go somewhere else in Monitoring. */
|
|
3
|
+
export interface MonitoringSectionProps {
|
|
4
|
+
location: IMonitoringLocation;
|
|
5
|
+
/** Go to another section or view, keeping the device unless `next` names one. */
|
|
6
|
+
navigate: (next: Partial<IMonitoringLocation> & {
|
|
7
|
+
section: MonitoringSectionId;
|
|
8
|
+
}) => void;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Monitoring: a device's logs, metrics, calls and alerts, and the metric and trigger definitions
|
|
12
|
+
* behind them, for this device, the user's others, and other users' devices that let them read
|
|
13
|
+
* them. The device picker applies to every section but All devices, which lists them all, and
|
|
14
|
+
* the route keeps the device, so a link opens the same view.
|
|
15
|
+
*/
|
|
16
|
+
export declare function MonitoringScreen(props: {
|
|
17
|
+
path?: string;
|
|
18
|
+
}): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MonitoringScreen = MonitoringScreen;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const responsive_section_nav_1 = require("../../components/responsive-section-nav");
|
|
6
|
+
const globals_1 = require("../../globals");
|
|
7
|
+
const hooks_1 = require("../../hooks");
|
|
8
|
+
const ui_loader_1 = require("../../ui-router/ui-loader");
|
|
9
|
+
const alerts_tab_1 = require("./alerts-tab");
|
|
10
|
+
const calls_tab_1 = require("./calls-tab");
|
|
11
|
+
const definitions_tab_1 = require("./definitions-tab");
|
|
12
|
+
const device_picker_1 = require("./device-picker");
|
|
13
|
+
const devices_tab_1 = require("./devices-tab");
|
|
14
|
+
const logs_tab_1 = require("./logs-tab");
|
|
15
|
+
const metrics_tab_1 = require("./metrics-tab");
|
|
16
|
+
const monitoring_routes_1 = require("./monitoring-routes");
|
|
17
|
+
const overview_tab_1 = require("./overview-tab");
|
|
18
|
+
const use_telemetry_1 = require("./use-telemetry");
|
|
19
|
+
const SECTIONS = [
|
|
20
|
+
{ id: "overview", label: "Overview", iconClassName: "bi-speedometer2" },
|
|
21
|
+
{ id: "devices", label: "All devices", iconClassName: "bi-pc-display-horizontal" },
|
|
22
|
+
{ id: "metrics", label: "Metrics", iconClassName: "bi-graph-up" },
|
|
23
|
+
{ id: "alerts", label: "Alerts", iconClassName: "bi-bell" },
|
|
24
|
+
{ id: "definitions", label: "Definitions", iconClassName: "bi-sliders" },
|
|
25
|
+
{ id: "logs", label: "Logs", iconClassName: "bi-list-columns-reverse" },
|
|
26
|
+
{ id: "calls", label: "Calls", iconClassName: "bi-arrow-left-right" },
|
|
27
|
+
];
|
|
28
|
+
/**
|
|
29
|
+
* Monitoring: a device's logs, metrics, calls and alerts, and the metric and trigger definitions
|
|
30
|
+
* behind them, for this device, the user's others, and other users' devices that let them read
|
|
31
|
+
* them. The device picker applies to every section but All devices, which lists them all, and
|
|
32
|
+
* the route keeps the device, so a link opens the same view.
|
|
33
|
+
*/
|
|
34
|
+
function MonitoringScreen(props) {
|
|
35
|
+
const [livePath] = (0, hooks_1.useObservable)(globals_1.mainContentPath);
|
|
36
|
+
const location = (0, monitoring_routes_1.parseMonitoringLocation)(props.path ?? livePath);
|
|
37
|
+
// A kept-mounted tab whose route is another app's shows (and reads) nothing.
|
|
38
|
+
if (!location)
|
|
39
|
+
return null;
|
|
40
|
+
const navigate = (next) => {
|
|
41
|
+
(0, globals_1.mainContentPath)((0, monitoring_routes_1.monitoringPath)({ deviceId: location.deviceId, ...next }));
|
|
42
|
+
};
|
|
43
|
+
const section = { location, navigate };
|
|
44
|
+
return ((0, jsx_runtime_1.jsx)(responsive_section_nav_1.ResponsiveSectionNav, { label: "Monitoring", sections: SECTIONS, activeSectionId: location.section, onSelect: (id) => navigate({ section: id }), toolbar: (0, jsx_runtime_1.jsx)(Toolbar, { location: location }), children: (0, jsx_runtime_1.jsxs)("div", { className: "p-3", children: [location.section === "overview" ? (0, jsx_runtime_1.jsx)(overview_tab_1.OverviewTab, { ...section }) : null, location.section === "devices" ? (0, jsx_runtime_1.jsx)(devices_tab_1.DevicesTab, { ...section }) : null, location.section === "metrics" ? (0, jsx_runtime_1.jsx)(metrics_tab_1.MetricsTab, { ...section }) : null, location.section === "alerts" ? (0, jsx_runtime_1.jsx)(alerts_tab_1.AlertsTab, { ...section }) : null, location.section === "definitions" ? (0, jsx_runtime_1.jsx)(definitions_tab_1.DefinitionsTab, { ...section }) : null, location.section === "logs" ? (0, jsx_runtime_1.jsx)(logs_tab_1.LogsTab, { ...section }) : null, location.section === "calls" ? (0, jsx_runtime_1.jsx)(calls_tab_1.CallsTab, { ...section }) : null] }, location.deviceId ?? "this") }));
|
|
45
|
+
}
|
|
46
|
+
/** The title and, outside All devices, the device picker. */
|
|
47
|
+
function Toolbar(props) {
|
|
48
|
+
const { location } = props;
|
|
49
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center gap-2 border-bottom px-3 py-2", children: [(0, jsx_runtime_1.jsx)("div", { className: "me-auto fw-semibold", children: "Monitoring" }), location.section === "devices" ? null : (0, jsx_runtime_1.jsx)(ToolbarPicker, { location: location })] }));
|
|
50
|
+
}
|
|
51
|
+
/** The device picker; it reads the devices only while it's shown. */
|
|
52
|
+
function ToolbarPicker(props) {
|
|
53
|
+
const { location } = props;
|
|
54
|
+
const devices = (0, use_telemetry_1.useMonitoredDevices)();
|
|
55
|
+
return ((0, jsx_runtime_1.jsx)(device_picker_1.DevicePicker, { devices: devices, deviceId: location.deviceId, onChange: (deviceId) => (0, globals_1.mainContentPath)((0, monitoring_routes_1.monitoringPath)({ section: location.section, deviceId })) }));
|
|
56
|
+
}
|
|
57
|
+
(0, ui_loader_1.registerInternalPeersUI)({
|
|
58
|
+
component: MonitoringScreen,
|
|
59
|
+
routes: [
|
|
60
|
+
{
|
|
61
|
+
isMatch: (_props, context) => {
|
|
62
|
+
const path = context.path.split("?")[0].toLowerCase();
|
|
63
|
+
return (path === monitoring_routes_1.MONITORING_APP_PATH ||
|
|
64
|
+
path.startsWith(`${monitoring_routes_1.MONITORING_APP_PATH}/`) ||
|
|
65
|
+
path === monitoring_routes_1.LEGACY_CONSOLE_LOGS_PATH);
|
|
66
|
+
},
|
|
67
|
+
uiCategory: "screen",
|
|
68
|
+
priority: 3,
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { type IAlertEvent, type IAlertState, type IMetricQueryResult, type ITelemetryConsumer, type ITelemetryStatus } from "@peers-app/peers-sdk";
|
|
2
|
+
import type { MonitoringSectionProps } from "./monitoring-screen";
|
|
3
|
+
/** Metrics the Overview's tiles read. */
|
|
4
|
+
export declare const OVERVIEW_METRICS: {
|
|
5
|
+
readonly errors: "logs.errors";
|
|
6
|
+
readonly calls: "calls.duration";
|
|
7
|
+
readonly failedDials: "mesh.attempt.failures";
|
|
8
|
+
};
|
|
9
|
+
/** What the Overview reads, in one go. */
|
|
10
|
+
export interface IOverviewData {
|
|
11
|
+
errors?: IMetricQueryResult;
|
|
12
|
+
calls?: IMetricQueryResult;
|
|
13
|
+
failedDials?: IMetricQueryResult;
|
|
14
|
+
status?: ITelemetryStatus;
|
|
15
|
+
alerts?: {
|
|
16
|
+
triggers: IAlertState[];
|
|
17
|
+
events: IAlertEvent[];
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Read everything the Overview shows: the last 24 hours of errors, calls and failed dials by hour,
|
|
22
|
+
* telemetry's own status, and the alerts. The calls leave out Monitoring's own reads, which would
|
|
23
|
+
* otherwise set their p95. One part failing leaves the rest.
|
|
24
|
+
*
|
|
25
|
+
* @param telemetry - The device's System Telemetry.
|
|
26
|
+
* @param now - The current time (for tests).
|
|
27
|
+
*/
|
|
28
|
+
export declare function readOverview(telemetry: ITelemetryConsumer, now?: number): Promise<IOverviewData>;
|
|
29
|
+
/** The Overview's headline numbers, as its tiles and the All devices section show them. */
|
|
30
|
+
export interface IOverviewSummary {
|
|
31
|
+
/** Error lines in the last 24 hours; undefined when they couldn't be read. */
|
|
32
|
+
errors?: number;
|
|
33
|
+
/** Calls in the last 24 hours, and their p95 in ms. */
|
|
34
|
+
callCount?: number;
|
|
35
|
+
p95?: number;
|
|
36
|
+
/** Triggers firing or pending now (enabled ones); undefined when alerts couldn't be read. */
|
|
37
|
+
active?: IAlertState[];
|
|
38
|
+
/** The telemetry database's size on disk. */
|
|
39
|
+
databaseBytes?: number;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Work out the Overview's headline numbers from what {@link readOverview} read.
|
|
43
|
+
*
|
|
44
|
+
* @param data - The Overview's reads.
|
|
45
|
+
*/
|
|
46
|
+
export declare function summarizeOverview(data: IOverviewData): IOverviewSummary;
|
|
47
|
+
/**
|
|
48
|
+
* Overview: errors, call latency, failed dials and the telemetry database's size over the last 24
|
|
49
|
+
* hours, then what's firing and the latest alerts.
|
|
50
|
+
*/
|
|
51
|
+
export declare function OverviewTab(props: MonitoringSectionProps): import("react/jsx-runtime").JSX.Element;
|