Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TP-Link Router Exporter

A Prometheus exporter for TP-Link routers that collects WAN/LAN status, host information, and network metrics.

Features

  • WAN status (IPv4/IPv6, primary/backup interfaces)
  • WAN uptime and traffic speed (uplink/downlink)
  • LAN status and MAC addresses
  • Online hosts detection with hostname, IP, speed, RSSI
  • Automatic token refresh on authentication errors

Requirements

  • Go 1.22+
  • TP-Link router with web management interface accessible from the host

Quick Start

1. Clone and build

git clone https://github.com/HuckOps/tplink_router_exporter
cd tplink_router_exporter
go build -o tplink-router-exporter .

2. Set environment variables

# Router management address
export ROUTER_ENDPOINT="http://192.168.0.1"
# Router admin password
export PASSWORD="your_password"
# Collection interval in seconds (default: 30)
export COLLECT_INTERVAL="30"

3. Run

./tplink-router-exporter

Access metrics at http://localhost:9100/metrics

Prometheus Configuration

Add to prometheus.yml:

scrape_configs:
  - job_name: 'tplink_router'
    static_configs:
      - targets: ['localhost:9100']

Available Metrics

WAN Status

Metric Type Labels Description
tplink_router_wan_status Gauge name, ip, netmask, gateway, proto, primary_dns, secondary_dns WAN interface status
tplink_router_wan_uptime Gauge name WAN connection uptime (seconds)
tplink_router_wan_tx_speed Gauge name Upload speed (kbps/s)
tplink_router_wan_rx_speed Gauge name Download speed (kbps/s)

name values: wan_1, wan_2, wan_v6_1, wan_v6_2

LAN Status

Metric Type Labels Description
tplink_router_lan_status Gauge ip, netmask, gateway, primary_dns, secondary_dns, ip_mode, mac LAN interface status

Host Information

Metric Type Labels Description
tplink_router_online_hosts Gauge Number of online hosts
tplink_router_host_detail Gauge hostname, ip, ipv6, mac, ssid Host detail
tplink_router_host_tx_speed Gauge hostname, ip Host upload speed (kbps/s)
tplink_router_host_rx_speed Gauge hostname, ip Host download speed (kbps/s)

Architecture

main.go                    # Entry point, HTTP server
├── config/                # Configuration (env vars)
├── pkg/tplink/            # Router API client
│   ├── api.go             # Login, GetDS, token management
│   └── ds.go              # Response structs
└── internal/collector/    # Prometheus collectors
    ├── network.go         # WAN/LAN metrics
    └── hosts.go           # Host metrics

Notes

  • Token is stored globally and auto-refreshed when the router returns error_code != 0
  • Collection interval defaults to 30 seconds, configurable via COLLECT_INTERVAL environment variable (in seconds)
  • All speed metrics are in kbps/s

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages