Skip to content

Commit 383b585

Browse files
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 <[email protected]> * chore(price_pusher): bump version to 10.1.0 for new gauge metrics feature Co-Authored-By: Ali <[email protected]> * chore: update readme example command * docs(price_pusher): add documentation for new price value gauge metrics Co-Authored-By: Ali <[email protected]> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Ali <[email protected]> Co-authored-by: Ali Behjati <[email protected]>
1 parent 08f2c37 commit 383b585

File tree

4 files changed

+75
-4
lines changed

4 files changed

+75
-4
lines changed

apps/price_pusher/README.md

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,12 @@ and the on-chain Pyth contract and deciding whether to push a new price. You can
211211

212212
### Example
213213

214-
For example, to push `BTC/USD` and `BNB/USD` prices on Fantom testnet, run the following command:
214+
For example, to push `BTC/USD` and `BNB/USD` prices on Sonic blaze testnet, run the following command:
215215

216216
```sh
217217
pnpm run dev evm \
218-
--endpoint https://endpoints.omniatech.io/v1/fantom/testnet/public \
219-
--pyth-contract-address 0x5744Cbf430D99456a0A8771208b674F27f8EF0Fb \
218+
--endpoint https://rpc.blaze.soniclabs.com \
219+
--pyth-contract-address 0x2880aB155794e7179c9eE2e38200202908C17B43 \
220220
--price-service-endpoint https://hermes.pyth.network \
221221
--mnemonic-file "./mnemonic" \
222222
--price-config-file "./price-config.stable.sample.yaml" \
@@ -272,6 +272,8 @@ The following metrics are available:
272272
- **pyth_price_last_published_time** (Gauge): The last published time of a price feed in unix timestamp, labeled by price_id and alias
273273
- **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
274274
- **pyth_price_feeds_total** (Gauge): Total number of price feeds being monitored
275+
- **pyth_source_price** (Gauge): Latest price value from Pyth source, labeled by price_id and alias
276+
- **pyth_target_price** (Gauge): Latest price value from target chain, labeled by price_id and alias
275277
- **pyth_wallet_balance** (Gauge): Current wallet balance of the price pusher in native token units, labeled by wallet_address and network
276278

277279
### Configuration
@@ -343,6 +345,30 @@ pyth_wallet_balance
343345
pyth_wallet_balance < 0.1
344346
```
345347

348+
7. Monitor current source price values:
349+
350+
```
351+
pyth_source_price
352+
```
353+
354+
8. Monitor current target price values:
355+
356+
```
357+
pyth_target_price
358+
```
359+
360+
9. Compare source vs target price differences:
361+
362+
```
363+
abs(pyth_source_price - pyth_target_price) / pyth_source_price * 100
364+
```
365+
366+
10. Detect significant price deviations (>1%):
367+
368+
```
369+
abs(pyth_source_price - pyth_target_price) / pyth_source_price * 100 > 1
370+
```
371+
346372
### Dashboard
347373

348374
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
353379
- **Price Feeds List**: A table listing all configured price feeds with their details.
354380
- **Successful Updates (Current Range)**: Graph showing the number of successful price updates over the current range with timeline.
355381
- **Update Conditions Distribution**: Pie chart showing the distribution of update conditions (YES/NO/EARLY) over the selected time range.
382+
- **Source vs Target Price Values**: Graphs showing current price values from both Pyth source and target chains for comparison.
383+
- **Price Deviation Monitoring**: Panels to track price differences between source and target chains.
356384
- **Wallet Balance**: Current balance of your wallet in native token units.
357385
- **Wallet Balance Over Time**: Graph tracking your wallet balance over time to monitor consumption.
358386
- **Failed Updates (Current Range)**: Graph showing the number of failed price updates over the current range with timeline.

apps/price_pusher/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pythnetwork/price-pusher",
3-
"version": "10.0.0",
3+
"version": "10.1.0",
44
"description": "Pyth Price Pusher",
55
"homepage": "https://pyth.network",
66
"main": "lib/index.js",

apps/price_pusher/src/controller.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ export class Controller {
6161
sourceLatestPrice.publishTime,
6262
priceConfig.timeDifference,
6363
);
64+
this.metrics.updatePriceValues(
65+
priceId,
66+
alias,
67+
sourceLatestPrice.price,
68+
targetLatestPrice.price,
69+
);
6470
}
6571

6672
const priceShouldUpdate = shouldUpdate(

apps/price_pusher/src/metrics.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export class PricePusherMetrics {
1515
public priceFeedsTotal: Gauge<string>;
1616
public sourceTimestamp: Gauge<string>;
1717
public configuredTimeDifference: Gauge<string>;
18+
public sourcePriceValue: Gauge<string>;
19+
public targetPriceValue: Gauge<string>;
1820
// Wallet metrics
1921
public walletBalance: Gauge<string>;
2022

@@ -61,6 +63,20 @@ export class PricePusherMetrics {
6163
registers: [this.registry],
6264
});
6365

66+
this.sourcePriceValue = new Gauge({
67+
name: "pyth_source_price",
68+
help: "Latest price value from Pyth source",
69+
labelNames: ["price_id", "alias"],
70+
registers: [this.registry],
71+
});
72+
73+
this.targetPriceValue = new Gauge({
74+
name: "pyth_target_price",
75+
help: "Latest price value from target chain",
76+
labelNames: ["price_id", "alias"],
77+
registers: [this.registry],
78+
});
79+
6480
// Wallet balance metric
6581
this.walletBalance = new Gauge({
6682
name: "pyth_wallet_balance",
@@ -158,6 +174,27 @@ export class PricePusherMetrics {
158174
);
159175
}
160176

177+
// Update price values
178+
public updatePriceValues(
179+
priceId: string,
180+
alias: string,
181+
sourcePrice: string | undefined,
182+
targetPrice: string | undefined,
183+
): void {
184+
if (sourcePrice !== undefined) {
185+
this.sourcePriceValue.set(
186+
{ price_id: priceId, alias },
187+
Number(sourcePrice),
188+
);
189+
}
190+
if (targetPrice !== undefined) {
191+
this.targetPriceValue.set(
192+
{ price_id: priceId, alias },
193+
Number(targetPrice),
194+
);
195+
}
196+
}
197+
161198
// Update wallet balance
162199
public updateWalletBalance(
163200
walletAddress: string,

0 commit comments

Comments
 (0)