allow bind prometheus to a different interface than the ssh one.
This commit is contained in:
parent
55c96bb2c7
commit
fad9a4cded
2 changed files with 14 additions and 8 deletions
|
|
@ -52,7 +52,7 @@ Usage of ./endlessh-go
|
||||||
-geoip_supplier string
|
-geoip_supplier string
|
||||||
Supplier to obtain Geohash of IPs. Possible values are "off", "ip-api", "freegeoip", "max-mind-db" (default "off")
|
Supplier to obtain Geohash of IPs. Possible values are "off", "ip-api", "freegeoip", "max-mind-db" (default "off")
|
||||||
-host string
|
-host string
|
||||||
Listening address (default "0.0.0.0")
|
SSH listening address (default "0.0.0.0")
|
||||||
-interval_ms int
|
-interval_ms int
|
||||||
Message millisecond delay (default 1000)
|
Message millisecond delay (default 1000)
|
||||||
-line_length int
|
-line_length int
|
||||||
|
|
@ -68,9 +68,11 @@ Usage of ./endlessh-go
|
||||||
-max_mind_db string
|
-max_mind_db string
|
||||||
Path to the MaxMind DB file.
|
Path to the MaxMind DB file.
|
||||||
-port string
|
-port string
|
||||||
Listening port (default "2222")
|
SSH listening port (default "2222")
|
||||||
-prometheus_entry string
|
-prometheus_entry string
|
||||||
Entry point for prometheus (default "metrics")
|
Entry point for prometheus (default "metrics")
|
||||||
|
-prometheus_host string
|
||||||
|
The address for prometheus (default "0.0.0.0")
|
||||||
-prometheus_port string
|
-prometheus_port string
|
||||||
The port for prometheus (default "2112")
|
The port for prometheus (default "2112")
|
||||||
-stderrthreshold value
|
-stderrthreshold value
|
||||||
|
|
|
||||||
16
main.go
16
main.go
|
|
@ -44,7 +44,7 @@ var (
|
||||||
clientSeconds *prometheus.CounterVec
|
clientSeconds *prometheus.CounterVec
|
||||||
)
|
)
|
||||||
|
|
||||||
func initPrometheus(connHost, prometheusPort, prometheusEntry string) {
|
func initPrometheus(prometheusHost, prometheusPort, prometheusEntry string) {
|
||||||
totalClients = prometheus.NewCounterFunc(
|
totalClients = prometheus.NewCounterFunc(
|
||||||
prometheus.CounterOpts{
|
prometheus.CounterOpts{
|
||||||
Name: "endlessh_client_open_count_total",
|
Name: "endlessh_client_open_count_total",
|
||||||
|
|
@ -99,8 +99,8 @@ func initPrometheus(connHost, prometheusPort, prometheusEntry string) {
|
||||||
prometheus.MustRegister(clientSeconds)
|
prometheus.MustRegister(clientSeconds)
|
||||||
http.Handle("/"+prometheusEntry, promhttp.Handler())
|
http.Handle("/"+prometheusEntry, promhttp.Handler())
|
||||||
go func() {
|
go func() {
|
||||||
glog.Infof("Starting Prometheus on %v:%v, entry point is /%v", connHost, prometheusPort, prometheusEntry)
|
glog.Infof("Starting Prometheus on %v:%v, entry point is /%v", prometheusHost, prometheusPort, prometheusEntry)
|
||||||
http.ListenAndServe(connHost+":"+prometheusPort, nil)
|
http.ListenAndServe(prometheusHost+":"+prometheusPort, nil)
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -109,9 +109,10 @@ func main() {
|
||||||
bannerMaxLength := flag.Int64("line_length", 32, "Maximum banner line length")
|
bannerMaxLength := flag.Int64("line_length", 32, "Maximum banner line length")
|
||||||
maxClients := flag.Int64("max_clients", 4096, "Maximum number of clients")
|
maxClients := flag.Int64("max_clients", 4096, "Maximum number of clients")
|
||||||
connType := flag.String("conn_type", "tcp", "Connection type. Possible values are tcp, tcp4, tcp6")
|
connType := flag.String("conn_type", "tcp", "Connection type. Possible values are tcp, tcp4, tcp6")
|
||||||
connHost := flag.String("host", "0.0.0.0", "Listening address")
|
connHost := flag.String("host", "0.0.0.0", "SSH listening address")
|
||||||
connPort := flag.String("port", "2222", "Listening port")
|
connPort := flag.String("port", "2222", "SSH listening port")
|
||||||
prometheusEnabled := flag.Bool("enable_prometheus", false, "Enable prometheus")
|
prometheusEnabled := flag.Bool("enable_prometheus", 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")
|
prometheusPort := flag.String("prometheus_port", "2112", "The port for prometheus")
|
||||||
prometheusEntry := flag.String("prometheus_entry", "metrics", "Entry point for prometheus")
|
prometheusEntry := flag.String("prometheus_entry", "metrics", "Entry point for prometheus")
|
||||||
geoipSupplier := flag.String("geoip_supplier", "off", "Supplier to obtain Geohash of IPs. Possible values are \"off\", \"ip-api\", \"freegeoip\", \"max-mind-db\"")
|
geoipSupplier := flag.String("geoip_supplier", "off", "Supplier to obtain Geohash of IPs. Possible values are \"off\", \"ip-api\", \"freegeoip\", \"max-mind-db\"")
|
||||||
|
|
@ -123,8 +124,11 @@ func main() {
|
||||||
}
|
}
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
if *connType == "tcp6" && *prometheusHost == "0.0.0.0" {
|
||||||
|
*prometheusHost = "[::]"
|
||||||
|
}
|
||||||
if *prometheusEnabled {
|
if *prometheusEnabled {
|
||||||
initPrometheus(*connHost, *prometheusPort, *prometheusEntry)
|
initPrometheus(*prometheusHost, *prometheusPort, *prometheusEntry)
|
||||||
}
|
}
|
||||||
|
|
||||||
rand.Seed(time.Now().UnixNano())
|
rand.Seed(time.Now().UnixNano())
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue