Merge pull request #179 from zhengyi13/add-bind-addr-support
Teach pihole-exporter how to bind to a specific interface.
This commit is contained in:
commit
5759f3ff42
4 changed files with 10 additions and 3 deletions
|
@ -195,6 +195,9 @@ scrape_configs:
|
|||
# WEBPASSWORD / api token defined on the PI-Hole interface at `/etc/pihole/setupVars.conf`
|
||||
-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 string (optional) (default "9617")
|
||||
```
|
||||
|
|
|
@ -24,6 +24,8 @@ type Config struct {
|
|||
PIHolePort uint16 `config:"pihole_port"`
|
||||
PIHolePassword string `config:"pihole_password"`
|
||||
PIHoleApiToken string `config:"pihole_api_token"`
|
||||
BindAddr string `config:"bind_addr"`
|
||||
Port uint16 `config:"port"`
|
||||
}
|
||||
|
||||
type EnvConfig struct {
|
||||
|
@ -32,6 +34,7 @@ type EnvConfig struct {
|
|||
PIHolePort []uint16 `config:"pihole_port"`
|
||||
PIHolePassword []string `config:"pihole_password"`
|
||||
PIHoleApiToken []string `config:"pihole_api_token"`
|
||||
BindAddr string `config:"bind_addr"`
|
||||
Port uint16 `config:"port"`
|
||||
Timeout time.Duration `config:"timeout"`
|
||||
}
|
||||
|
@ -43,6 +46,7 @@ func getDefaultEnvConfig() *EnvConfig {
|
|||
PIHolePort: []uint16{80},
|
||||
PIHolePassword: []string{},
|
||||
PIHoleApiToken: []string{},
|
||||
BindAddr: "0.0.0.0",
|
||||
Port: 9617,
|
||||
Timeout: 5 * time.Second,
|
||||
}
|
||||
|
|
|
@ -20,10 +20,10 @@ type Server struct {
|
|||
|
||||
// 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).
|
||||
func NewServer(port uint16, clients []*pihole.Client) *Server {
|
||||
func NewServer(addr string, port uint16, clients []*pihole.Client) *Server {
|
||||
mux := http.NewServeMux()
|
||||
httpServer := &http.Server{
|
||||
Addr: ":" + strconv.Itoa(int(port)),
|
||||
Addr: addr + ":" + strconv.Itoa(int(port)),
|
||||
Handler: mux,
|
||||
}
|
||||
|
||||
|
|
2
main.go
2
main.go
|
@ -22,7 +22,7 @@ func main() {
|
|||
|
||||
clients := buildClients(clientConfigs, envConf)
|
||||
|
||||
s := server.NewServer(envConf.Port, clients)
|
||||
s := server.NewServer(envConf.BindAddr, envConf.Port, clients)
|
||||
go func() {
|
||||
s.ListenAndServe()
|
||||
close(serverDead)
|
||||
|
|
Loading…
Reference in a new issue