Skip to content

Commit f446942

Browse files
committed
feat(metrics): add price update delay metric and update method
1 parent 3e39dda commit f446942

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

apps/price_pusher/src/controller.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ export class Controller {
6262
);
6363
}
6464

65+
if (this.metrics && targetLatestPrice && sourceLatestPrice) {
66+
this.metrics.updatePriceDelay(
67+
priceId,
68+
alias,
69+
targetLatestPrice.publishTime,
70+
sourceLatestPrice.publishTime,
71+
priceConfig.timeDifference,
72+
);
73+
}
74+
6575
const priceShouldUpdate = shouldUpdate(
6676
priceConfig,
6777
sourceLatestPrice,

apps/price_pusher/src/metrics.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export class PricePusherMetrics {
1414
public lastPublishedTime: Gauge<string>;
1515
public priceUpdateAttempts: Counter<string>;
1616
public priceFeedsTotal: Gauge<string>;
17+
public priceUpdateDelay: Gauge<string>;
1718
// Wallet metrics
1819
public walletBalance: Gauge<string>;
1920

@@ -46,6 +47,13 @@ export class PricePusherMetrics {
4647
registers: [this.registry],
4748
});
4849

50+
this.priceUpdateDelay = new Gauge({
51+
name: "pyth_price_update_delay",
52+
help: "Delay between source and target timestamps relative to configured threshold (positive means over threshold)",
53+
labelNames: ["price_id", "alias"],
54+
registers: [this.registry],
55+
});
56+
4957
// Wallet balance metric
5058
this.walletBalance = new Gauge({
5159
name: "pyth_wallet_balance",
@@ -133,6 +141,20 @@ export class PricePusherMetrics {
133141
this.priceFeedsTotal.set(count);
134142
}
135143

144+
// Update price delay relative to threshold
145+
public updatePriceDelay(
146+
priceId: string,
147+
alias: string,
148+
targetLatestPricePublishTime: number,
149+
sourceLatestPricePublishTime: number,
150+
priceConfigTimeDifference: number,
151+
): void {
152+
this.priceUpdateDelay.set(
153+
{ price_id: priceId, alias },
154+
sourceLatestPricePublishTime - targetLatestPricePublishTime - priceConfigTimeDifference
155+
);
156+
}
157+
136158
// Update wallet balance
137159
public updateWalletBalance(
138160
walletAddress: string,

0 commit comments

Comments
 (0)