This is a Prometheus exporter that monitors a Solana RPC node, optimized with memory garbage collection to limit resource usage.
Clone the repository:
git clone https://github.com/yourusername/solana-rpc-monitor.git
cd solana-rpc-monitor
Install dependencies:
pip install -r requirements.txt
Create a config.yml file (or use environment variables):
# See config-yml example
The application can be configured through environment variables or a config.yml file:
| Parameter | Environment Variable | Default | Description |
|---|---|---|---|
| RPC Endpoint | SOLANA_RPC_ENDPOINT | http://localhost:8799 | URL of your Solana RPC node |
| Network Endpoint | NETWORK_RPC_ENDPOINT | https://api.mainnet-beta.solana.com | Reference RPC for comparisons |
| WebSocket Endpoint | SOLANA_WS_ENDPOINT | ws://localhost:8800 | WebSocket URL of your Solana node |
| Port | METRIC_PORT | 6660 | Port for Prometheus metrics |
| Collection Interval | SLEEP_TIME | 15 | Seconds between metric collections |
| Metric Retention | METRIC_RETENTION_SECONDS | 60 | Seconds to keep metrics in memory |
| Log Level | LOG_LEVEL | INFO | Logging verbosity |
python main.py
This will start the metrics server on the configured port (default: 6660).
Add this to your prometheus.yml:
scrape_configs:
- job_name: 'solana-rpc'
scrape_interval: 20s
static_configs:
- targets: ['localhost:6660']
The application now includes automatic memory management:
/metrics endpoint, garbage collection is triggeredYou can modify the retention period in your config.yml:
metric_retention_seconds: 120 # Keep metrics for 2 minutes
The application logs its memory usage and garbage collection statistics. You can also add the following metrics to your Grafana dashboard:
process_resident_memory_bytes: Monitor the memory usage of the exporter.
├── config.py # Configuration handling
├── exporter/
│ ├── __init__.py
│ ├── collector.py # Metrics collection
│ └── exporter.py # HTTP server and main loop
├── metrics/
│ ├── __init__.py
│ ├── metrics.py # Prometheus metric definitions
│ └── manager.py # Memory management
├── modules/ # Individual monitoring modules
│ ├── __init__.py
│ ├── block_time.py
│ ├── epoch_monitor.py
│ ├── node_health.py
│ ├── slot_monitor.py
│ └── ...
├── utils/
│ ├── __init__.py
│ └── func.py # Utility functions
├── config.yml # Configuration file
├── main.py # Application entry point
└── requirements.txt # Dependencies
Logs are stored in the logs/ directory. Memory management events are logged at the DEBUG level.
The application includes a comprehensive test suite:
# Run all tests
pytest
# Run tests with coverage report
pytest --cov=./ --cov-report=term-missing
# Run a specific test file
pytest tests/test_metrics_manager.py
# Clone the repository
git clone https://github.com/yourusername/solana-rpc-monitor.git
cd solana-rpc-monitor
# Install dependencies including development dependencies
pip install -r requirements.txt
# Run linting
flake8
pylint $(git ls-files '*.py')
The project includes a Makefile to simplify common development tasks:
# Install dependencies
make setup
# Run linting
make lint
# Run tests
make test
# Run tests with coverage
make coverage
# Clean up temporary files
make clean
# Install git hooks for pre-commit checks
make install-hooks
# Run all checks (lint, test, coverage)
make all
# Show available commands
make help
The project includes pre-commit hooks to ensure code quality before committing:
Install the git hooks to run tests automatically before each commit:
make install-hooks
This will install a pre-commit hook that runs linting and tests before allowing commits.
Alternatively, you can use the pre-commit framework:
# Install pre-commit
pip install pre-commit
# Install the git hooks
pre-commit install
# Run pre-commit on all files
pre-commit run --all-files
The project uses GitHub Actions for continuous integration and delivery:
CI Pipeline: Triggered on every push and pull request
Docker Build Pipeline: Triggered on pushes to main/master and tags
# Build the Docker image locally
docker build -t solana-rpc-monitor .
# Run the container
docker run -p 6660:6660 -v $(pwd)/config.yml:/app/config.yml solana-rpc-monitor
Content type
Image
Digest
sha256:f27b0ce61…
Size
51.7 MB
Last updated
over 1 year ago
docker pull chainstack/solana-eyes