Monitor OpenVPN connections with Grafana dashboard and Prometheus metrics

Intermediate 45 min Apr 15, 2026 160 views
Ubuntu 24.04 Debian 12 AlmaLinux 9 Rocky Linux 9

Set up comprehensive monitoring for your OpenVPN server using Prometheus to collect connection metrics and Grafana to visualize client connections, bandwidth usage, and server performance through custom dashboards.

Prerequisites

  • OpenVPN server installed and configured
  • Root or sudo access
  • At least 2GB RAM
  • Basic knowledge of Prometheus and Grafana

What this solves

OpenVPN monitoring helps you track client connections, bandwidth usage, and server performance in real-time. This tutorial shows you how to export OpenVPN status data to Prometheus and create comprehensive Grafana dashboards for VPN infrastructure monitoring.

Step-by-step installation

Update system packages

Start by updating your package manager to ensure you get the latest versions of monitoring tools.

sudo apt update && sudo apt upgrade -y
sudo dnf update -y

Install required dependencies

Install Python and required packages for the OpenVPN Prometheus exporter.

sudo apt install -y python3 python3-pip git wget curl
sudo dnf install -y python3 python3-pip git wget curl

Configure OpenVPN status logging

Enable OpenVPN status logging to generate metrics data. Edit your OpenVPN server configuration to include status file output.

# Add these lines to enable status monitoring
status /var/log/openvpn/openvpn-status.log 10
status-version 2
management localhost 7505

Create OpenVPN log directory

Create the log directory with proper permissions for OpenVPN status files.

sudo mkdir -p /var/log/openvpn
sudo chown nobody:nogroup /var/log/openvpn
sudo chmod 755 /var/log/openvpn

Restart OpenVPN service

Restart OpenVPN to apply the new configuration and start generating status logs.

sudo systemctl restart openvpn@server
sudo systemctl status openvpn@server

Install Prometheus

Download and install Prometheus server to collect and store OpenVPN metrics.

cd /tmp
wget https://github.com/prometheus/prometheus/releases/download/v2.45.0/prometheus-2.45.0.linux-amd64.tar.gz
tar xvfz prometheus-2.45.0.linux-amd64.tar.gz
sudo mv prometheus-2.45.0.linux-amd64 /opt/prometheus
sudo useradd --no-create-home --shell /bin/false prometheus

Create Prometheus directories

Set up directory structure and permissions for Prometheus configuration and data storage.

sudo mkdir -p /etc/prometheus /var/lib/prometheus
sudo chown prometheus:prometheus /etc/prometheus /var/lib/prometheus
sudo chown prometheus:prometheus /opt/prometheus/prometheus /opt/prometheus/promtool

Create Prometheus configuration

Configure Prometheus to scrape OpenVPN metrics from the exporter we'll set up next.

global:
  scrape_interval: 15s
  evaluation_interval: 15s

rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['localhost:9090']

  - job_name: 'openvpn'
    static_configs:
      - targets: ['localhost:9176']
    scrape_interval: 10s
    metrics_path: /metrics

Create Prometheus systemd service

Set up systemd service for automatic Prometheus startup and management.

