HUB
Sign inSign up
solana-eyes logo

chainstack/solana-eyes

By chainstack

•Updated over 1 year ago

Image
0

4.3K

chainstack/solana-eyes repository overview

⁠Solana RPC Monitor with Memory Management

This is a Prometheus exporter that monitors a Solana RPC node, optimized with memory garbage collection to limit resource usage.

⁠Updated Features

  • Memory Management: Automatically cleans up metrics data after it's scraped by Prometheus
  • Retention Configuration: Configure how long metric data is kept in memory
  • Scrape Detection: Detects when Prometheus scrapes metrics and triggers garbage collection
  • Metrics Collection: Comprehensive Solana RPC monitoring metrics
  • Performance Optimizations: Reduced memory footprint for long-running instances

⁠Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/solana-rpc-monitor.git
    cd solana-rpc-monitor
    
  2. Install dependencies:

    pip install -r requirements.txt
    
  3. Create a config.yml file (or use environment variables):

    # See config-yml example
    

⁠Configuration

The application can be configured through environment variables or a config.yml file:

ParameterEnvironment VariableDefaultDescription
RPC EndpointSOLANA_RPC_ENDPOINThttp://localhost:8799⁠URL of your Solana RPC node
Network EndpointNETWORK_RPC_ENDPOINThttps://api.mainnet-beta.solana.com⁠Reference RPC for comparisons
WebSocket EndpointSOLANA_WS_ENDPOINTws://localhost:8800WebSocket URL of your Solana node
PortMETRIC_PORT6660Port for Prometheus metrics
Collection IntervalSLEEP_TIME15Seconds between metric collections
Metric RetentionMETRIC_RETENTION_SECONDS60Seconds to keep metrics in memory
Log LevelLOG_LEVELINFOLogging verbosity

⁠Usage

⁠Starting the Monitor
python main.py

This will start the metrics server on the configured port (default: 6660).

⁠Prometheus Configuration

Add this to your prometheus.yml:

scrape_configs:
  - job_name: 'solana-rpc'
    scrape_interval: 20s
    static_configs:
      - targets: ['localhost:6660']
⁠Memory Management

The application now includes automatic memory management:

  1. Each metric is collected and stored in memory with a timestamp
  2. When Prometheus scrapes the /metrics endpoint, garbage collection is triggered
  3. The metrics manager clears data older than the configured retention period (default: 60 seconds)
  4. Periodic garbage collection also runs during the collection cycle

You can modify the retention period in your config.yml:

metric_retention_seconds: 120  # Keep metrics for 2 minutes
⁠Monitoring the Monitor

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
  • Set alerts if memory grows beyond expected bounds

⁠Directory Structure

.
├── 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

⁠Logging

Logs are stored in the logs/ directory. Memory management events are logged at the DEBUG level.

⁠Testing

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

⁠Development

⁠Setup Development Environment
# 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')
⁠Using the Makefile

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
⁠Pre-commit Hooks

The project includes pre-commit hooks to ensure code quality before committing:

⁠Option 1: Manual Git Hooks

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.

⁠Option 2: Pre-commit Framework

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
⁠CI/CD Pipeline

The project uses GitHub Actions for continuous integration and delivery:

  1. CI Pipeline: Triggered on every push and pull request

    • Code linting with flake8 and pylint
    • Unit tests with pytest
    • Code coverage reports
    • Docker image building and vulnerability scanning
  2. Docker Build Pipeline: Triggered on pushes to main/master and tags

    • Builds Docker image
    • Pushes to Docker Hub with appropriate tags
⁠Docker
# 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

Tag summary

Content type

Image

Digest

sha256:f27b0ce61…

Size

51.7 MB

Last updated

over 1 year ago

docker pull chainstack/solana-eyes