How to Set Up Prometheus Monitoring with frp: Enabling the Metrics Endpoint
Enable Prometheus monitoring in frp by setting enablePrometheus = true in frps.toml alongside a configured webServer port, then scrape the /metrics endpoint exposed on the dashboard address.
fatedier/frp (Fast Reverse Proxy) exposes internal statistics—including connection counts, traffic volume, and proxy states—through a Prometheus-compatible metrics endpoint. Activating this feature requires enabling the web dashboard and setting a configuration flag in the server configuration file.
Configuration Prerequisites
The frps (server) component serves metrics through its embedded HTTP server. Consequently, you must enable the web dashboard before the /metrics endpoint becomes available. Without an active webServer configuration, the route registration logic in server/service.go never mounts the Prometheus handler.
Enabling the Metrics Endpoint in frps.toml
Set enablePrometheus = true within your server configuration file. This boolean flag resides in the ServerConfig struct defined in pkg/config/v1/server.go (lines 73–76), triggering the registration of the /metrics handler during service initialization.
# frps.toml
[webServer]
port = 7400
user = "admin"
password = "admin"
enablePrometheus = true
The dashboard listens on the specified port, and the metrics endpoint inherits this address. According to the source code in server/service.go, the registerRouteHandlers function (lines 94–104) conditionally attaches promhttp.Handler() to the /metrics route only when EnablePrometheus is true.
How frp Collects and Exposes Metrics
Configuration Layer
In pkg/config/v1/server.go, the ServerConfig struct contains the EnablePrometheus field. When parsed from TOML, this value determines whether the server initializes Prometheus instrumentation at startup.
HTTP Route Registration
The Service.registerRouteHandlers method in server/service.go builds the HTTP router for the administrative interface. If EnablePrometheus is true, it registers the standard Prometheus Go client handler (promhttp.Handler()) at the /metrics path, exposing all collected metric families.
Internal Metrics Collection
The server/metrics package maintains metric vectors updated throughout the server's lifecycle. Functions such as metrics.Server.NewClient() and metrics.Server.AddTrafficIn/Out() increment counters and gauges whenever clients connect, disconnect, or transmit data. These updates feed the registry queried by the Prometheus scraper.
Verifying the Endpoint Locally
Before adding the target to Prometheus, confirm the endpoint returns valid exposition format:
curl http://127.0.0.1:7400/metrics | head -n 10
Expect output containing metric families such as frp_server_client_total and frp_server_proxy_total:
# HELP frp_server_client_total Total number of connected clients
# TYPE frp_server_client_total gauge
frp_server_client_total 1
# HELP frp_server_proxy_total Total number of active proxies
# TYPE frp_server_proxy_total gauge
frp_server_proxy_total 3
Scraping Configuration for Prometheus
Add a scrape job to your prometheus.yml pointing to the frp dashboard address:
scrape_configs:
- job_name: 'frp'
static_configs:
- targets: ['127.0.0.1:7400']
metrics_path: '/metrics'
scheme: http
Reload Prometheus to begin collecting frp_* time series.
Visualizing Metrics in Grafana
Import the following dashboard JSON to monitor client connections and traffic rates:
{
"title": "frp Overview",
"panels": [
{
"type": "graph",
"title": "Connected Clients",
"targets": [{ "expr": "frp_server_client_total" }]
},
{
"type": "graph",
"title": "Traffic In (bytes)",
"targets": [{ "expr": "rate(frp_server_traffic_in_bytes[1m])" }]
}
]
}
Summary
- The frps server exposes Prometheus metrics only when both the
webServerport andenablePrometheusare configured infrps.toml. - The
EnablePrometheusflag inpkg/config/v1/server.gocontrols whetherregisterRouteHandlersinserver/service.gomounts thepromhttp.Handler(). - Metric collection occurs inside the
server/metricspackage, tracking client connections and traffic via vectors likefrp_server_client_total. - Verification requires curling the
/metricsendpoint on the dashboard port before configuring Prometheus scraping.
Frequently Asked Questions
Do I need to enable the web dashboard to use Prometheus monitoring with frp?
Yes. The /metrics endpoint is served by the same HTTP server instance that hosts the administrative dashboard. If webServer.port is unset or zero, the registerRouteHandlers function never executes, leaving the Prometheus handler unregistered regardless of the enablePrometheus setting.
What frp metrics are available in Prometheus?
The server/metrics package exposes gauges and counters for total connected clients (frp_server_client_total), active proxies (frp_server_proxy_total), and traffic volume (frp_server_traffic_in_bytes and frp_server_traffic_out_bytes). These metrics update in real-time as clients connect and transmit data through the reverse proxy.
Can I expose the metrics endpoint on a different port than the web dashboard?
No. According to the current implementation in server/service.go, the Prometheus handler attaches to the same HTTP listener used by the dashboard UI. Both services share the address and port defined in the webServer configuration section.
Is the Prometheus metrics endpoint protected by dashboard authentication?
No. While the dashboard UI requires the credentials specified in webServer.user and webServer.password, the /metrics endpoint typically remains unauthenticated to allow Prometheus scrapers access without credential management. Verify your specific frp version behavior, as implementations may vary.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →