Read config JSON only if there is any

This commit is contained in:
Thomas Roehl 2021-11-26 18:19:45 +01:00
parent 8d643bb5e8
commit cb8221e73c

View File

@ -13,7 +13,7 @@ import (
const NETSTATFILE = `/proc/net/dev` const NETSTATFILE = `/proc/net/dev`
type NetstatCollectorConfig struct { type NetstatCollectorConfig struct {
ExcludeDevices []string `json:"exclude_devices, omitempty"` ExcludeDevices []string `json:"exclude_devices"`
} }
type NetstatCollector struct { type NetstatCollector struct {
@ -31,10 +31,12 @@ func (m *NetstatCollector) Init(config []byte) error {
2: "pkts_in", 2: "pkts_in",
10: "pkts_out", 10: "pkts_out",
} }
err := json.Unmarshal(config, &m.config) if len(config) > 0 {
if err != nil { err := json.Unmarshal(config, &m.config)
log.Print(err.Error()) if err != nil {
return err log.Print(err.Error())
return err
}
} }
_, err = ioutil.ReadFile(string(NETSTATFILE)) _, err = ioutil.ReadFile(string(NETSTATFILE))
if err == nil { if err == nil {