A simple network monitoring tool. This project uses Python to perform network checks and can be run using Docker. Monitoring dashboards can be set up using the provided Grafana and Prometheus configurations.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
- Docker
- Docker Compose (if using the
docker-composesetup) - Python (if running locally without Docker)
-
Clone the repository:
git clone https://github.com/yufeikang/netmon.git cd netmon -
Build and run with Docker (recommended for isolated environment):
# Build the Docker image docker build -t netmon . # Run the Docker container docker run netmon
-
Alternatively, using Docker Compose (for multi-container setup including Grafana/Prometheus):
cd docker-compose docker-compose up -dcd docker-compose docker-compose up -d
- Prometheus will be available at `http://localhost:9090` - Grafana will be available at `http://localhost:3000` (login with admin/admin, then change password. Datasource and dashboard should be auto-provisioned). -
To run locally without Docker (ensure Python and dependencies are installed):
# Create and activate a virtual environment (recommended) python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate` # Install dependencies pip install -r requirements.txt # Run the application (assuming net_monitor.py is the main script) python net_monitor.py
Describe how to use your project. For example:
- If it's a script:
uv run python net_monitor.py --target example.com - If it's a service: "Access the service at
http://localhost:YOUR_PORT"
This project includes a Dockerfile to build a containerized version of the application.
-
Build the image:
docker build -t netmon . -
Run the container:
docker run netmon
The docker-compose/ directory contains a docker-compose.yaml file to orchestrate the main application along with Prometheus for metrics collection and Grafana for visualization.
If you already have Prometheus and Grafana instances running, you can configure netmon to integrate with them.
-
Run the
netmonDocker container:Pull the latest image from GitHub Container Registry and run it, exposing the metrics port (default
9105):docker pull ghcr.io/yufeikang/netmon:latest docker run -d --name netmon -p 9105:9105 ghcr.io/yufeikang/netmon:latest
This will start
netmonand expose its Prometheus metrics onhttp://<your-docker-host-ip>:9105/metrics. -
Configure Prometheus to scrape
netmonmetrics:Add the following job to your
prometheus.ymlconfiguration file:scrape_configs: # ... your other scrape configs ... - job_name: 'netmon' static_configs: - targets: ['<your-docker-host-ip>:9105'] # Replace <your-docker-host-ip> with the IP address of the machine running the netmon container
If
netmonis running on the same machine as Prometheus, you can often uselocalhost:9105orhost.docker.internal:9105(depending on your Docker setup). Reload your Prometheus configuration after making changes. -
Import the Grafana Dashboard:
The pre-configured Grafana dashboard for
netmonis located atdocker-compose/grafana/provisioning/dashboards/netmon_dashboard.json. You can import this JSON file into your existing Grafana instance:- Go to your Grafana UI.
- Navigate to "Dashboards" -> "Browse".
- Click on "Import".
- Upload the
netmon_dashboard.jsonfile or paste its content. - Select your Prometheus data source when prompted.
This will provide you with the default
netmondashboard.
This repository is configured with a GitHub Actions workflow (.github/workflows/deploy-docker.yml) that automatically:
- Builds the Docker image from the
Dockerfile. - Pushes the image to GitHub Packages (ghcr.io) on every push to the
mainbranch.
The image will be tagged as ghcr.io/yufeikang/netmon:latest.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
This project is licensed under the MIT License - see the LICENSE.md file for details (if you choose to add one).