Skip to content

Commit 528aae2

Browse files
committed
add prom metrics
1 parent 3127036 commit 528aae2

File tree

12 files changed

+1226
-45
lines changed

12 files changed

+1226
-45
lines changed

apps/price_pusher/README.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,91 @@ pushed twice and you won't pay additional costs most of the time.** However, the
259259
conditions in the RPCs because they are often behind a load balancer which can sometimes cause rejected
260260
transactions to land on-chain. You can reduce the chances of additional cost overhead by reducing the
261261
pushing frequency.
262+
263+
## Prometheus Metrics
264+
265+
The price_pusher now supports Prometheus metrics to monitor the health and performance of the price update service. Metrics are exposed via an HTTP endpoint that can be scraped by Prometheus.
266+
267+
### Available Metrics
268+
269+
The following metrics are available:
270+
271+
- **pyth_price_last_published_time**: The last published time of a price feed in unix timestamp
272+
- **pyth_price_updates_total**: Total number of price updates pushed to the chain
273+
- **pyth_price_update_duration_seconds**: Duration of price update operations in seconds
274+
- **pyth_active_price_feeds**: Number of active price feeds being monitored
275+
- **pyth_price_update_errors_total**: Total number of errors encountered during price updates
276+
- **pyth_price_update_attempts_total**: Total number of price update attempts
277+
278+
### Configuration
279+
280+
Metrics are enabled by default and can be configured using the following command-line options:
281+
282+
- `--enable-metrics`: Enable or disable the Prometheus metrics server (default: true)
283+
- `--metrics-port`: Port for the Prometheus metrics server (default: 9090)
284+
285+
Example:
286+
287+
```bash
288+
node lib/index.js evm --config config.evm.mainnet.json --metrics-port 9091
289+
```
290+
291+
### Running Locally with Docker
292+
293+
You can run a local Prometheus instance to test the metrics:
294+
295+
1. Create a `prometheus.yml` file:
296+
297+
```yaml
298+
global:
299+
scrape_interval: 15s
300+
301+
scrape_configs:
302+
- job_name: "price_pusher"
303+
static_configs:
304+
- targets: ["localhost:9090"]
305+
```
306+
307+
2. Run Prometheus with Docker:
308+
309+
```bash
310+
docker run -d --name prometheus -p 9090:9090 \
311+
-v $(pwd)/prometheus.yml:/etc/prometheus/prometheus.yml \
312+
prom/prometheus
313+
```
314+
315+
3. Run Grafana with Docker:
316+
317+
```bash
318+
docker run -d --name grafana -p 3000:3000 grafana/grafana
319+
```
320+
321+
4. Access Grafana at http://localhost:3000 (default credentials: admin/admin) and add Prometheus as a data source (URL: http://host.docker.internal:9090).
322+
323+
### Example Grafana Queries
324+
325+
Here are some example Grafana queries to monitor your price feeds:
326+
327+
1. Last published time for each price feed:
328+
329+
```
330+
pyth_price_last_published_time
331+
```
332+
333+
2. Number of price updates in the last hour:
334+
335+
```
336+
sum(increase(pyth_price_updates_total[1h]))
337+
```
338+
339+
3. Price feeds not updated in the last hour:
340+
341+
```
342+
time() - pyth_price_last_published_time > 3600
343+
```
344+
345+
4. Average update duration:
346+
347+
```
348+
rate(pyth_price_update_duration_seconds_sum[5m]) / rate(pyth_price_update_duration_seconds_count[5m])
349+
```

