Skip to content

Commit 03ffd16

Browse files
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]>
1 parent 46184e0 commit 03ffd16

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

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)