Skip to content

Commit e331450

Browse files
seunlanlegeclaude
andcommitted
[simplex]: replace dashboard with Prometheus/Grafana metrics
Replace the built-in HTML dashboard with a proper Prometheus metrics endpoint and Grafana dashboards. Adds order volume, cumulative profit, and per-phase processing duration metrics. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent a00942a commit e331450

16 files changed

Lines changed: 1105 additions & 1879 deletions

File tree

sdk/packages/simplex/README.md

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,81 @@ We provide a simple script for Docker operations:
5656
# Run as container
5757
./scripts/docker.sh run
5858

59-
# Use Docker Compose
59+
# Use Docker Compose (includes Prometheus + Grafana)
6060
./scripts/docker.sh up
6161
./scripts/docker.sh down
6262
./scripts/docker.sh logs
6363
```
6464

65+
## Monitoring
66+
67+
Simplex exposes Prometheus metrics when started with the `-p` flag. The Docker Compose stack includes Prometheus and Grafana pre-configured with a dashboard.
68+
69+
### Quick Start
70+
71+
```bash
72+
# Start everything (simplex + prometheus + grafana)
73+
cd scripts && docker compose up -d
74+
75+
# Grafana is at http://localhost:3420 (admin/admin)
76+
# Prometheus is at http://localhost:9091
77+
```
78+
79+
### Without Docker
80+
81+
```bash
82+
# Start simplex with metrics on port 9090
83+
simplex run -c config.toml -p 9090
84+
85+
# Point your own Prometheus at http://localhost:9090/metrics
86+
```
87+
88+
### Exposed Metrics
89+
90+
| Metric | Type | Labels | Description |
91+
|---|---|---|---|
92+
| `simplex_orders_detected_total` | counter | | Orders detected on-chain |
93+
| `simplex_orders_filled_total` | counter | | Orders successfully filled |
94+
| `simplex_orders_executed_total` | counter | `success`, `strategy` | Orders executed (pass/fail) |
95+
| `simplex_orders_skipped_total` | counter | | Orders skipped (not profitable) |
96+
| `simplex_bids_submitted_total` | counter | `success` | Bids submitted to Hyperbridge |
97+
| `simplex_balance_usdc` | gauge | `chain_id` | USDC balance per chain |
98+
| `simplex_balance_usdt` | gauge | `chain_id` | USDT balance per chain |
99+
| `simplex_balance_native` | gauge | `chain_id`, `symbol` | Native token balance per chain |
100+
| `simplex_balance_exotic` | gauge | `chain_id`, `symbol` | Exotic token balance per chain |
101+
| `simplex_bids_pending` | gauge | | Bids pending retraction |
102+
| `simplex_bids_successful` | gauge | | Total successful bids |
103+
| `simplex_bids_failed` | gauge | | Total failed bids |
104+
| `simplex_bids_retracted` | gauge | | Total retracted bids |
105+
| `simplex_hyperbridge_balance_free` | gauge | | Substrate free balance |
106+
| `simplex_hyperbridge_balance_reserved` | gauge | | Substrate reserved balance |
107+
| `simplex_uptime_seconds` | gauge | | Process uptime |
108+
| `simplex_order_processing_duration_seconds` | histogram | `success` | Detection-to-execution latency |
109+
110+
Node.js process metrics (CPU, memory, GC, event loop) are also exported with the `simplex_` prefix.
111+
112+
### Environment Variables
113+
114+
| Variable | Default | Description |
115+
|---|---|---|
116+
| `GRAFANA_PORT` | `3420` | Grafana host port |
117+
| `GRAFANA_USER` | `admin` | Grafana admin username |
118+
| `GRAFANA_PASSWORD` | `admin` | Grafana admin password |
119+
| `PROMETHEUS_PORT` | `9091` | Prometheus host port |
120+
| `CONFIG_PATH` | `../config.toml` | Path to simplex config file |
121+
122+
### Grafana Dashboard
123+
124+
A pre-provisioned "Simplex Filler" dashboard is included with panels for:
125+
126+
- Order throughput and success rate
127+
- Order processing latency percentiles (p50/p95/p99)
128+
- USDC/USDT/native/exotic balance history per chain
129+
- Total stablecoin balance across all chains
130+
- Hyperbridge substrate balance
131+
- Bid status breakdown
132+
- Process memory usage
133+
65134
## Configuration
66135

67136
The filler uses a TOML configuration file. See `filler-config-example.toml` for a complete example.

sdk/packages/simplex/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
"ethers": "^5.7.2",
7474
"p-queue": "^8.1.0",
7575
"pino": "^9.9.5",
76+
"prom-client": "^15.1.0",
7677
"pino-pretty": "^11.3.0",
7778
"scale-ts": "^1.6.1",
7879
"toml": "^3.0.0",

sdk/packages/simplex/pnpm-lock.yaml

Lines changed: 30 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/packages/simplex/scripts/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ RUN cd packages/sdk && pnpm build
3232
# Build simplex
3333
RUN cd packages/simplex && pnpm build
3434

35-
# Create a healthcheck script
35+
# Create a healthcheck script that hits the metrics /health endpoint
3636
RUN echo '#!/bin/sh' > /app/healthcheck.sh && \
37-
echo 'ps -ef | grep "node" | grep -v grep > /dev/null || exit 1' >> /app/healthcheck.sh && \
37+
echo 'node -e "fetch(\"http://localhost:9090/health\").then(r=>{if(!r.ok)throw 1})" 2>/dev/null || ps -ef | grep "node" | grep -v grep > /dev/null || exit 1' >> /app/healthcheck.sh && \
3838
chmod +x /app/healthcheck.sh
3939

4040
USER simplex

sdk/packages/simplex/scripts/docker-compose.yml

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ services:
88
dockerfile: packages/simplex/scripts/Dockerfile
99
container_name: hyperbridge-simplex
1010
restart: unless-stopped
11-
command: ["run", "-c", "/app/config/config.toml"]
11+
command: ["run", "-c", "/app/config/config.toml", "-p", "9090"]
1212
volumes:
1313
- ${CONFIG_PATH:-../config.toml}:/app/config/config.toml:ro
1414
environment:
@@ -21,12 +21,48 @@ services:
2121
max-size: "10m"
2222
max-file: "3"
2323
healthcheck:
24-
test: ["CMD", "/app/healthcheck.sh"]
24+
test: ["CMD", "node", "-e", "fetch('http://localhost:9090/health').then(r=>{if(!r.ok)throw 1})"]
2525
interval: 30s
2626
timeout: 10s
2727
retries: 3
2828
start_period: 5s
2929

30+
prometheus:
31+
image: prom/prometheus:latest
32+
container_name: simplex-prometheus
33+
restart: unless-stopped
34+
volumes:
35+
- ./monitoring/prometheus.yml:/etc/prometheus/prometheus.yml:ro
36+
- prometheus-data:/prometheus
37+
command:
38+
- "--config.file=/etc/prometheus/prometheus.yml"
39+
- "--storage.tsdb.retention.time=30d"
40+
networks:
41+
- simplex-network
42+
ports:
43+
- "${PROMETHEUS_PORT:-9091}:9090"
44+
45+
grafana:
46+
image: grafana/grafana:latest
47+
container_name: simplex-grafana
48+
restart: unless-stopped
49+
volumes:
50+
- ./monitoring/grafana/provisioning:/etc/grafana/provisioning:ro
51+
- ./monitoring/grafana/dashboards:/var/lib/grafana/dashboards:ro
52+
- grafana-data:/var/lib/grafana
53+
environment:
54+
- GF_SECURITY_ADMIN_USER=${GRAFANA_USER:-admin}
55+
- GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_PASSWORD:-admin}
56+
- GF_USERS_ALLOW_SIGN_UP=false
57+
networks:
58+
- simplex-network
59+
ports:
60+
- "${GRAFANA_PORT:-3420}:3000"
61+
62+
volumes:
63+
prometheus-data:
64+
grafana-data:
65+
3066
networks:
3167
simplex-network:
3268
driver: bridge

0 commit comments

Comments
 (0)