[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target

[Service]
User=prometheus
Group=prometheus
Type=simple
ExecStart=/opt/prometheus/prometheus \
    --config.file /etc/prometheus/prometheus.yml \
    --storage.tsdb.path /var/lib/prometheus/ \
    --web.console.templates=/opt/prometheus/consoles \
    --web.console.libraries=/opt/prometheus/console_libraries \
    --web.listen-address=0.0.0.0:9090

[Install]
WantedBy=multi-user.target

Install OpenVPN Prometheus exporter

Clone and install the OpenVPN Prometheus exporter to convert status logs into Prometheus metrics.

cd /opt
sudo git clone https://github.com/kumina/openvpn_exporter.git
cd openvpn_exporter
sudo pip3 install -r requirements.txt

Create OpenVPN exporter systemd service

Configure the OpenVPN exporter as a systemd service for automatic startup and monitoring.

[Unit]
Description=OpenVPN Prometheus Exporter
After=network.target

[Service]
Type=simple
User=nobody
Group=nogroup
ExecStart=/usr/bin/python3 /opt/openvpn_exporter/openvpn_exporter.py \
    --openvpn.status-paths /var/log/openvpn/openvpn-status.log \
    --web.listen-address 0.0.0.0:9176
Restart=always
RestartSec=15

[Install]
WantedBy=multi-user.target

Set proper permissions

Configure file ownership and permissions for the Prometheus configuration.

sudo chown prometheus:prometheus /etc/prometheus/prometheus.yml
sudo chown -R nobody:nogroup /opt/openvpn_exporter

Start monitoring services

Enable and start both Prometheus and the OpenVPN exporter services.

sudo systemctl daemon-reload
sudo systemctl enable --now prometheus
sudo systemctl enable --now openvpn-exporter
sudo systemctl status prometheus
sudo systemctl status openvpn-exporter

Install Grafana

Add the Grafana repository and install Grafana for dashboard visualization.

sudo apt install -y software-properties-common
wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee /etc/apt/sources.list.d/grafana.list
sudo apt update
sudo apt install -y grafana
sudo dnf install -y https://dl.grafana.com/oss/release/grafana-10.0.0-1.x86_64.rpm

Configure Grafana

Set up basic Grafana configuration with security settings and domain configuration.

[server]
http_addr = 0.0.0.0
http_port = 3000
domain = example.com

[security]
admin_user = admin
admin_password = your_secure_password_here

[users]
allow_sign_up = false
allow_org_create = false

Start Grafana service

Enable and start the Grafana service for dashboard access.

sudo systemctl enable --now grafana-server
sudo systemctl status grafana-server

Configure firewall rules

Open necessary ports for Prometheus, Grafana, and the OpenVPN exporter.

sudo ufw allow 3000/tcp comment 'Grafana'
sudo ufw allow 9090/tcp comment 'Prometheus'
sudo ufw allow 9176/tcp comment 'OpenVPN Exporter'
sudo firewall-cmd --permanent --add-port=3000/tcp
sudo firewall-cmd --permanent --add-port=9090/tcp
sudo firewall-cmd --permanent --add-port=9176/tcp
sudo firewall-cmd --reload

Configure Grafana dashboards

Add Prometheus data source

Access Grafana at http://your-server-ip:3000 and add Prometheus as a data source. Navigate to Configuration > Data Sources > Add data source > Prometheus.

URL: http://localhost:9090
Access: Server (default)
HTTP Method: GET

Create OpenVPN dashboard

Create a new dashboard with panels to monitor OpenVPN connections and performance metrics.

# Connected clients count
openvpn_up

Client connection status

openvpn_client_connected

Bytes received per client

rate(openvpn_client_bytes_received_total[5m])

Bytes sent per client

rate(openvpn_client_bytes_sent_total[5m])

Server uptime

openvpn_server_connected

Configure dashboard panels

Set up specific panels for comprehensive OpenVPN monitoring with appropriate visualization types.

Panel TypeQueryDescription
Statopenvpn_upServer status (up/down)
Statcount(openvpn_client_connected == 1)Connected clients count
Time Seriesrate(openvpn_client_bytes_received_total[5m]) * 8Download bandwidth (bps)
Time Seriesrate(openvpn_client_bytes_sent_total[5m]) * 8Upload bandwidth (bps)
Tableopenvpn_client_connectedClient connection details

Set up alerting

Configure Prometheus alerting rules

Create alerting rules for OpenVPN monitoring to notify about connection issues.

groups:
  - name: openvpn
    rules:
      - alert: OpenVPNDown
        expr: openvpn_up == 0
        for: 1m
        labels:
          severity: critical
        annotations:
          summary: "OpenVPN server is down"
          description: "OpenVPN server has been down for more than 1 minute"
      
      - alert: HighClientCount
        expr: count(openvpn_client_connected == 1) > 50
        for: 5m
        labels:
          severity: warning
        annotations:
          summary: "High number of VPN connections"
          description: "More than 50 clients connected to VPN server"

Update Prometheus configuration

Add the alerting rules to your Prometheus configuration.

global:
  scrape_interval: 15s
  evaluation_interval: 15s

rule_files:
  - "openvpn-rules.yml"

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['localhost:9090']

  - job_name: 'openvpn'
    static_configs:
      - targets: ['localhost:9176']
    scrape_interval: 10s
    metrics_path: /metrics

Restart Prometheus

Restart Prometheus to load the new alerting rules.

sudo chown prometheus:prometheus /etc/prometheus/openvpn-rules.yml
sudo systemctl restart prometheus
sudo systemctl status prometheus

Verify your setup

# Check OpenVPN status log generation
sudo tail -f /var/log/openvpn/openvpn-status.log

Verify Prometheus is collecting metrics

curl http://localhost:9176/metrics | grep openvpn

Check Prometheus targets

curl http://localhost:9090/api/v1/targets

Verify services are running

sudo systemctl status openvpn@server prometheus openvpn-exporter grafana-server

Access your monitoring interfaces:

  • Grafana dashboard: http://your-server-ip:3000
  • Prometheus web interface: http://your-server-ip:9090
  • OpenVPN exporter metrics: http://your-server-ip:9176/metrics

Common issues

SymptomCauseFix
No metrics from exporterStatus log not generatedCheck OpenVPN config includes status directive
Exporter connection failedPermission issues with log filesudo chown nobody:nogroup /var/log/openvpn/openvpn-status.log
Prometheus can't scrape targetsFirewall blocking portsEnsure ports 9090, 9176, 3000 are open
Grafana shows no dataPrometheus data source misconfiguredVerify Prometheus URL is http://localhost:9090
Old metrics displayedOpenVPN status file not updatingRestart OpenVPN service and check status interval

Next steps

Automated install script

Run this to automate the entire setup

Need help?

Don't want to manage this yourself?

We handle managed devops services for businesses that depend on uptime. From initial setup to ongoing operations.