From e9d7d50f2b49a22d25a91e53a7df9d10e6e73db1 Mon Sep 17 00:00:00 2001 From: Ulric Qin Date: Mon, 11 Jul 2022 12:30:49 +0800 Subject: [PATCH] modify default settings --- conf/input.exec/exec.toml | 6 ++-- conf/input.http_response/http_response.toml | 6 ++-- conf/input.kafka/kafka.toml | 3 +- conf/input.kubernetes/kubernetes.toml | 5 +-- conf/input.mysql/mysql.toml | 2 +- conf/input.net_response/net_response.toml | 6 ++-- conf/input.nvidia_smi/nvidia_smi.toml | 3 +- conf/input.oracle/oracle.toml | 2 +- conf/input.ping/ping.toml | 6 ++-- conf/input.prometheus/prometheus.toml | 26 +++++++-------- conf/input.rabbitmq/rabbitmq.toml | 2 +- conf/input.redis/redis.toml | 2 +- conf/input.switch_legacy/switch_legacy.toml | 6 ++-- conf/input.tomcat/tomcat.toml | 3 +- conf/input.zookeeper/zookeeper.toml | 2 +- inputs/exec/exec.go | 6 ++++ inputs/http_response/http_response.go | 12 ++++--- inputs/kafka/kafka.go | 7 +++- inputs/kubernetes/kubernetes.go | 29 ++++++++-------- inputs/mysql/mysql.go | 6 ++-- inputs/net_response/net_response.go | 5 ++- .../nginx_upstream_check.go | 12 ++++--- inputs/nvidia_smi/nvidia_smi.go | 3 +- inputs/oracle/oracle_linux_amd64.go | 5 ++- inputs/ping/ping.go | 7 ++++ inputs/prometheus/prometheus.go | 33 +++++++++++++++---- inputs/rabbitmq/rabbitmq.go | 7 ++-- inputs/redis/redis.go | 7 ++++ inputs/switch_legacy/switch_legacy.go | 13 ++++++-- inputs/tomcat/tomcat.go | 6 ++-- inputs/zookeeper/zookeeper.go | 4 +++ 31 files changed, 161 insertions(+), 81 deletions(-) diff --git a/conf/input.exec/exec.toml b/conf/input.exec/exec.toml index 3acfa4dd..ca34712a 100644 --- a/conf/input.exec/exec.toml +++ b/conf/input.exec/exec.toml @@ -1,11 +1,11 @@ # # collect interval # interval = 15 -# [[instances]] +[[instances]] # # commands, support glob -# commands = [ +commands = [ # "/opt/categraf/scripts/*.sh" -# ] +] # # timeout for each command to complete # timeout = 5 diff --git a/conf/input.http_response/http_response.toml b/conf/input.http_response/http_response.toml index 66619dc8..2c8914cf 100644 --- a/conf/input.http_response/http_response.toml +++ b/conf/input.http_response/http_response.toml @@ -1,11 +1,11 @@ # # collect interval # interval = 15 -# [[instances]] -# targets = [ +[[instances]] +targets = [ # "http://localhost", # "https://www.baidu.com" -# ] +] # # append some labels for series # labels = { region="cloud", product="n9e" } diff --git a/conf/input.kafka/kafka.toml b/conf/input.kafka/kafka.toml index 9c31420d..2cac4523 100644 --- a/conf/input.kafka/kafka.toml +++ b/conf/input.kafka/kafka.toml @@ -15,7 +15,8 @@ labels = { cluster="kafka-cluster-01" } log_level = "error" # Address (host:port) of Kafka server. -kafka_uris = ["127.0.0.1:9092","127.0.0.1:9092","127.0.0.1:9092"] +# kafka_uris = ["127.0.0.1:9092","127.0.0.1:9092","127.0.0.1:9092"] +kafka_uris = [] # Connect using SASL/PLAIN # Default is false diff --git a/conf/input.kubernetes/kubernetes.toml b/conf/input.kubernetes/kubernetes.toml index 141daa78..1f86d066 100644 --- a/conf/input.kubernetes/kubernetes.toml +++ b/conf/input.kubernetes/kubernetes.toml @@ -1,7 +1,7 @@ # # collect interval # interval = 15 -# [[instances]] +[[instances]] # # append some labels for series # labels = { region="cloud", product="n9e" } @@ -9,7 +9,8 @@ # interval_times = 1 # URL for the kubelet -url = "https://$HOSTIP:10250" +# url = "https://$HOSTIP:10250" +url = "" gather_system_container_metrics = true gather_node_metrics = true diff --git a/conf/input.mysql/mysql.toml b/conf/input.mysql/mysql.toml index 2a478e02..05b0f413 100644 --- a/conf/input.mysql/mysql.toml +++ b/conf/input.mysql/mysql.toml @@ -1,7 +1,7 @@ # # collect interval # interval = 15 -# [[instances]] +[[instances]] # address = "127.0.0.1:3306" # username = "root" # password = "1234" diff --git a/conf/input.net_response/net_response.toml b/conf/input.net_response/net_response.toml index 9f2546de..52cd9d73 100644 --- a/conf/input.net_response/net_response.toml +++ b/conf/input.net_response/net_response.toml @@ -1,12 +1,12 @@ # # collect interval # interval = 15 -# [[instances]] -# targets = [ +[[instances]] +targets = [ # "127.0.0.1:22", # "localhost:6379", # ":9090" -# ] +] # # append some labels for series # labels = { region="cloud", product="n9e" } diff --git a/conf/input.nvidia_smi/nvidia_smi.toml b/conf/input.nvidia_smi/nvidia_smi.toml index d0082d2e..fcff6d18 100644 --- a/conf/input.nvidia_smi/nvidia_smi.toml +++ b/conf/input.nvidia_smi/nvidia_smi.toml @@ -2,7 +2,8 @@ # interval = 15 # exec local command -# nvidia_smi_command = "nvidia-smi" +# e.g. nvidia_smi_command = "nvidia-smi" +nvidia_smi_command = "" # exec remote command # nvidia_smi_command = "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null SSH_USER@SSH_HOST nvidia-smi" diff --git a/conf/input.oracle/oracle.toml b/conf/input.oracle/oracle.toml index 08572aab..daf85b2b 100644 --- a/conf/input.oracle/oracle.toml +++ b/conf/input.oracle/oracle.toml @@ -1,7 +1,7 @@ # # collect interval # interval = 15 -# [[instances]] +[[instances]] # address = "10.1.2.3:1521/orcl" # username = "monitor" # password = "123456" diff --git a/conf/input.ping/ping.toml b/conf/input.ping/ping.toml index 8d6ae779..ef92b462 100644 --- a/conf/input.ping/ping.toml +++ b/conf/input.ping/ping.toml @@ -1,14 +1,14 @@ # # collect interval # interval = 15 -# [[instances]] +[[instances]] # send ping packets to -# targets = [ +targets = [ # "www.baidu.com", # "127.0.0.1", # "10.4.5.6", # "10.4.5.7" -# ] +] # # append some labels for series # labels = { region="cloud", product="n9e" } diff --git a/conf/input.prometheus/prometheus.toml b/conf/input.prometheus/prometheus.toml index 030173cf..b3691ede 100644 --- a/conf/input.prometheus/prometheus.toml +++ b/conf/input.prometheus/prometheus.toml @@ -2,25 +2,25 @@ # interval = 15 [[instances]] -# urls = [ +urls = [ # "http://localhost:9104/metrics" -# ] +] url_label_key = "instance" url_label_value = "{{.Host}}" ## Scrape Services available in Consul Catalog -[instances.consul] - enabled = false - agent = "http://localhost:8500" - query_interval = "5m" - - [[instances.consul.query]] - name = "a service name" - tag = "a service tag" - url = 'http://{{if ne .ServiceAddress ""}}{{.ServiceAddress}}{{else}}{{.Address}}{{end}}:{{.ServicePort}}/{{with .ServiceMeta.metrics_path}}{{.}}{{else}}metrics{{end}}' - [instances.consul.query.tags] - host = "{{.Node}}" +# [instances.consul] +# enabled = false +# agent = "http://localhost:8500" +# query_interval = "5m" + +# [[instances.consul.query]] +# name = "a service name" +# tag = "a service tag" +# url = 'http://{{if ne .ServiceAddress ""}}{{.ServiceAddress}}{{else}}{{.Address}}{{end}}:{{.ServicePort}}/{{with .ServiceMeta.metrics_path}}{{.}}{{else}}metrics{{end}}' +# [instances.consul.query.tags] +# host = "{{.Node}}" # bearer_token_string = "" diff --git a/conf/input.rabbitmq/rabbitmq.toml b/conf/input.rabbitmq/rabbitmq.toml index 8e9a016f..41b9707b 100644 --- a/conf/input.rabbitmq/rabbitmq.toml +++ b/conf/input.rabbitmq/rabbitmq.toml @@ -11,7 +11,7 @@ # # collect interval # interval = 15 -# [[instances]] +[[instances]] # # Management Plugin url # url = "http://localhost:15672" # username = "guest" diff --git a/conf/input.redis/redis.toml b/conf/input.redis/redis.toml index d91f001c..bd5c0261 100644 --- a/conf/input.redis/redis.toml +++ b/conf/input.redis/redis.toml @@ -1,7 +1,7 @@ # # collect interval # interval = 15 -# [[instances]] +[[instances]] # address = "127.0.0.1:6379" # username = "" # password = "" diff --git a/conf/input.switch_legacy/switch_legacy.toml b/conf/input.switch_legacy/switch_legacy.toml index 1f69da18..d7895305 100644 --- a/conf/input.switch_legacy/switch_legacy.toml +++ b/conf/input.switch_legacy/switch_legacy.toml @@ -7,18 +7,18 @@ switch_id_label = "ip" "192.168.88.160" = "switch001.bj" "192.168.88.161" = "switch002.bj" -# [[instances]] +[[instances]] # # interval = global.interval * interval_times # interval_times = 1 # use global unique string to specify instance # labels = { region="beijing" } -# ips = [ +ips = [ # "172.16.2.1", # "172.16.4/24", # "192.168.56.102-192.168.56.120" -# ] +] community = "public" diff --git a/conf/input.tomcat/tomcat.toml b/conf/input.tomcat/tomcat.toml index 97638997..8aed7600 100644 --- a/conf/input.tomcat/tomcat.toml +++ b/conf/input.tomcat/tomcat.toml @@ -2,9 +2,10 @@ # interval = 15 # Gather metrics from the Tomcat server status page. -# [[instances]] +[[instances]] ## URL of the Tomcat server status # url = "http://127.0.0.1:8080/manager/status/all?XML=true" +url = "" ## HTTP Basic Auth Credentials # username = "tomcat" diff --git a/conf/input.zookeeper/zookeeper.toml b/conf/input.zookeeper/zookeeper.toml index f60678bb..e96bf6cc 100644 --- a/conf/input.zookeeper/zookeeper.toml +++ b/conf/input.zookeeper/zookeeper.toml @@ -1,7 +1,7 @@ # # collect interval # interval = 15 -# [[instances]] +[[instances]] # cluster_name = "dev-zk-cluster" # addresses = "127.0.0.1:2181" # timeout = 10 diff --git a/inputs/exec/exec.go b/inputs/exec/exec.go index beb61e1c..b7131b5c 100644 --- a/inputs/exec/exec.go +++ b/inputs/exec/exec.go @@ -59,6 +59,9 @@ func (e *Exec) Init() error { } for i := 0; i < len(e.Instances); i++ { + if len(e.Instances[i].Commands) == 0 { + continue + } if e.Instances[i].DataFormat == "" || e.Instances[i].DataFormat == "influx" { e.Instances[i].parser = influx.NewParser() } else if e.Instances[i].DataFormat == "falcon" { @@ -82,6 +85,9 @@ func (e *Exec) Gather(slist *list.SafeList) { wg.Add(len(e.Instances)) for i := range e.Instances { ins := e.Instances[i] + if len(ins.Commands) == 0 { + continue + } go e.GatherOnce(&wg, slist, ins) } diff --git a/inputs/http_response/http_response.go b/inputs/http_response/http_response.go index e2089aa2..439def43 100644 --- a/inputs/http_response/http_response.go +++ b/inputs/http_response/http_response.go @@ -1,7 +1,6 @@ package http_response import ( - "errors" "fmt" "io" "io/ioutil" @@ -59,6 +58,10 @@ type httpClient interface { } func (ins *Instance) Init() error { + if len(ins.Targets) == 0 { + return nil + } + if ins.ResponseTimeout < config.Duration(time.Second) { ins.ResponseTimeout = config.Duration(time.Second * 3) } @@ -67,10 +70,6 @@ func (ins *Instance) Init() error { ins.Method = "GET" } - if len(ins.Targets) == 0 { - return errors.New("http_response targets empty") - } - client, err := ins.createHTTPClient() if err != nil { return fmt.Errorf("failed to create http client: %v", err) @@ -174,6 +173,9 @@ func (h *HTTPResponse) Gather(slist *list.SafeList) { atomic.AddUint64(&h.Counter, 1) for i := range h.Instances { ins := h.Instances[i] + if len(ins.Targets) == 0 { + continue + } h.wg.Add(1) go h.gatherOnce(slist, ins) } diff --git a/inputs/kafka/kafka.go b/inputs/kafka/kafka.go index 6da87129..b3ef6e8a 100644 --- a/inputs/kafka/kafka.go +++ b/inputs/kafka/kafka.go @@ -70,6 +70,10 @@ func (r *Kafka) Gather(slist *list.SafeList) { for i := range r.Instances { ins := r.Instances[i] + if len(ins.KafkaURIs) == 0 { + continue + } + r.waitgrp.Add(1) go func(slist *list.SafeList, ins *Instance) { defer r.waitgrp.Done() @@ -159,8 +163,9 @@ type Instance struct { func (ins *Instance) Init() error { if len(ins.KafkaURIs) == 0 || ins.KafkaURIs[0] == "" { - return fmt.Errorf("kafka_uris must be specified") + return nil } + if ins.UseTLS && (ins.CertFile == "" || ins.KeyFile == "") { return fmt.Errorf("tls is enabled but key pair was not provided") } diff --git a/inputs/kubernetes/kubernetes.go b/inputs/kubernetes/kubernetes.go index 778b1edb..b5a177e1 100644 --- a/inputs/kubernetes/kubernetes.go +++ b/inputs/kubernetes/kubernetes.go @@ -2,7 +2,6 @@ package kubernetes import ( "encoding/json" - "errors" "fmt" "log" "net/http" @@ -64,6 +63,10 @@ func (k *Kubernetes) Gather(slist *list.SafeList) { for i := range k.Instances { ins := k.Instances[i] + if ins.URL == "" { + continue + } + k.waitgrp.Add(1) go func(slist *list.SafeList, ins *Instance) { defer k.waitgrp.Done() @@ -113,7 +116,7 @@ type Instance struct { func (ins *Instance) Init() error { if ins.URL == "" { - return errors.New("url is blank") + return nil } ins.URL = os.Expand(ins.URL, config.GetEnv) @@ -185,10 +188,10 @@ func (ins *Instance) buildPodMetrics(summaryMetrics *SummaryMetrics, podInfo []M if ins.GatherPodContainerMetrics { for _, container := range pod.Containers { tags := map[string]string{ - "node": summaryMetrics.Node.NodeName, - "namespace": pod.PodRef.Namespace, - "container": container.Name, - "pod": pod.PodRef.Name, + "node": summaryMetrics.Node.NodeName, + "namespace": pod.PodRef.Namespace, + "container": container.Name, + "pod": pod.PodRef.Name, } for k, v := range podLabels { tags[k] = v @@ -214,10 +217,10 @@ func (ins *Instance) buildPodMetrics(summaryMetrics *SummaryMetrics, podInfo []M if ins.GatherPodVolumeMetrics { for _, volume := range pod.Volumes { tags := map[string]string{ - "node": summaryMetrics.Node.NodeName, - "pod": pod.PodRef.Name, - "namespace": pod.PodRef.Namespace, - "volume": volume.Name, + "node": summaryMetrics.Node.NodeName, + "pod": pod.PodRef.Name, + "namespace": pod.PodRef.Namespace, + "volume": volume.Name, } for k, v := range podLabels { tags[k] = v @@ -252,8 +255,8 @@ func (ins *Instance) buildPodMetrics(summaryMetrics *SummaryMetrics, podInfo []M func (ins *Instance) buildSystemContainerMetrics(summaryMetrics *SummaryMetrics, slist *list.SafeList) { for _, container := range summaryMetrics.Node.SystemContainers { tags := map[string]string{ - "node": summaryMetrics.Node.NodeName, - "container": container.Name, + "node": summaryMetrics.Node.NodeName, + "container": container.Name, } fields := make(map[string]interface{}) @@ -275,7 +278,7 @@ func (ins *Instance) buildSystemContainerMetrics(summaryMetrics *SummaryMetrics, func (ins *Instance) buildNodeMetrics(summaryMetrics *SummaryMetrics, slist *list.SafeList) { tags := map[string]string{ - "node": summaryMetrics.Node.NodeName, + "node": summaryMetrics.Node.NodeName, } fields := make(map[string]interface{}) fields["node_cpu_usage_nanocores"] = summaryMetrics.Node.CPU.UsageNanoCores diff --git a/inputs/mysql/mysql.go b/inputs/mysql/mysql.go index 49135206..2e1f20de 100644 --- a/inputs/mysql/mysql.go +++ b/inputs/mysql/mysql.go @@ -2,7 +2,6 @@ package mysql import ( "database/sql" - "errors" "fmt" "log" "sync" @@ -55,7 +54,7 @@ type Instance struct { func (ins *Instance) Init() error { if ins.Address == "" { - return errors.New("address is blank") + return nil } if ins.UseTLS { @@ -189,6 +188,9 @@ func (m *MySQL) Gather(slist *list.SafeList) { atomic.AddUint64(&m.Counter, 1) for i := range m.Instances { ins := m.Instances[i] + if len(ins.Address) == 0 { + continue + } m.wg.Add(1) go m.gatherOnce(slist, ins) } diff --git a/inputs/net_response/net_response.go b/inputs/net_response/net_response.go index 0820e2c6..1fe1176b 100644 --- a/inputs/net_response/net_response.go +++ b/inputs/net_response/net_response.go @@ -41,7 +41,7 @@ type Instance struct { func (ins *Instance) Init() error { if len(ins.Targets) == 0 { - return errors.New("targets empty") + return nil } if ins.Protocol == "" { @@ -121,6 +121,9 @@ func (n *NetResponse) Gather(slist *list.SafeList) { atomic.AddUint64(&n.Counter, 1) for i := range n.Instances { ins := n.Instances[i] + if len(ins.Targets) == 0 { + continue + } n.wg.Add(1) go n.gatherOnce(slist, ins) } diff --git a/inputs/nginx_upstream_check/nginx_upstream_check.go b/inputs/nginx_upstream_check/nginx_upstream_check.go index accf59dc..4d3f44d7 100644 --- a/inputs/nginx_upstream_check/nginx_upstream_check.go +++ b/inputs/nginx_upstream_check/nginx_upstream_check.go @@ -62,6 +62,10 @@ func (r *NginxUpstreamCheck) Gather(slist *list.SafeList) { for i := range r.Instances { ins := r.Instances[i] + if len(ins.Targets) == 0 { + continue + } + r.waitgrp.Add(1) go func(slist *list.SafeList, ins *Instance) { defer r.waitgrp.Done() @@ -103,6 +107,10 @@ type httpClient interface { } func (ins *Instance) Init() error { + if len(ins.Targets) == 0 { + return nil + } + if ins.Timeout < config.Duration(time.Second) { ins.Timeout = config.Duration(time.Second * 5) } @@ -111,10 +119,6 @@ func (ins *Instance) Init() error { ins.Method = "GET" } - if len(ins.Targets) == 0 { - return types.ErrInstancesEmpty - } - client, err := ins.createHTTPClient() if err != nil { return fmt.Errorf("failed to create http client: %v", err) diff --git a/inputs/nvidia_smi/nvidia_smi.go b/inputs/nvidia_smi/nvidia_smi.go index 5efcd7e5..c17dc85a 100644 --- a/inputs/nvidia_smi/nvidia_smi.go +++ b/inputs/nvidia_smi/nvidia_smi.go @@ -39,8 +39,7 @@ func (s *GPUStats) Drop() {} func (s *GPUStats) Init() error { if s.NvidiaSmiCommand == "" { - // do nothing - return nil + return types.ErrInstancesEmpty } qFieldsOrdered, qFieldToRFieldMap, err := buildQFieldToRFieldMap(s.QueryFieldNames, s.NvidiaSmiCommand) diff --git a/inputs/oracle/oracle_linux_amd64.go b/inputs/oracle/oracle_linux_amd64.go index ef69baf8..ebdd7925 100644 --- a/inputs/oracle/oracle_linux_amd64.go +++ b/inputs/oracle/oracle_linux_amd64.go @@ -76,7 +76,7 @@ func (o *Oracle) Init() error { for i := 0; i < len(o.Instances); i++ { dbConf := o.Instances[i] if dbConf.Address == "" { - return fmt.Errorf("some oracle address is blank") + continue } connString := getConnectionString(dbConf) db, err := sqlx.Open("godror", connString) @@ -105,6 +105,9 @@ func (o *Oracle) Gather(slist *list.SafeList) { atomic.AddUint64(&o.Counter, 1) for i := range o.Instances { ins := o.Instances[i] + if ins.Address == "" { + continue + } o.wg.Add(1) go o.gatherOnce(slist, ins) } diff --git a/inputs/ping/ping.go b/inputs/ping/ping.go index 0169de83..4298a6f9 100644 --- a/inputs/ping/ping.go +++ b/inputs/ping/ping.go @@ -39,6 +39,10 @@ type Instance struct { } func (ins *Instance) Init() error { + if len(ins.Targets) == 0 { + return nil + } + if ins.Count < 1 { ins.Count = 1 } @@ -113,6 +117,9 @@ func (p *Ping) Gather(slist *list.SafeList) { atomic.AddUint64(&p.Counter, 1) for i := range p.Instances { ins := p.Instances[i] + if len(ins.Targets) == 0 { + continue + } p.wg.Add(1) go p.gatherOnce(slist, ins) } diff --git a/inputs/prometheus/prometheus.go b/inputs/prometheus/prometheus.go index 791c1e6c..62971f49 100644 --- a/inputs/prometheus/prometheus.go +++ b/inputs/prometheus/prometheus.go @@ -1,6 +1,7 @@ package prometheus import ( + "errors" "io" "log" "net/http" @@ -46,17 +47,29 @@ type Instance struct { client *http.Client } +func (ins *Instance) Empty() bool { + if len(ins.URLs) > 0 { + return false + } + + if ins.ConsulConfig.Enabled && len(ins.ConsulConfig.Queries) > 0 { + return false + } + + return true +} + func (ins *Instance) Init() error { - if ins.ConsulConfig.Enabled { - if len(ins.ConsulConfig.Queries) == 0 { - return types.ErrInstancesEmpty - } + if ins.Empty() { + return nil + } + + if ins.ConsulConfig.Enabled && len(ins.ConsulConfig.Queries) > 0 { if err := ins.InitConsulClient(); err != nil { return err } - } else if len(ins.URLs) == 0 { - return types.ErrInstancesEmpty } + for i, u := range ins.URLs { ins.URLs[i] = strings.Replace(u, "$hostname", config.Config.GetHostname(), -1) ins.URLs[i] = strings.Replace(u, "$ip", config.Config.Global.IP, -1) @@ -139,7 +152,9 @@ func (p *Prometheus) Init() error { for i := 0; i < len(p.Instances); i++ { if err := p.Instances[i].Init(); err != nil { - return err + if !errors.Is(err, types.ErrInstancesEmpty) { + return err + } } } @@ -154,6 +169,10 @@ func (p *Prometheus) Gather(slist *list.SafeList) { for i := range p.Instances { ins := p.Instances[i] + if ins.Empty() { + continue + } + p.waitgrp.Add(1) go func(slist *list.SafeList, ins *Instance) { defer p.waitgrp.Done() diff --git a/inputs/rabbitmq/rabbitmq.go b/inputs/rabbitmq/rabbitmq.go index aff21a91..813c3a23 100644 --- a/inputs/rabbitmq/rabbitmq.go +++ b/inputs/rabbitmq/rabbitmq.go @@ -2,7 +2,6 @@ package rabbitmq import ( "encoding/json" - "errors" "fmt" "io" "log" @@ -60,6 +59,10 @@ func (r *RabbitMQ) Gather(slist *list.SafeList) { for i := range r.Instances { ins := r.Instances[i] + if ins.URL == "" { + continue + } + r.waitgrp.Add(1) go func(slist *list.SafeList, ins *Instance) { defer r.waitgrp.Done() @@ -111,7 +114,7 @@ type Instance struct { func (ins *Instance) Init() error { if ins.URL == "" { - return errors.New("url is blank") + return nil } var err error diff --git a/inputs/redis/redis.go b/inputs/redis/redis.go index 9f3a4ffa..184886e2 100644 --- a/inputs/redis/redis.go +++ b/inputs/redis/redis.go @@ -44,6 +44,10 @@ type Instance struct { } func (ins *Instance) Init() error { + if ins.Address == "" { + return nil + } + redisOptions := &redis.Options{ Addr: ins.Address, Username: ins.Username, @@ -107,6 +111,9 @@ func (r *Redis) Gather(slist *list.SafeList) { atomic.AddUint64(&r.Counter, 1) for i := range r.Instances { ins := r.Instances[i] + if ins.Address == "" { + continue + } r.wg.Add(1) go r.gatherOnce(slist, ins) } diff --git a/inputs/switch_legacy/switch_legacy.go b/inputs/switch_legacy/switch_legacy.go index 71f72b56..b0dbfdcc 100644 --- a/inputs/switch_legacy/switch_legacy.go +++ b/inputs/switch_legacy/switch_legacy.go @@ -64,6 +64,10 @@ func (s *Switch) Gather(slist *list.SafeList) { for i := range s.Instances { ins := s.Instances[i] + if len(ins.IPs) == 0 { + continue + } + s.waitgrp.Add(1) go func(slist *list.SafeList, ins *Instance) { defer s.waitgrp.Done() @@ -138,6 +142,10 @@ type Custom struct { } func (ins *Instance) Init() error { + if len(ins.IPs) == 0 { + return nil + } + ips := ins.parseIPs() if len(ips) == 0 { return errors.New("ips empty") @@ -633,10 +641,9 @@ func (ins *Instance) parseIPs() (lst []string) { item := ins.IPs[i] aip := sw.ParseIp(item) - for _, ip := range aip { - lst = append(lst, ip) - } + lst = append(lst, aip...) } + return } diff --git a/inputs/tomcat/tomcat.go b/inputs/tomcat/tomcat.go index 16bdb277..b9df9e73 100644 --- a/inputs/tomcat/tomcat.go +++ b/inputs/tomcat/tomcat.go @@ -2,7 +2,6 @@ package tomcat import ( "encoding/xml" - "errors" "log" "net/http" "net/url" @@ -80,7 +79,7 @@ type Instance struct { func (ins *Instance) Init() error { if ins.URL == "" { - return errors.New("url is blank") + return nil } if ins.Timeout <= 0 { @@ -170,6 +169,9 @@ func (t *Tomcat) Gather(slist *list.SafeList) { atomic.AddUint64(&t.Counter, 1) for i := range t.Instances { ins := t.Instances[i] + if ins.URL == "" { + continue + } t.wg.Add(1) go t.gatherOnce(slist, ins) } diff --git a/inputs/zookeeper/zookeeper.go b/inputs/zookeeper/zookeeper.go index 57896c6a..d27ca9f2 100644 --- a/inputs/zookeeper/zookeeper.go +++ b/inputs/zookeeper/zookeeper.go @@ -94,6 +94,10 @@ func (z *Zookeeper) Gather(slist *list.SafeList) { for i := range z.Instances { ins := z.Instances[i] + if len(ins.Addresses) == 0 { + continue + } + z.waitgrp.Add(1) go func(slist *list.SafeList, ins *Instance) { defer z.waitgrp.Done()