try multiple addresses
This commit is contained in:
parent
ad38fcaf8d
commit
fbfda3b144
1 changed files with 9 additions and 5 deletions
14
main.go
14
main.go
|
@ -8,6 +8,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/DrJosh9000/sungrow/modbus"
|
"github.com/DrJosh9000/sungrow/modbus"
|
||||||
|
@ -18,7 +19,7 @@ import (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
httpAddr = flag.String("http-addr", ":9455", "Address to listen on")
|
httpAddr = flag.String("http-addr", ":9455", "Address to listen on")
|
||||||
inverterAddr = flag.String("inverter-addr", "rakmodule_00DBC1:502", "Address of inverter")
|
inverterAddrs = flag.String("inverter-addrs", "rakmodule_00DBC1:502,192.168.86.6:502", "Comma-separated list of inverter addresses (modbus-tcp with 'encryption')")
|
||||||
scrapeInterval = flag.Duration("scrape-interval", 15*time.Second, "Period of modbus scraping loop")
|
scrapeInterval = flag.Duration("scrape-interval", 15*time.Second, "Period of modbus scraping loop")
|
||||||
|
|
||||||
registerGauges = make(map[uint16]prometheus.Gauge)
|
registerGauges = make(map[uint16]prometheus.Gauge)
|
||||||
|
@ -137,11 +138,14 @@ func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
// Is the inverter reachable?
|
// Is the inverter reachable?
|
||||||
sgc, err := dialSungrow(*inverterAddr)
|
for _, addr := range strings.Split(*inverterAddrs, ",") {
|
||||||
if err != nil {
|
sgc, err := dialSungrow(addr)
|
||||||
log.Fatalf("Couldn't dial inverter: %v", err)
|
if err != nil {
|
||||||
|
log.Fatalf("Couldn't dial inverter: %v", err)
|
||||||
|
}
|
||||||
|
defer sgc.Close()
|
||||||
|
break
|
||||||
}
|
}
|
||||||
defer sgc.Close()
|
|
||||||
|
|
||||||
// HTTP setup
|
// HTTP setup
|
||||||
http.Handle("/metrics", promhttp.Handler())
|
http.Handle("/metrics", promhttp.Handler())
|
||||||
|
|
Loading…
Reference in a new issue