annotate src/main.ts @ 5:9eaa993ed373

monitoring
author drewp@bigasterisk.com
date Sun, 15 Oct 2023 18:47:45 -0700
parents 4365c72c59f6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
drewp@bigasterisk.com
parents:
diff changeset
1 import { LitElement, TemplateResult, css, html } from "lit";
drewp@bigasterisk.com
parents:
diff changeset
2 import { customElement, property } from "lit/decorators.js";
drewp@bigasterisk.com
parents:
diff changeset
3 export { SgSource, SgView, StreamedGraph } from "@bigasterisk/streamed-graph";
5
9eaa993ed373 monitoring
drewp@bigasterisk.com
parents: 0
diff changeset
4 export { MetricRow } from "./MetricRow";
0
drewp@bigasterisk.com
parents:
diff changeset
5
drewp@bigasterisk.com
parents:
diff changeset
6 @customElement("fd-page")
drewp@bigasterisk.com
parents:
diff changeset
7 export class FdPage extends LitElement {
drewp@bigasterisk.com
parents:
diff changeset
8 static styles = [
drewp@bigasterisk.com
parents:
diff changeset
9 css`
drewp@bigasterisk.com
parents:
diff changeset
10 :host {
drewp@bigasterisk.com
parents:
diff changeset
11 display: flex;
drewp@bigasterisk.com
parents:
diff changeset
12 flex-direction: column;
drewp@bigasterisk.com
parents:
diff changeset
13 height: 100vh;
drewp@bigasterisk.com
parents:
diff changeset
14 }
drewp@bigasterisk.com
parents:
diff changeset
15 button {
drewp@bigasterisk.com
parents:
diff changeset
16 margin: 10px;
drewp@bigasterisk.com
parents:
diff changeset
17 padding: 20px;
drewp@bigasterisk.com
parents:
diff changeset
18 }
drewp@bigasterisk.com
parents:
diff changeset
19 `,
drewp@bigasterisk.com
parents:
diff changeset
20 ];
drewp@bigasterisk.com
parents:
diff changeset
21 @property() status: {} = { "loading...": "" };
drewp@bigasterisk.com
parents:
diff changeset
22 @property() lastCommand: {} = { command: "none" };
drewp@bigasterisk.com
parents:
diff changeset
23 connectedCallback(): void {
drewp@bigasterisk.com
parents:
diff changeset
24 super.connectedCallback();
drewp@bigasterisk.com
parents:
diff changeset
25 this.getStatus();
drewp@bigasterisk.com
parents:
diff changeset
26 }
drewp@bigasterisk.com
parents:
diff changeset
27
drewp@bigasterisk.com
parents:
diff changeset
28 async getStatus() {
drewp@bigasterisk.com
parents:
diff changeset
29 this.status = await (await fetch("api/status")).json();
drewp@bigasterisk.com
parents:
diff changeset
30 setTimeout(() => {
drewp@bigasterisk.com
parents:
diff changeset
31 requestAnimationFrame(() => {
drewp@bigasterisk.com
parents:
diff changeset
32 this.getStatus();
drewp@bigasterisk.com
parents:
diff changeset
33 });
drewp@bigasterisk.com
parents:
diff changeset
34 }, 1000);
drewp@bigasterisk.com
parents:
diff changeset
35 }
drewp@bigasterisk.com
parents:
diff changeset
36 render() {
drewp@bigasterisk.com
parents:
diff changeset
37 return html`
drewp@bigasterisk.com
parents:
diff changeset
38 <h1>Front door lock</h1>
drewp@bigasterisk.com
parents:
diff changeset
39
drewp@bigasterisk.com
parents:
diff changeset
40 <div>Status: ${JSON.stringify(this.status)} ${JSON.stringify(this.lastCommand)}</div>
drewp@bigasterisk.com
parents:
diff changeset
41 <div>
drewp@bigasterisk.com
parents:
diff changeset
42 <button @click=${() => this.simple("unlock")}>Unlock</button>
drewp@bigasterisk.com
parents:
diff changeset
43 <button @click=${() => this.simple("stayUnlocked")}>Unlock and stay unlocked</button>
drewp@bigasterisk.com
parents:
diff changeset
44 <button @click=${() => this.simple("lock")}>Lock</button>
drewp@bigasterisk.com
parents:
diff changeset
45 </div>
drewp@bigasterisk.com
parents:
diff changeset
46 <streamed-graph expanded="true">
drewp@bigasterisk.com
parents:
diff changeset
47 <sg-source url="./api/graph"></sg-source>
drewp@bigasterisk.com
parents:
diff changeset
48 <sg-source url="./view.n3"></sg-source>
drewp@bigasterisk.com
parents:
diff changeset
49 <sg-view uri="#view"></sg-view>
drewp@bigasterisk.com
parents:
diff changeset
50 </streamed-graph>
drewp@bigasterisk.com
parents:
diff changeset
51 <p>
5
9eaa993ed373 monitoring
drewp@bigasterisk.com
parents: 0
diff changeset
52 <a href="metrics">metrics</a> | <a href="api/graph">graph</a> |
9eaa993ed373 monitoring
drewp@bigasterisk.com
parents: 0
diff changeset
53 <a href="https://bigasterisk.com/k/clusters/local/namespaces/default/deployments/front-door-lock">deploy</a> |
9eaa993ed373 monitoring
drewp@bigasterisk.com
parents: 0
diff changeset
54 <a href="https://bigasterisk.com/k/clusters/local/namespaces/default/deployments/front-door-lock/logs">logs</a> |
9eaa993ed373 monitoring
drewp@bigasterisk.com
parents: 0
diff changeset
55 <a href="https://bigasterisk.com/vmalert/groups#group-14459482342649697182">alert group</a>
9eaa993ed373 monitoring
drewp@bigasterisk.com
parents: 0
diff changeset
56 </p>
9eaa993ed373 monitoring
drewp@bigasterisk.com
parents: 0
diff changeset
57 <p>
9eaa993ed373 monitoring
drewp@bigasterisk.com
parents: 0
diff changeset
58 <metric-row label="reader esp32: mqtt connected " q='hw_connected{job="fingerprint"}'></metric-row>
9eaa993ed373 monitoring
drewp@bigasterisk.com
parents: 0
diff changeset
59 <metric-row label="reader service: up " q='up{job="fingerprint"}'></metric-row>
9eaa993ed373 monitoring
drewp@bigasterisk.com
parents: 0
diff changeset
60 <metric-row label="reader service: mqtt connected" q='mqtt_connected{job="fingerprint"}'></metric-row>
9eaa993ed373 monitoring
drewp@bigasterisk.com
parents: 0
diff changeset
61 <metric-row label="Lock service (this page): up " q='up{job="front-door-lock"}'></metric-row>
9eaa993ed373 monitoring
drewp@bigasterisk.com
parents: 0
diff changeset
62 <metric-row label="Lock service: mqtt connected " q='mqtt_connected{job="front-door-lock"}'></metric-row>
9eaa993ed373 monitoring
drewp@bigasterisk.com
parents: 0
diff changeset
63 <metric-row label="Lock esp32: mqtt-connected " q='hw_connected{job="front-door-lock"}'></metric-row>
0
drewp@bigasterisk.com
parents:
diff changeset
64 </p>
drewp@bigasterisk.com
parents:
diff changeset
65 <bigast-loginbar></bigast-loginbar>
drewp@bigasterisk.com
parents:
diff changeset
66 `;
drewp@bigasterisk.com
parents:
diff changeset
67 }
drewp@bigasterisk.com
parents:
diff changeset
68 async simple(command: string) {
drewp@bigasterisk.com
parents:
diff changeset
69 const t1 = Date.now();
drewp@bigasterisk.com
parents:
diff changeset
70 this.lastCommand = { command: command, sentAt: t1 };
drewp@bigasterisk.com
parents:
diff changeset
71 var status;
drewp@bigasterisk.com
parents:
diff changeset
72 try {
drewp@bigasterisk.com
parents:
diff changeset
73 const resp = await fetch(`api/simple/${command}`, { method: "PUT" });
drewp@bigasterisk.com
parents:
diff changeset
74 status = resp.status;
drewp@bigasterisk.com
parents:
diff changeset
75 } catch (e) {
drewp@bigasterisk.com
parents:
diff changeset
76 status = "" + e;
drewp@bigasterisk.com
parents:
diff changeset
77 }
drewp@bigasterisk.com
parents:
diff changeset
78 const t2 = Date.now();
drewp@bigasterisk.com
parents:
diff changeset
79 this.lastCommand = { command: command, sentAt: t1, tookMs: t2 - t1, status: status };
drewp@bigasterisk.com
parents:
diff changeset
80 }
drewp@bigasterisk.com
parents:
diff changeset
81 }