try multiple addresses

This commit is contained in:
Josh Deprez 2021-02-07 17:52:20 +11:00
parent ad38fcaf8d
commit fbfda3b144

View file

@ -8,6 +8,7 @@ import (
"fmt"
"log"
"net/http"
"strings"
"time"
"github.com/DrJosh9000/sungrow/modbus"
@ -18,7 +19,7 @@ import (
var (
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")
registerGauges = make(map[uint16]prometheus.Gauge)
@ -137,11 +138,14 @@ func main() {
flag.Parse()
// Is the inverter reachable?
sgc, err := dialSungrow(*inverterAddr)
for _, addr := range strings.Split(*inverterAddrs, ",") {
sgc, err := dialSungrow(addr)
if err != nil {
log.Fatalf("Couldn't dial inverter: %v", err)
}
defer sgc.Close()
break
}
// HTTP setup
http.Handle("/metrics", promhttp.Handler())