A hands-on tutorial for monitoring applications with Prometheus and Grafana. This project demonstrates both application-level metrics (HTTP requests from a Go web server) and system-level metrics (CPU, memory, disk) using Node Exporter.
- Architecture
- Dashboard Preview
- Dashboard Configuration
- Built With
- Getting Started
- Setup
- Usage
- Troubleshooting
- Project File Structure
This diagram shows the complete monitoring flow from user interaction to real-time visualization. Each component serves a specific role in collecting, storing, and displaying metrics from the Go web application and system resources.
flowchart TD
User[User Browser]
GoApp[Go Web Server<br/>Port 8080<br/>Exposes /metrics endpoint]
NodeExporter[Node Exporter<br/>Port 9100<br/>Collects system metrics]
Prometheus[Prometheus<br/>Port 9090<br/>Scrapes & stores metrics<br/>Time-series database]
Grafana[Grafana<br/>Port 3000<br/>Creates dashboards<br/>Visualizes data]
User -->|1. Visits website| GoApp
Prometheus -->|2a. Scrapes /metrics| GoApp
Prometheus -->|2b. Scrapes system metrics| NodeExporter
Grafana -->|3. Queries metrics| Prometheus
User -->|4. Views dashboard| Grafana
style User fill:#555,stroke:#000,stroke-width:2px,color:#fff
style GoApp fill:#333,stroke:#000,stroke-width:2px,color:#fff
style NodeExporter fill:#333,stroke:#000,stroke-width:2px,color:#fff
style Prometheus fill:#444,stroke:#000,stroke-width:2px,color:#fff
style Grafana fill:#444,stroke:#000,stroke-width:2px,color:#fff
- User Traffic Generation: Users visit the Go web server, generating HTTP requests that create application metrics
- Metrics Collection:
- Prometheus scrapes application metrics from the Go app's
/metricsendpoint every 15 seconds - Prometheus scrapes system metrics (CPU, memory, disk, network) from Node Exporter every 15 seconds
- Prometheus scrapes application metrics from the Go app's
- Data Querying: Grafana uses PromQL queries to fetch metrics from the Prometheus database
- Real-time Visualization: Users view live application and system metrics in Grafana dashboards
Prometheus Targets Page: This picture confirms that Prometheus is successfully connected to and scraping both the Go application and Node Exporter.
Application Metrics Dashboard: This picture shows the application dashboard visualizing the rate of HTTP requests per second.
System Metrics Dashboard: This picture shows the Node Exporter dashboard with system-level metrics including CPU, memory, disk, and network usage.
Setting up the Application Metrics Panel:
This picture shows the configuration for tracking request rates using the rate(http_requests_total[5m]) query.
The query uses:
- Metric:
http_requests_total - Operation:
Rateover a 5-minute range - Visualization: Time series chart
The Node Exporter dashboard (Dashboard ID: 1860) tracks:
- CPU Metrics: CPU usage percentage, system load
- Memory Metrics: RAM usage, swap usage
- Disk Metrics: Disk space usage, I/O operations
- Network Metrics: Network traffic (bytes sent/received)
- Go - Backend web server and application logic
- Prometheus - Metrics collection and time-series database
- Grafana - Data visualization and dashboard creation
- Node Exporter - System and hardware metrics collector
- Docker & Docker Compose - Containerization and orchestration
To get a local copy up and running, follow these steps.
You must have the following software installed:
- Go (version 1.25.1 or later)
- Docker and Docker Compose
-
Clone the repository:
git clone https://github.com/14yashh/prometheus-visit-metrics.git cd prometheus-visit-metrics -
Start the Go Application: Open a terminal, navigate into the web server's directory, and run the application.
cd web-server go mod tidy # Download dependencies if needed go run main.go
The server should display:
Go server starting on port 8080... -
Start the Monitoring Stack: Open a second terminal in the project's root directory and launch the Docker containers.
docker-compose up
Prometheus is configured via the prometheus.yml file in your project root. Here's what you need to know:
-
Scrape Configuration:
- Application Target:
host.docker.internal:8080(your Go web server) - System Target:
node-exporter:9100(Node Exporter container) - Scrape Interval: 15 seconds (defined in global config)
- Metrics Paths:
/metricsfor both targets
- Application Target:
-
Verify Prometheus is Scraping:
- Go to
http://localhost:9090/targets - Check that both targets show as "UP":
visitor-metric-app(Go application)node-exporter(system metrics)
- If either is down, verify the respective service is running
- Go to
-
Query Metrics:
- Navigate to
http://localhost:9090/graph - Try application queries:
http_requests_totalorrate(http_requests_total[5m]) - Try system queries:
node_cpu_seconds_totalornode_memory_MemAvailable_bytes - Use the "Execute" button to see results
- Navigate to
-
Add Prometheus Data Source:
- Navigate to Configuration → Data Sources
- Add Prometheus with URL:
http://prometheus:9090 - Note: Use
prometheus:9090(notlocalhost:9090) because Grafana communicates with Prometheus inside Docker's network
-
Create Application Metrics Dashboard:
- Click on "+" → Dashboard → Add new panel
- Select
prometheus-visit-metricsas the data source - Configure the Query:
- Metric: Select
http_requests_total - Operation: Choose
Ratewith a range of5m - This creates the query:
rate(http_requests_total[5m])
- Metric: Select
- Customize the Panel:
- Set visualization type to "Time series"
- Add a descriptive title like "HTTP Request Rate"
- Save the dashboard
-
Create System Metrics Dashboard (Node Exporter):
Option A: Import Pre-built Dashboard (Recommended)
- Click on "+" → Import Dashboard
- Enter Dashboard ID: 1860
- Select your Prometheus data source
- Click "Import"
- This dashboard includes comprehensive system metrics: CPU, memory, disk I/O, network traffic, filesystem usage, and system uptime
Option B: Create Custom Dashboard
- Create a new dashboard or add panels to the existing one
- Add panels for system metrics:
- CPU Usage:
100 - (avg by (instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100) - Memory Usage:
(1 - (node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes)) * 100 - Disk Usage:
100 - ((node_filesystem_avail_bytes * 100) / node_filesystem_size_bytes) - Network Traffic:
rate(node_network_receive_bytes_total[5m])andrate(node_network_transmit_bytes_total[5m])
- CPU Usage:
- Customize visualization types (gauges, time series, stat panels)
- Save the dashboard
Once everything is set up, you can use the monitoring stack:
- Go Web App: Visit
http://localhost:8080to generate traffic and create application metrics data. - App Metrics: View the raw application metrics at
http://localhost:8080/metricsto see Prometheus-format data. - Node Exporter Metrics: View system metrics at
http://localhost:9100/metricsto see hardware and OS metrics. - Prometheus UI: Access Prometheus at
http://localhost:9090to query and explore both application and system metrics. - Grafana Dashboard: Access Grafana at
http://localhost:3000to view your configured dashboards for application and system visualizations.
Common Issues:
- Port conflicts: Ensure ports 3000, 8080, 9090, and 9100 are available
- Docker issues: Make sure Docker daemon is running
- Metrics not showing: Wait 15-30 seconds for initial Prometheus scraping
- Go module issues: Run
go mod tidyin the web-server directory - Node Exporter not showing data: Verify the node-exporter container is running with
docker ps - Targets down in Prometheus: Check that all containers are running and networking is properly configured
The repository is organized as follows:
.
├── docker-compose.yml # Orchestrates all containers (Prometheus, Grafana, Node Exporter)
├── prometheus.yml # Prometheus scrape configuration for app and system metrics
├── README.md # Project documentation
├── images/ # Screenshots and documentation assets
│ ├── grafana-dashboard.png # Application metrics dashboard
│ ├── grafana-config.png # Application dashboard configuration
│ ├── node-exporter-dashboard.png # System metrics dashboard
│ ├── node-exporter-config.png # System dashboard configuration
│ └── prometheus-targets.png # Prometheus targets status
└── web-server/ # Go application directory
├── go.mod # Go module dependencies
├── go.sum # Dependency checksums
└── main.go # Main Go application with metrics



