Skip to content

Commit 5ab72dd

Browse files
docs: add comprehensive README and monitoring stack
1 parent 14619e7 commit 5ab72dd

File tree

7 files changed

+234
-2
lines changed

7 files changed

+234
-2
lines changed

.dockerignore

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Git
2+
.git
3+
.gitignore
4+
5+
# Documentation
6+
README.md
7+
CHANGELOG.md
8+
9+
# Docker
10+
Dockerfile
11+
docker-compose.yml
12+
.dockerignore
13+
14+
# CI/CD
15+
.github
16+
17+
# Environment
18+
.env
19+
.env.example
20+
21+
# Data
22+
data/
23+
*.jsonl
24+
25+
# IDE
26+
.vscode
27+
.idea
28+
29+
# OS
30+
.DS_Store
31+
Thumbs.db
32+
33+
# Misc
34+
prometheus.yml
35+
grafana/
36+

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Generated by Cargo
22
/target/
33

4-
# Lock files for binaries
5-
Cargo.lock
4+
# Lock files for libraries (but commit for binaries)
5+
# Cargo.lock
66

77
# Environment variables
88
.env

CHANGELOG.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [0.1.0] - 2024-01-15
9+
10+
### Added
11+
12+
- Initial release of Solana Event Listener
13+
- WebSocket JSON-RPC client for Solana blockchain
14+
- Support for `logsSubscribe` mode for monitoring program logs
15+
- Support for `accountSubscribe` mode for monitoring account changes
16+
- Prometheus metrics endpoint on `/metrics` with:
17+
- `sol_events_total`: Counter for total events processed
18+
- `sol_errors_total`: Counter for total errors encountered
19+
- `sol_ws_connected`: Gauge for WebSocket connection status
20+
- JSONL file storage for event persistence
21+
- Automatic reconnection with exponential backoff (capped at 30s)
22+
- Graceful shutdown on CTRL+C
23+
- Configuration via environment variables and CLI arguments
24+
- Docker Compose setup with Prometheus and Grafana
25+
- Comprehensive CI/CD pipeline with GitHub Actions
26+
- Extensive test coverage for core functionality
27+
- Documentation with quickstart guide and examples
28+
29+
### Technical Details
30+
31+
- Built with Rust 2021 edition
32+
- Uses Tokio async runtime for high performance
33+
- Structured logging with tracing
34+
- Error handling with anyhow and thiserror
35+
- Clippy clean with `-D warnings`
36+
37+
[0.1.0]: https://github.com/yourusername/solana-event-listener/releases/tag/v0.1.0
38+

