changeset 2375:623836db99af

fix ts warning
author drewp@bigasterisk.com
date Thu, 08 Jun 2023 15:05:59 -0700
parents 9d47c44d4ae4
children 4556eebe5d73
files light9/web/lib/parse-prometheus-text-format.d.ts light9/web/metrics/StatsLine.ts
diffstat 2 files changed, 20 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/light9/web/lib/parse-prometheus-text-format.d.ts	Thu Jun 08 15:05:59 2023 -0700
@@ -0,0 +1,4 @@
+declare module "parse-prometheus-text-format" {
+  function parsePrometheusTextFormat(s: string): any;
+  export default parsePrometheusTextFormat;
+}
--- a/light9/web/metrics/StatsLine.ts	Thu Jun 08 14:54:26 2023 -0700
+++ b/light9/web/metrics/StatsLine.ts	Thu Jun 08 15:05:59 2023 -0700
@@ -48,7 +48,7 @@
     changedProperties.forEach((oldValue: any, propName: string) => {
       if (propName == "name") {
         const reload = () => {
-          fetch("/service/"+this.name + "/metrics").then((resp) => {
+          fetch("/service/" + this.name + "/metrics").then((resp) => {
             if (resp.ok) {
               resp
                 .text()
@@ -58,7 +58,7 @@
                   setTimeout(reload, 1000);
                 })
                 .catch((err) => {
-                  log(`${this.name} failing`, err)
+                  log(`${this.name} failing`, err);
                   setTimeout(reload, 1000);
                 });
             } else {
@@ -195,7 +195,6 @@
     return html`[NEW ${JSON.stringify(d)} ${path}]`;
   }
 
-
   valueDisplay(m: Metric, v: Value): TemplateResult {
     if (m.type == "GAUGE") {
       return html`${v.value}`;
@@ -249,22 +248,18 @@
   }
 
   tightLabel(labs: { [key: string]: string }): string {
-    const d: { [key: string]: string } = {}
+    const d: { [key: string]: string } = {};
     for (let k in labs) {
-      if (k == 'app_name') continue;
-      if (k == 'output') continue;
-      if (k=='status_code'&&labs[k]=="200") continue;
-      d[k] = labs[k]
+      if (k == "app_name") continue;
+      if (k == "output") continue;
+      if (k == "status_code" && labs[k] == "200") continue;
+      d[k] = labs[k];
     }
-    const ret = JSON.stringify(d)
-    return ret == "{}" ? "" : ret
+    const ret = JSON.stringify(d);
+    return ret == "{}" ? "" : ret;
   }
   tightMetric(name: string): string {
-    return name
-    .replace('starlette', '⭐')
-    .replace("_request" ,"_req")
-    .replace("_duration" ,"_dur")
-    .replace('_seconds', '_s')
+    return name.replace("starlette", "⭐").replace("_request", "_req").replace("_duration", "_dur").replace("_seconds", "_s");
   }
   render() {
     const now = Date.now() / 1000;
@@ -274,31 +269,31 @@
       <div>
         <table>
           ${displayedStats.map(
-      (row, rowNum) => html`
+            (row, rowNum) => html`
               <tr>
                 <th>${this.tightMetric(row.name)}</th>
                 <td>
                   <table>
                     ${row.metrics.map(
-        (v) => html`
+                      (v) => html`
                         <tr>
                           <td>${this.tightLabel(v.labels)}</td>
                           <td>${this.valueDisplay(row, v)}</td>
                         </tr>
                       `
-      )}
+                    )}
                   </table>
                 </td>
                 ${rowNum == 0
-          ? html`
+                  ? html`
                       <td rowspan="${displayedStats.length}">
                         <stats-process id="proc" cpu="${this.cpu}" mem="${this.mem}"></stats-process>
                       </td>
                     `
-          : ""}
+                  : ""}
               </tr>
             `
-    )}
+          )}
         </table>
       </div>
     `;