Просмотр исходного кода

feat: add update conditions tracking and update related metrics in README and dashboard

Daniel Chew 8 месяцев назад
Родитель
Сommit
62cb38c6b7

+ 5 - 5
apps/price_pusher/README.md

@@ -270,10 +270,9 @@ The following metrics are available:
 
 - **pyth_price_last_published_time** (Gauge): The last published time of a price feed in unix timestamp
 - **pyth_price_updates_total** (Counter): Total number of price updates pushed to the chain
-- **pyth_price_update_duration_seconds** (Histogram): Duration of price update operations in seconds
 - **pyth_price_feeds_total** (Gauge): Total number of price feeds being monitored
 - **pyth_price_update_errors_total** (Counter): Total number of errors encountered during price updates
-- **pyth_price_update_attempts_total** (Counter): Total number of price update attempts
+- **pyth_update_conditions_total** (Counter): Count of update condition checks by status (YES/NO/EARLY)
 - **pyth_wallet_balance** (Gauge): Current wallet balance of the price pusher in native token units
 
 ### Configuration
@@ -358,10 +357,10 @@ sum(increase(pyth_price_updates_total[1h]))
 time() - pyth_price_last_published_time > 3600
 ```
 
-4. Average update duration:
+4. Distribution of update conditions:
 
 ```