Dockerfile

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Build stage
2+
FROM rust:1.75-slim as builder
3+
4+
WORKDIR /app
5+
6+
# Install dependencies
7+
RUN apt-get update && apt-get install -y \
8+
pkg-config \
9+
libssl-dev \
10+
&& rm -rf /var/lib/apt/lists/*
11+
12+
# Copy manifest files
13+
COPY Cargo.toml Cargo.lock ./
14+
15+
# Copy source code
16+
COPY src ./src
17+
18+
# Build for release
19+
RUN cargo build --release
20+
21+
# Runtime stage
22+
FROM debian:bookworm-slim
23+
24+
WORKDIR /app
25+
26+
# Install runtime dependencies
27+
RUN apt-get update && apt-get install -y \
28+
ca-certificates \
29+
&& rm -rf /var/lib/apt/lists/*
30+
31+
# Copy binary from builder
32+
COPY --from=builder /app/target/release/solana-event-listener /app/
33+
34+
EXPOSE 9108
35+
36+
CMD ["/app/solana-event-listener"]
37+

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,26 @@ cargo run --release -- --mode account --accounts <PUBKEY1,PUBKEY2>
6868
cargo run --release -- --metrics-addr 0.0.0.0:9999
6969
```
7070

71+
### Docker Compose (Recommended for Production)
72+
73+
Start with Prometheus and Grafana:
74+
75+
```bash
76+
# Build and start all services
77+
docker-compose up -d
78+
79+
# View logs
80+
docker-compose logs -f solana-event-listener
81+
82+
# Stop services
83+
docker-compose down
84+
```
85+
86+
Access dashboards:
87+
- **Prometheus**: http://localhost:9090
88+
- **Grafana**: http://localhost:3000 (default: `admin`/`admin`)
89+
- **Metrics**: http://localhost:9108/metrics
90+
7191
### Check Metrics
7292

7393
```bash
@@ -118,6 +138,27 @@ CLI flags override environment variables.
118138
{"timestamp":"2024-01-15T10:30:45Z","pubkey":"Address...","slot":12345,"lamports":1000000,"data":"base64..."}
119139
```
120140

141+
## Terminal Output Example
142+
143+
Running in logs mode produces output like:
144+
145+
```
146+
$ cargo run --release -- --mode logs --program-id ComputeBudget111111111111111111111111111111
147+
148+
2024-01-15T10:30:45.123Z INFO Starting Solana Event Listener v0.1.0
149+
2024-01-15T10:30:45.125Z INFO Configuration loaded: mode=logs
150+
2024-01-15T10:30:45.126Z INFO Metrics registry initialized
151+
2024-01-15T10:30:45.127Z INFO Metrics server spawned on 0.0.0.0:9108
152+
2024-01-15T10:30:45.128Z INFO Storage initialized: ./events.jsonl
153+
2024-01-15T10:30:45.129Z INFO Starting logs subscription mode
154+
2024-01-15T10:30:45.130Z INFO Connecting to Solana WebSocket: wss://api.mainnet-beta.solana.com/
155+
2024-01-15T10:30:45.456Z INFO Connected to WebSocket
156+
2024-01-15T10:30:45.457Z INFO Sending subscription request for program: ComputeBudget111111111111111111111111111111
157+
2024-01-15T10:30:45.500Z INFO Subscribed to logs for program: ComputeBudget111111111111111111111111111111
158+
2024-01-15T10:30:46.200Z INFO Event: signature=5VeK..., slot=245000000, program=ComputeBudget111111111111111111111111111111, log_lines=3
159+
2024-01-15T10:30:47.100Z INFO Event: signature=7XmP..., slot=245000001, program=ComputeBudget111111111111111111111111111111, log_lines=2
160+
```
161+
121162
## Architecture
122163

123164
```

docker-compose.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
version: '3.8'
2+
3+
services:
4+
solana-event-listener:
5+
build:
6+
context: .
7+
dockerfile: Dockerfile
8+
container_name: solana-event-listener
9+
restart: unless-stopped
10+
environment:
11+
- WS_URL=${WS_URL:-wss://api.mainnet-beta.solana.com/}
12+
- MODE=${MODE:-logs}
13+
- PROGRAM_ID=${PROGRAM_ID}
14+
- ACCOUNTS=${ACCOUNTS}
15+
- COMMITMENT=${COMMITMENT:-finalized}
16+
- EVENT_LOG_PATH=/data/events.jsonl
17+
- METRICS_ADDR=0.0.0.0:9108
18+
- RUST_LOG=${RUST_LOG:-info}
19+
volumes:
20+
- ./data:/data
21+
- ./events.jsonl:/data/events.jsonl:rw
22+
networks:
23+
- monitoring
24+
depends_on:
25+
- prometheus
26+
27+
prometheus:
28+
image: prom/prometheus:latest
29+
container_name: prometheus
30+
restart: unless-stopped
31+
ports:
32+
- "9090:9090"
33+
volumes:
34+
- ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
35+
- prometheus-data:/prometheus
36+
command:
37+
- '--config.file=/etc/prometheus/prometheus.yml'
38+
- '--storage.tsdb.path=/prometheus'
39+
- '--storage.tsdb.retention.time=30d'
40+
- '--web.console.libraries=/usr/share/prometheus/console_libraries'
41+
- '--web.console.templates=/usr/share/prometheus/consoles'
42+
networks:
43+
- monitoring
44+
45+
grafana:
46+
image: grafana/grafana:latest
47+
container_name: grafana
48+
restart: unless-stopped
49+
ports:
50+
- "3000:3000"
51+
environment:
52+
- GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_PASSWORD:-admin}
53+
- GF_SECURITY_ADMIN_USER=${GRAFANA_USER:-admin}
54+
- GF_USERS_ALLOW_SIGN_UP=false
55+
volumes:
56+
- grafana-data:/var/lib/grafana
57+
- ./grafana/dashboards:/etc/grafana/provisioning/dashboards
58+
- ./grafana/datasources:/etc/grafana/provisioning/datasources
59+
networks:
60+
- monitoring
61+
depends_on:
62+
- prometheus
63+
64+
volumes:
65+
prometheus-data:
66+
grafana-data:
67+
68+
networks:
69+
monitoring:
70+
driver: bridge
71+

prometheus.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
global:
2+
scrape_interval: 15s
3+
evaluation_interval: 15s
4+
5+
scrape_configs:
6+
- job_name: 'solana-event-listener'
7+
static_configs:
8+
- targets: ['solana-event-listener:9108']
9+

0 commit comments

Comments
 (0)