mirror of
https://github.com/eko/pihole-exporter.git
synced 2024-11-26 11:55:26 +01:00
Teach pihole-exporter how to bind to a specific interface.
This commit is contained in:
parent
7095927491
commit
62f51680c5
@ -195,6 +195,9 @@ scrape_configs:
|
|||||||
# WEBPASSWORD / api token defined on the PI-Hole interface at `/etc/pihole/setupVars.conf`
|
# WEBPASSWORD / api token defined on the PI-Hole interface at `/etc/pihole/setupVars.conf`
|
||||||
-pihole_api_token string (optional)
|
-pihole_api_token string (optional)
|
||||||
|
|
||||||
|
# Address to be used for the exporter
|
||||||
|
-bind_addr string (optional) (default "0.0.0.0")
|
||||||
|
|
||||||
# Port to be used for the exporter
|
# Port to be used for the exporter
|
||||||
-port string (optional) (default "9617")
|
-port string (optional) (default "9617")
|
||||||
```
|
```
|
||||||
|
@ -24,6 +24,8 @@ type Config struct {
|
|||||||
PIHolePort uint16 `config:"pihole_port"`
|
PIHolePort uint16 `config:"pihole_port"`
|
||||||
PIHolePassword string `config:"pihole_password"`
|
PIHolePassword string `config:"pihole_password"`
|
||||||
PIHoleApiToken string `config:"pihole_api_token"`
|
PIHoleApiToken string `config:"pihole_api_token"`
|
||||||
|
BindAddr string `config:"bind_addr"`
|
||||||
|
Port uint16 `config:"port"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type EnvConfig struct {
|
type EnvConfig struct {
|
||||||
@ -32,6 +34,7 @@ type EnvConfig struct {
|
|||||||
PIHolePort []uint16 `config:"pihole_port"`
|
PIHolePort []uint16 `config:"pihole_port"`
|
||||||
PIHolePassword []string `config:"pihole_password"`
|
PIHolePassword []string `config:"pihole_password"`
|
||||||
PIHoleApiToken []string `config:"pihole_api_token"`
|
PIHoleApiToken []string `config:"pihole_api_token"`
|
||||||
|
BindAddr string `config:"bind_addr"`
|
||||||
Port uint16 `config:"port"`
|
Port uint16 `config:"port"`
|
||||||
Timeout time.Duration `config:"timeout"`
|
Timeout time.Duration `config:"timeout"`
|
||||||
}
|
}
|
||||||
@ -43,6 +46,7 @@ func getDefaultEnvConfig() *EnvConfig {
|
|||||||
PIHolePort: []uint16{80},
|
PIHolePort: []uint16{80},
|
||||||
PIHolePassword: []string{},
|
PIHolePassword: []string{},
|
||||||
PIHoleApiToken: []string{},
|
PIHoleApiToken: []string{},
|
||||||
|
BindAddr: "0.0.0.0",
|
||||||
Port: 9617,
|
Port: 9617,
|
||||||
Timeout: 5 * time.Second,
|
Timeout: 5 * time.Second,
|
||||||
}
|
}
|
||||||
|
@ -20,10 +20,10 @@ type Server struct {
|
|||||||
|
|
||||||
// NewServer method initializes a new HTTP server instance and associates
|
// NewServer method initializes a new HTTP server instance and associates
|
||||||
// the different routes that will be used by Prometheus (metrics) or for monitoring (readiness, liveness).
|
// the different routes that will be used by Prometheus (metrics) or for monitoring (readiness, liveness).
|
||||||
func NewServer(port uint16, clients []*pihole.Client) *Server {
|
func NewServer(addr string, port uint16, clients []*pihole.Client) *Server {
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
httpServer := &http.Server{
|
httpServer := &http.Server{
|
||||||
Addr: ":" + strconv.Itoa(int(port)),
|
Addr: addr + ":" + strconv.Itoa(int(port)),
|
||||||
Handler: mux,
|
Handler: mux,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
main.go
2
main.go
@ -22,7 +22,7 @@ func main() {
|
|||||||
|
|
||||||
clients := buildClients(clientConfigs, envConf)
|
clients := buildClients(clientConfigs, envConf)
|
||||||
|
|
||||||
s := server.NewServer(envConf.Port, clients)
|
s := server.NewServer(envConf.BindAddr, envConf.Port, clients)
|
||||||
go func() {
|
go func() {
|
||||||
s.ListenAndServe()
|
s.ListenAndServe()
|
||||||
close(serverDead)
|
close(serverDead)
|
||||||
|
Loading…
Reference in New Issue
Block a user