apps/price_pusher/alerts.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
groups:
2+
- name: price_pusher_alerts
3+
rules:
4+
- alert: PriceFeedNotUpdated
5+
expr: time() - pyth_price_last_published_time > 3600
6+
for: 5m
7+
labels:
8+
severity: warning
9+
annotations:
10+
summary: "Price feed not updated"
11+
description: "Price feed {{ $labels.alias }} has not been updated for more than 1 hour"
12+
13+
- alert: HighErrorRate
14+
expr: sum(increase(pyth_price_update_errors_total[15m])) > 5
15+
for: 5m
16+
labels:
17+
severity: warning
18+
annotations:
19+
summary: "High error rate in price updates"
20+
description: "There have been more than 5 errors in the last 15 minutes"
21+
22+
- alert: NoRecentPriceUpdates
23+
expr: sum(increase(pyth_price_updates_total[30m])) == 0
24+
for: 5m
25+
labels:
26+
severity: critical
27+
annotations:
28+
summary: "No recent price updates"
29+
description: "No price updates have been pushed in the last 30 minutes"
30+
31+
- alert: PricePusherDown
32+
expr: up{job=~"price_pusher.*"} == 0
33+
for: 1m
34+
labels:
35+
severity: critical
36+
annotations:
37+
summary: "Price pusher service is down"
38+
description: "The price pusher service {{ $labels.instance }} is down"
39+
40+
- alert: HighUpdateDuration
41+
expr: rate(pyth_price_update_duration_seconds_sum[5m]) / rate(pyth_price_update_duration_seconds_count[5m]) > 5
42+
for: 5m
43+
labels:
44+
severity: warning
45+
annotations:
46+
summary: "High update duration"
47+
description: "Price updates are taking longer than 5 seconds on average"
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
version: "3"
2+
3+
services:
4+
prometheus:
5+
image: prom/prometheus:latest
6+
container_name: prometheus
7+
ports:
8+
- "9090:9090"
9+
volumes:
10+
- ./prometheus.yml:/etc/prometheus/prometheus.yml
11+
- ./alerts.yml:/etc/prometheus/alerts.yml
12+
command:
13+
- "--config.file=/etc/prometheus/prometheus.yml"
14+
- "--storage.tsdb.path=/prometheus"
15+
- "--web.console.libraries=/usr/share/prometheus/console_libraries"
16+
- "--web.console.templates=/usr/share/prometheus/consoles"
17+
networks:
18+
- monitoring
19+
20+
grafana:
21+
image: grafana/grafana:latest
22+
container_name: grafana
23+
ports:
24+
- "3000:3000"
25+
volumes:
26+
- grafana-storage:/var/lib/grafana
27+
environment:
28+
- GF_SECURITY_ADMIN_USER=admin
29+
- GF_SECURITY_ADMIN_PASSWORD=admin
30+
- GF_USERS_ALLOW_SIGN_UP=false
31+
depends_on:
32+
- prometheus
33+
networks:
34+
- monitoring
35+
36+
# Example price_pusher service for Ethereum
37+
# price_pusher_ethereum:
38+
# image: your-price-pusher-image:latest
39+
# container_name: price_pusher_ethereum
40+
# volumes:
41+
# - ./config.evm.mainnet.json:/app/config.json
42+
# - ./mnemonic:/app/mnemonic
43+
# command: >
44+
# node lib/index.js evm
45+
# --config /app/config.json
46+
# --mnemonic-file /app/mnemonic
47+
# --metrics-port 9091
48+
# ports:
49+
# - "9091:9091"
50+
# networks:
51+
# - monitoring
52+
# restart: unless-stopped
53+
54+
# Example price_pusher service for Solana
55+
# price_pusher_solana:
56+
# image: your-price-pusher-image:latest
57+
# container_name: price_pusher_solana
58+
# volumes:
59+
# - ./config.solana.mainnet.json:/app/config.json
60+
# - ./mnemonic:/app/mnemonic
61+
# command: >
62+
# node lib/index.js solana
63+
# --config /app/config.json
64+
# --mnemonic-file /app/mnemonic
65+
# --metrics-port 9092
66+
# ports:
67+
# - "9092:9092"
68+
# networks:
69+
# - monitoring
70+
# restart: unless-stopped
71+
72+
networks:
73+
monitoring:
74+
driver: bridge
75+
76+
volumes:
77+
grafana-storage:

0 commit comments

Comments
 (0)