Add prometheus_enable flag and fallback from enable_prometheus

This commit is contained in:
Shizun Ge
2026-07-24 19:13:22 -07:00
parent 5d534c0890
commit 484c7fa794
4 changed files with 21 additions and 7 deletions
+4 -2
View File
@@ -55,7 +55,7 @@ Usage of ./endlessh-go
-conn_type string
Connection type. Possible values are tcp, tcp4, tcp6 (default "tcp")
-enable_prometheus
Enable prometheus
Enable prometheus (deprecated, use prometheus_enable)
-geoip_supplier string
Supplier to obtain Geohash of IPs. Possible values are "off", "ip-api", "max-mind-db" (default "off")
-healthcheck
@@ -90,6 +90,8 @@ Usage of ./endlessh-go
SSH listening port. You may provide multiple -port flags to listen to multiple ports. (default "2222")
-prometheus_clean_unseen_seconds int
Remove series if the IP is not seen for the given time. Set to 0 to disable. (default 0)
-prometheus_enable
Enable prometheus
-prometheus_entry string
Entry point for prometheus (default "metrics")
-prometheus_host string
@@ -121,7 +123,7 @@ Endlessh-go exports the following Prometheus metrics.
| endlessh_client_open_count | count | Number of connections of clients. <br> Labels: <br> <ul><li> `ip`: Remote IP of the client </li> <li> `local_port`: Local port the program listens to </li> <li> `country`: Country of the IP </li> <li> `location`: Country, Region, and City </li> <li> `geohash`: Geohash of the location </li></ul> |
| endlessh_client_trapped_time_seconds | count | Seconds a client spends on endlessh. <br> Labels: <br> <ul><li> `ip`: Remote IP of the client </li> <li> `local_port`: Local port the program listens to </li></ul> |
The metrics is off by default, you can turn it via the CLI argument `-enable_prometheus`.
The metrics is off by default, you can turn it via the CLI argument `-prometheus_enable`.
It listens to port `2112` and entry point is `/metrics` by default. The port and entry point can be changed via CLI arguments.
+1 -1
View File
@@ -8,7 +8,7 @@ services:
- -interval_ms=1000
- -logtostderr
- -v=1
- -enable_prometheus
- -prometheus_enable
- -geoip_supplier=ip-api
networks:
- example_network
+1 -1
View File
@@ -14,7 +14,7 @@ spec:
- -interval_ms=1000
- -logtostderr
- -v=1
- -enable_prometheus
- -prometheus_enable
- -geoip_supplier=ip-api
- -host=[::]
- -prometheus_host=[::]
+15 -3
View File
@@ -144,7 +144,8 @@ func main() {
proxyProtocolReadHeaderTimeout := flag.Int("proxy_protocol_read_header_timeout_ms", 200, "Timeout for reading the PROXY protocol header in milliseconds. If the connection does not send a valid PROXY protocol header in this time, the header is ignored.")
// Prometheus metrics flags
prometheusEnabled := flag.Bool("enable_prometheus", false, "Enable prometheus")
prometheusEnabledOld := flag.Bool("enable_prometheus", false, "Enable prometheus (deprecated, use prometheus_enable)")
prometheusEnabledNew := flag.Bool("prometheus_enable", false, "Enable prometheus")
prometheusHost := flag.String("prometheus_host", "0.0.0.0", "The address for prometheus")
prometheusPort := flag.String("prometheus_port", "2112", "The port for prometheus")
prometheusEntry := flag.String("prometheus_entry", "metrics", "Entry point for prometheus")
@@ -173,7 +174,18 @@ func main() {
os.Exit(0)
}
if *prometheusEnabled {
prometheusEnabled := *prometheusEnabledNew
prometheusEnableSet := false
flag.Visit(func(f *flag.Flag) {
if f.Name == "prometheus_enable" {
prometheusEnableSet = true
}
})
if !prometheusEnableSet {
prometheusEnabled = *prometheusEnabledOld
}
if prometheusEnabled {
if *connType == "tcp6" && *prometheusHost == "0.0.0.0" {
*prometheusHost = "[::]"
}
@@ -189,7 +201,7 @@ func main() {
metrics.InitPrometheus(*prometheusHost, *prometheusPort, *prometheusEntry)
}
records := metrics.StartRecording(*maxClients, *prometheusEnabled, *prometheusCleanUnseenSeconds,
records := metrics.StartRecording(*maxClients, prometheusEnabled, *prometheusCleanUnseenSeconds,
geoip.GeoOption{
GeoipSupplier: *geoipSupplier,
MaxMindDbFileName: *maxMindDbFileName,