ソースを参照

feat(price_pusher): add gauge metrics for source and target price values (#3008)

* feat(price_pusher): add gauge metrics for source and target price values

- Add pyth_source_price and pyth_target_price gauge metrics to track latest price values
- Update controller to set price value metrics alongside existing timestamp metrics
- Use consistent labeling with price_id and alias for metric identification
- Convert string prices to numbers for Prometheus gauge compatibility

Co-Authored-By: Ali <ali@dourolabs.xyz>

* chore(price_pusher): bump version to 10.1.0 for new gauge metrics feature

Co-Authored-By: Ali <ali@dourolabs.xyz>

* chore: update readme example command

* docs(price_pusher): add documentation for new price value gauge metrics

Co-Authored-By: Ali <ali@dourolabs.xyz>

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Ali <ali@dourolabs.xyz>
Co-authored-by: Ali Behjati <bahjatia@gmail.com>
devin-ai-integration[bot] 2 ヶ月 前
コミット
383b585f53

+ 31 - 3
apps/price_pusher/README.md

@@ -211,12 +211,12 @@ and the on-chain Pyth contract and deciding whether to push a new price. You can
 
 ### Example
 
-For example, to push `BTC/USD` and `BNB/USD` prices on Fantom testnet, run the following command:
+For example, to push `BTC/USD` and `BNB/USD` prices on Sonic blaze testnet, run the following command:
 
 ```sh
 pnpm run dev evm \
-  --endpoint https://endpoints.omniatech.io/v1/fantom/testnet/public \
-  --pyth-contract-address 0x5744Cbf430D99456a0A8771208b674F27f8EF0Fb \
+  --endpoint https://rpc.blaze.soniclabs.com \
+  --pyth-contract-address 0x2880aB155794e7179c9eE2e38200202908C17B43 \
   --price-service-endpoint https://hermes.pyth.network \
   --mnemonic-file "./mnemonic" \
   --price-config-file "./price-config.stable.sample.yaml" \
@@ -272,6 +272,8 @@ The following metrics are available:
 - **pyth_price_last_published_time** (Gauge): The last published time of a price feed in unix timestamp, labeled by price_id and alias
 - **pyth_price_update_attempts_total** (Counter): Total number of price update attempts with their trigger condition and status, labeled by price_id, alias, trigger, and status
 - **pyth_price_feeds_total** (Gauge): Total number of price feeds being monitored
+- **pyth_source_price** (Gauge): Latest price value from Pyth source, labeled by price_id and alias
+- **pyth_target_price** (Gauge): Latest price value from target chain, labeled by price_id and alias
 - **pyth_wallet_balance** (Gauge): Current wallet balance of the price pusher in native token units, labeled by wallet_address and network
 
 ### Configuration
@@ -343,6 +345,30 @@ pyth_wallet_balance
 pyth_wallet_balance < 0.1
 ```
 
+7. Monitor current source price values:
+
+```
+pyth_source_price
+```
+
+8. Monitor current target price values:
+
+```
+pyth_target_price
+```
+
+9. Compare source vs target price differences:
+
+```
+abs(pyth_source_price - pyth_target_price) / pyth_source_price * 100
+```
+
+10. Detect significant price deviations (>1%):
+
+```
+abs(pyth_source_price - pyth_target_price) / pyth_source_price * 100 > 1
+```
+
 ### Dashboard
 
 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:
@@ -353,6 +379,8 @@ The docker-compose setup includes a pre-configured Grafana dashboard (`grafana-d
 - **Price Feeds List**: A table listing all configured price feeds with their details.
 - **Successful Updates (Current Range)**: Graph showing the number of successful price updates over the current range with timeline.
 - **Update Conditions Distribution**: Pie chart showing the distribution of update conditions (YES/NO/EARLY) over the selected time range.
+- **Source vs Target Price Values**: Graphs showing current price values from both Pyth source and target chains for comparison.
+- **Price Deviation Monitoring**: Panels to track price differences between source and target chains.
 - **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.
 - **Failed Updates (Current Range)**: Graph showing the number of failed price updates over the current range with timeline.

+ 1 - 1
apps/price_pusher/package.json

@@ -1,6 +1,6 @@
 {
   "name": "@pythnetwork/price-pusher",
-  "version": "10.0.0",
+  "version": "10.1.0",
   "description": "Pyth Price Pusher",
   "homepage": "https://pyth.network",
   "main": "lib/index.js",

+ 6 - 0
apps/price_pusher/src/controller.ts

@@ -61,6 +61,12 @@ export class Controller {
             sourceLatestPrice.publishTime,
             priceConfig.timeDifference,
           );
+          this.metrics.updatePriceValues(
+            priceId,
+            alias,
+            sourceLatestPrice.price,
+            targetLatestPrice.price,
+          );
         }
 
         const priceShouldUpdate = shouldUpdate(

+ 37 - 0
apps/price_pusher/src/metrics.ts

@@ -15,6 +15,8 @@ export class PricePusherMetrics {
   public priceFeedsTotal: Gauge<string>;
   public sourceTimestamp: Gauge<string>;
   public configuredTimeDifference: Gauge<string>;
+  public sourcePriceValue: Gauge<string>;
+  public targetPriceValue: Gauge<string>;
   // Wallet metrics
   public walletBalance: Gauge<string>;
 
@@ -61,6 +63,20 @@ export class PricePusherMetrics {
       registers: [this.registry],
     });
 
+    this.sourcePriceValue = new Gauge({
+      name: "pyth_source_price",
+      help: "Latest price value from Pyth source",
+      labelNames: ["price_id", "alias"],
+      registers: [this.registry],
+    });
+
+    this.targetPriceValue = new Gauge({
+      name: "pyth_target_price",
+      help: "Latest price value from target chain",
+      labelNames: ["price_id", "alias"],
+      registers: [this.registry],
+    });
+
     // Wallet balance metric
     this.walletBalance = new Gauge({
       name: "pyth_wallet_balance",
@@ -158,6 +174,27 @@ export class PricePusherMetrics {
     );
   }
 
+  // Update price values
+  public updatePriceValues(
+    priceId: string,
+    alias: string,
+    sourcePrice: string | undefined,
+    targetPrice: string | undefined,
+  ): void {
+    if (sourcePrice !== undefined) {
+      this.sourcePriceValue.set(
+        { price_id: priceId, alias },
+        Number(sourcePrice),
+      );
+    }
+    if (targetPrice !== undefined) {
+      this.targetPriceValue.set(
+        { price_id: priceId, alias },
+        Number(targetPrice),
+      );
+    }
+  }
+
   // Update wallet balance
   public updateWalletBalance(
     walletAddress: string,