-rate(pyth_price_update_duration_seconds_sum[5m]) / rate(pyth_price_update_duration_seconds_count[5m])
+sum by (condition) (increase(pyth_update_conditions_total[$__range]))
 ```
 
 5. Monitor wallet balances:
@@ -378,13 +377,14 @@ pyth_wallet_balance < 0.1
 
 ### Dashboard
 
-The docker-compose setup includes a pre-configured Grafana dashboard (`grafana-dashboard.sample.json`) that provides monitoring of your price pusher operations. Based on the screenshot, the dashboard includes the following panels:
+The docker-compose setup includes a pre-configured Grafana dashboard (`grafana-dashboard.sample.json`) that provides monitoring of your price pusher operations. The dashboard includes the following panels:
 
 - **Configured Price Feeds**: Shows the number of price feeds configured in your price-config file.
 - **Active Price Feeds**: Displays the number of price feeds currently being actively monitored.
 - **Time Since Last Update**: Shows how long it's been since the last successful price update was published on-chain.
 - **Price Feeds List**: A table listing all configured price feeds with their details.
 - **Price Updates (Last Hour)**: Graph showing the number of price updates over the last hour with timeline.
+- **Update Conditions Distribution**: Pie chart showing the distribution of update conditions (YES/NO/EARLY) over the selected time range.
 - **Wallet Balance**: Current balance of your wallet in native token units.
 - **Wallet Balance Over Time**: Graph tracking your wallet balance over time to monitor consumption.
 - **Update Errors**: Tracks errors encountered during price update operations.

+ 123 - 3
apps/price_pusher/grafana-dashboard.sample.json

@@ -529,6 +529,126 @@
       "title": "Price Updates (Last Hour)",
       "type": "timeseries"
     },
+    {
+      "datasource": {
+        "type": "prometheus",
+        "uid": "prometheus"
+      },
+      "fieldConfig": {
+        "defaults": {
+          "color": {
+            "mode": "palette-classic"
+          },
+          "custom": {
+            "hideFrom": {
+              "legend": false,
+              "tooltip": false,
+              "viz": false
+            }
+          },
+          "mappings": []
+        },
+        "overrides": [
+          {
+            "matcher": {
+              "id": "byName",
+              "options": "YES"
+            },
+            "properties": [
+              {
+                "id": "color",
+                "value": {
+                  "fixedColor": "green",
+                  "mode": "fixed"
+                }
+              }
+            ]
+          },
+          {
+            "matcher": {
+              "id": "byName",
+              "options": "NO"
+            },
+            "properties": [
+              {
+                "id": "color",
+                "value": {
+                  "fixedColor": "red",
+                  "mode": "fixed"
+                }
+              }
+            ]
+          },
+          {
+            "matcher": {
+              "id": "byName",
+              "options": "EARLY"
+            },
+            "properties": [
+              {
+                "id": "color",
+                "value": {
+                  "fixedColor": "yellow",
+                  "mode": "fixed"
+                }
+              }
+            ]
+          }
+        ]
+      },
+      "gridPos": {
+        "h": 8,
+        "w": 6,
+        "x": 0,
+        "y": 16
+      },
+      "id": 13,
+      "options": {
+        "displayLabels": [
+          "percent",
+          "name"
+        ],
+        "legend": {
+          "displayMode": "list",
+          "placement": "right",
+          "showLegend": true,
+          "values": [
+            "value",
+            "percent"
+          ]
+        },
+        "pieType": "pie",
+        "reduceOptions": {
+          "calcs": [
+            "sum"
+          ],
+          "fields": "",
+          "values": false
+        },
+        "tooltip": {
+          "hideZeros": false,
+          "mode": "single",
+          "sort": "none"
+        }
+      },
+      "pluginVersion": "11.5.2",
+      "targets": [
+        {
+          "datasource": {
+            "type": "prometheus",
+            "uid": "prometheus"
+          },
+          "editorMode": "code",
+          "expr": "sum by (condition) (increase(pyth_update_conditions_total[$__range]))",
+          "instant": false,
+          "legendFormat": "{{condition}}",
+          "range": true,
+          "refId": "A"
+        }
+      ],
+      "title": "Update Conditions Distribution (Current Range)",
+      "type": "piechart"
+    },
     {
       "datasource": {
         "type": "prometheus",
@@ -563,8 +683,8 @@
       },
       "gridPos": {
         "h": 8,
-        "w": 12,
-        "x": 0,
+        "w": 6,
+        "x": 6,
         "y": 16
       },
       "id": 10,
@@ -808,6 +928,6 @@
   "timezone": "",
   "title": "Pyth Price Pusher Dashboard",
   "uid": "pyth-price-pusher",
-  "version": 41,
+  "version": 44,
   "weekStart": ""
 }

+ 5 - 7
apps/price_pusher/src/controller.ts

@@ -9,7 +9,7 @@ import { SuperWalletClient } from "./evm/super-wallet";
 // Define the wallet balance info interface
 interface WalletBalanceInfo {
   client: SuperWalletClient;
-  address: string;
+  address: `0x${string}`;
   network: string;
   updateInterval: DurationInSeconds;
 }
@@ -36,9 +36,7 @@ export class Controller {
     this.walletBalanceInfo = config.walletBalanceInfo;
 
     // Set the number of price feeds if metrics are enabled
-    if (this.metrics) {
-      this.metrics.setPriceFeedsTotal(this.priceConfigs.length);
-    }
+    this.metrics?.setPriceFeedsTotal(this.priceConfigs.length);
   }
 
   // Get wallet balance and update metrics
@@ -48,7 +46,7 @@ export class Controller {
     try {
       const { client, address, network } = this.walletBalanceInfo;
       const balance = await client.getBalance({
-        address: address as `0x${string}`,
+        address: address,
       });
 
       this.metrics.updateWalletBalance(address, network, balance);
@@ -112,9 +110,9 @@ export class Controller {
           this.logger,
         );
 
-        // Record price update attempt in metrics
+        // Record update condition in metrics
         if (this.metrics) {
-          this.metrics.recordPriceUpdateAttempt(priceId, alias);
+          this.metrics.recordUpdateCondition(priceId, alias, priceShouldUpdate);
         }
 
         if (priceShouldUpdate == UpdateCondition.YES) {

+ 18 - 8
apps/price_pusher/src/metrics.ts

@@ -2,6 +2,7 @@ import { Registry, Counter, Gauge } from "prom-client";
 import express from "express";
 import { PriceInfo } from "./interface";
 import { Logger } from "pino";
+import { UpdateCondition } from "./price-config";
 
 // Define the metrics we want to track
 export class PricePusherMetrics {
@@ -14,7 +15,7 @@ export class PricePusherMetrics {
   public priceUpdatesTotal: Counter<string>;
   public priceFeedsTotal: Gauge<string>;
   public priceUpdateErrors: Counter<string>;
-  public priceUpdateAttempts: Counter<string>;
+  public updateConditionsTotal: Counter<string>;
   // Wallet metrics
   public walletBalance: Gauge<string>;
 
@@ -54,10 +55,10 @@ export class PricePusherMetrics {
       registers: [this.registry],
     });
 
-    this.priceUpdateAttempts = new Counter({
-      name: "pyth_price_update_attempts_total",
-      help: "Total number of price update attempts",
-      labelNames: ["price_id", "alias"],
+    this.updateConditionsTotal = new Counter({
+      name: "pyth_update_conditions_total",
+      help: "Total number of price update condition checks by status (YES/NO/EARLY)",
+      labelNames: ["price_id", "alias", "condition"],
       registers: [this.registry],
     });
 
@@ -100,9 +101,18 @@ export class PricePusherMetrics {
     this.priceUpdatesTotal.inc({ price_id: priceId, alias });
   }
 
-  // Record a price update attempt
-  public recordPriceUpdateAttempt(priceId: string, alias: string): void {
-    this.priceUpdateAttempts.inc({ price_id: priceId, alias });
+  // Record update condition status (YES/NO/EARLY)
+  public recordUpdateCondition(
+    priceId: string,
+    alias: string,
+    condition: UpdateCondition,
+  ): void {
+    const conditionLabel = UpdateCondition[condition];
+    this.updateConditionsTotal.inc({
+      price_id: priceId,
+      alias,
+      condition: conditionLabel,
+    });
   }
 
   // Record a price update error