From 13cc06e338ff3940028b563ad03ba2dd8a564b60 Mon Sep 17 00:00:00 2001 From: ziv Date: Mon, 1 Aug 2022 19:00:28 +0800 Subject: [PATCH] input code refactor --- agent/metrics_agent.go | 13 ++--- agent/metrics_reader.go | 8 +-- inputs/conntrack/conntrack.go | 7 --- inputs/cpu/cpu.go | 4 -- inputs/disk/disk.go | 12 ----- inputs/diskio/diskio.go | 7 --- inputs/dns_query/dns_query.go | 4 -- inputs/docker/docker.go | 4 -- inputs/elasticsearch/elasticsearch.go | 4 -- inputs/exec/exec.go | 4 -- inputs/http_response/http_response.go | 4 -- inputs/inputs.go | 50 ++++++++++++++++--- inputs/jolokia_agent/jolokia_agent.go | 4 -- inputs/jolokia_proxy/jolokia_proxy.go | 4 -- inputs/kafka/kafka.go | 3 -- inputs/kernel/kernel.go | 4 -- inputs/kernel_vmstat/kernel_vmstat.go | 4 -- inputs/kubernetes/kubernetes.go | 4 -- .../linux_sysctl_fs/linux_sysctl_fs_linux.go | 4 -- inputs/logstash/logstash.go | 4 -- inputs/mem/mem.go | 4 -- inputs/mongodb/mongodb.go | 3 -- inputs/mysql/mysql.go | 4 -- inputs/net/net.go | 3 -- inputs/net_response/net_response.go | 4 -- inputs/netstat/netstat.go | 4 -- inputs/nfsclient/nfsclient.go | 5 -- .../nginx_upstream_check.go | 4 -- inputs/ntp/ntp.go | 3 -- inputs/nvidia_smi/nvidia_smi.go | 3 -- inputs/oracle/oracle_linux_amd64.go | 3 -- inputs/ping/ping.go | 4 -- inputs/processes/processes_notwindows.go | 4 -- inputs/procstat/procstat.go | 4 -- inputs/prometheus/prometheus.go | 4 -- inputs/rabbitmq/rabbitmq.go | 4 -- inputs/redis/redis.go | 3 -- inputs/redis_sentinel/redis_sentinel.go | 4 -- inputs/switch_legacy/switch_legacy.go | 5 -- inputs/system/system.go | 4 -- inputs/tomcat/tomcat.go | 4 -- inputs/tpl/tpl.go | 14 ------ inputs/zookeeper/zookeeper.go | 4 -- 43 files changed, 50 insertions(+), 200 deletions(-) diff --git a/agent/metrics_agent.go b/agent/metrics_agent.go index 33ba5080..969ce63a 100644 --- a/agent/metrics_agent.go +++ b/agent/metrics_agent.go @@ -56,19 +56,15 @@ func (a *Agent) startMetricsAgent() error { continue } - if err = input.Init(); err != nil { + if err = inputs.MayInit(input); err != nil { if !errors.Is(err, types.ErrInstancesEmpty) { log.Println("E! failed to init input:", name, "error:", err) } continue } - if input.GetInstances() != nil { - instances := input.GetInstances() - if len(instances) == 0 { - continue - } - + instances := inputs.MayGetInstances(input) + if instances != nil { empty := true for i := 0; i < len(instances); i++ { if err := instances[i].InitInternalConfig(); err != nil { @@ -76,13 +72,12 @@ func (a *Agent) startMetricsAgent() error { continue } - if err := instances[i].Init(); err != nil { + if err := inputs.MayInit(instances[i]); err != nil { if !errors.Is(err, types.ErrInstancesEmpty) { log.Println("E! failed to init input:", name, "error:", err) } continue } - empty = false } diff --git a/agent/metrics_reader.go b/agent/metrics_reader.go index 84f0241a..8624a709 100644 --- a/agent/metrics_reader.go +++ b/agent/metrics_reader.go @@ -41,7 +41,7 @@ func NewInputReader(inputName string, in inputs.Input) *InputReader { func (r *InputReader) Stop() { r.quitChan <- struct{}{} - r.input.Drop() + inputs.MayDrop(r.input) } func (r *InputReader) startInput() { @@ -82,10 +82,10 @@ func (r *InputReader) gatherOnce() { // plugin level, for system plugins slist := types.NewSampleList() - r.input.Gather(slist) + inputs.MayGather(r.input, slist) r.forward(r.input.Process(slist)) - instances := r.input.GetInstances() + instances := inputs.MayGetInstances(r.input) if len(instances) == 0 { return } @@ -106,7 +106,7 @@ func (r *InputReader) gatherOnce() { } insList := types.NewSampleList() - ins.Gather(insList) + inputs.MayGather(ins, insList) r.forward(ins.Process(insList)) }(instances[i]) } diff --git a/inputs/conntrack/conntrack.go b/inputs/conntrack/conntrack.go index 5e576d77..d800d0bb 100644 --- a/inputs/conntrack/conntrack.go +++ b/inputs/conntrack/conntrack.go @@ -40,11 +40,6 @@ func init() { }) } -// just placeholder -func (c *Conntrack) GetInstances() []inputs.Instance { - return nil -} - func (c *Conntrack) setDefaults() { if len(c.Dirs) == 0 { c.Dirs = dfltDirs @@ -60,8 +55,6 @@ func (c *Conntrack) Init() error { return nil } -func (c *Conntrack) Drop() {} - func (c *Conntrack) Gather(slist *types.SampleList) { var metricKey string fields := make(map[string]interface{}) diff --git a/inputs/cpu/cpu.go b/inputs/cpu/cpu.go index 170c4352..0edd32af 100644 --- a/inputs/cpu/cpu.go +++ b/inputs/cpu/cpu.go @@ -28,10 +28,6 @@ func init() { }) } -func (c *CPUStats) Init() error { return nil } -func (c *CPUStats) Drop() {} -func (c *CPUStats) GetInstances() []inputs.Instance { return nil } - func (c *CPUStats) Gather(slist *types.SampleList) { times, err := c.ps.CPUTimes(c.CollectPerCPU, true) if err != nil { diff --git a/inputs/disk/disk.go b/inputs/disk/disk.go index 7e2d7838..5f5a1a5e 100644 --- a/inputs/disk/disk.go +++ b/inputs/disk/disk.go @@ -29,18 +29,6 @@ func init() { }) } -// just placeholder -func (s *DiskStats) GetInstances() []inputs.Instance { - return nil -} - -func (s *DiskStats) Init() error { - return nil -} - -func (s *DiskStats) Drop() { -} - func (s *DiskStats) Gather(slist *types.SampleList) { disks, partitions, err := s.ps.DiskUsage(s.MountPoints, s.IgnoreFS) if err != nil { diff --git a/inputs/diskio/diskio.go b/inputs/diskio/diskio.go index 031cd6b1..9d5121f3 100644 --- a/inputs/diskio/diskio.go +++ b/inputs/diskio/diskio.go @@ -28,13 +28,6 @@ func init() { }) } -// just placeholder -func (d *DiskIO) GetInstances() []inputs.Instance { - return nil -} - -func (d *DiskIO) Drop() {} - func (d *DiskIO) Init() error { for _, device := range d.Devices { if filter.HasMeta(device) { diff --git a/inputs/dns_query/dns_query.go b/inputs/dns_query/dns_query.go index 3f22b9f1..21273ca0 100644 --- a/inputs/dns_query/dns_query.go +++ b/inputs/dns_query/dns_query.go @@ -34,10 +34,6 @@ func init() { }) } -func (dq *DnsQuery) Init() error { return nil } -func (dq *DnsQuery) Drop() {} -func (dq *DnsQuery) Gather(slist *types.SampleList) {} - func (dq *DnsQuery) GetInstances() []inputs.Instance { ret := make([]inputs.Instance, len(dq.Instances)) for i := 0; i < len(dq.Instances); i++ { diff --git a/inputs/docker/docker.go b/inputs/docker/docker.go index 24ab6ccc..7fe63c82 100644 --- a/inputs/docker/docker.go +++ b/inputs/docker/docker.go @@ -50,10 +50,6 @@ func init() { }) } -func (d *Docker) Init() error { return nil } -func (d *Docker) Drop() {} -func (d *Docker) Gather(slist *itypes.SampleList) {} - func (d *Docker) GetInstances() []inputs.Instance { ret := make([]inputs.Instance, len(d.Instances)) for i := 0; i < len(d.Instances); i++ { diff --git a/inputs/elasticsearch/elasticsearch.go b/inputs/elasticsearch/elasticsearch.go index e93e38b2..3743cb88 100644 --- a/inputs/elasticsearch/elasticsearch.go +++ b/inputs/elasticsearch/elasticsearch.go @@ -94,10 +94,6 @@ func init() { }) } -func (r *Elasticsearch) Init() error { return nil } -func (r *Elasticsearch) Drop() {} -func (r *Elasticsearch) Gather(slist *types.SampleList) {} - func (r *Elasticsearch) GetInstances() []inputs.Instance { ret := make([]inputs.Instance, len(r.Instances)) for i := 0; i < len(r.Instances); i++ { diff --git a/inputs/exec/exec.go b/inputs/exec/exec.go index f9b67f23..1683c163 100644 --- a/inputs/exec/exec.go +++ b/inputs/exec/exec.go @@ -45,10 +45,6 @@ func init() { }) } -func (e *Exec) Init() error { return nil } -func (e *Exec) Drop() {} -func (e *Exec) Gather(slist *types.SampleList) {} - func (e *Exec) GetInstances() []inputs.Instance { ret := make([]inputs.Instance, len(e.Instances)) for i := 0; i < len(e.Instances); i++ { diff --git a/inputs/http_response/http_response.go b/inputs/http_response/http_response.go index c8ed7a5e..36e4b61b 100644 --- a/inputs/http_response/http_response.go +++ b/inputs/http_response/http_response.go @@ -145,10 +145,6 @@ func init() { }) } -func (h *HTTPResponse) Init() error { return nil } -func (h *HTTPResponse) Drop() {} -func (h *HTTPResponse) Gather(slist *types.SampleList) {} - func (h *HTTPResponse) GetInstances() []inputs.Instance { ret := make([]inputs.Instance, len(h.Instances)) for i := 0; i < len(h.Instances); i++ { diff --git a/inputs/inputs.go b/inputs/inputs.go index 85aa2fa5..a8dd6164 100644 --- a/inputs/inputs.go +++ b/inputs/inputs.go @@ -5,16 +5,53 @@ import ( "flashcat.cloud/categraf/types" ) +type Initializer interface { + Init() error +} + +type SampleGatherer interface { + Gather(*types.SampleList) +} + +type Dropper interface { + Drop() +} + +type InstancesGetter interface { + GetInstances() []Instance +} + +func MayInit(t interface{}) error { + if initializer, ok := t.(Initializer); ok { + return initializer.Init() + } + return nil +} + +func MayGather(t interface{}, slist *types.SampleList) { + if gather, ok := t.(SampleGatherer); ok { + gather.Gather(slist) + } +} + +func MayDrop(t interface{}) { + if dropper, ok := t.(Dropper); ok { + dropper.Drop() + } +} + +func MayGetInstances(t interface{}) []Instance { + if instancesGetter, ok := t.(InstancesGetter); ok { + return instancesGetter.GetInstances() + } + return nil +} + type Input interface { GetLabels() map[string]string GetInterval() config.Duration InitInternalConfig() error Process(*types.SampleList) *types.SampleList - - Init() error - Drop() - Gather(*types.SampleList) - GetInstances() []Instance } type Creator func() Input @@ -30,7 +67,4 @@ type Instance interface { GetIntervalTimes() int64 InitInternalConfig() error Process(*types.SampleList) *types.SampleList - - Init() error - Gather(*types.SampleList) } diff --git a/inputs/jolokia_agent/jolokia_agent.go b/inputs/jolokia_agent/jolokia_agent.go index fa00e6a3..8e2aea11 100644 --- a/inputs/jolokia_agent/jolokia_agent.go +++ b/inputs/jolokia_agent/jolokia_agent.go @@ -26,10 +26,6 @@ func init() { }) } -func (r *JolokiaAgent) Init() error { return nil } -func (r *JolokiaAgent) Drop() {} -func (r *JolokiaAgent) Gather(slist *types.SampleList) {} - func (r *JolokiaAgent) GetInstances() []inputs.Instance { ret := make([]inputs.Instance, len(r.Instances)) for i := 0; i < len(r.Instances); i++ { diff --git a/inputs/jolokia_proxy/jolokia_proxy.go b/inputs/jolokia_proxy/jolokia_proxy.go index f8082d65..3f4a2c28 100644 --- a/inputs/jolokia_proxy/jolokia_proxy.go +++ b/inputs/jolokia_proxy/jolokia_proxy.go @@ -25,10 +25,6 @@ func init() { }) } -func (r *JolokiaProxy) Init() error { return nil } -func (r *JolokiaProxy) Drop() {} -func (r *JolokiaProxy) Gather(slist *types.SampleList) {} - func (r *JolokiaProxy) GetInstances() []inputs.Instance { ret := make([]inputs.Instance, len(r.Instances)) for i := 0; i < len(r.Instances); i++ { diff --git a/inputs/kafka/kafka.go b/inputs/kafka/kafka.go index 37eeb878..c2c949e8 100644 --- a/inputs/kafka/kafka.go +++ b/inputs/kafka/kafka.go @@ -28,9 +28,6 @@ func init() { }) } -func (r *Kafka) Init() error { return nil } -func (r *Kafka) Gather(slist *types.SampleList) {} - func (r *Kafka) GetInstances() []inputs.Instance { ret := make([]inputs.Instance, len(r.Instances)) for i := 0; i < len(r.Instances); i++ { diff --git a/inputs/kernel/kernel.go b/inputs/kernel/kernel.go index ac74a76a..516351e1 100644 --- a/inputs/kernel/kernel.go +++ b/inputs/kernel/kernel.go @@ -43,10 +43,6 @@ func init() { }) } -func (s *KernelStats) Init() error { return nil } -func (s *KernelStats) Drop() {} -func (s *KernelStats) GetInstances() []inputs.Instance { return nil } - func (s *KernelStats) Gather(slist *types.SampleList) { data, err := s.getProcStat() if err != nil { diff --git a/inputs/kernel_vmstat/kernel_vmstat.go b/inputs/kernel_vmstat/kernel_vmstat.go index b54c70ad..2c4aebff 100644 --- a/inputs/kernel_vmstat/kernel_vmstat.go +++ b/inputs/kernel_vmstat/kernel_vmstat.go @@ -32,10 +32,6 @@ func init() { }) } -func (s *KernelVmstat) Init() error { return nil } -func (s *KernelVmstat) Drop() {} -func (s *KernelVmstat) GetInstances() []inputs.Instance { return nil } - func (s *KernelVmstat) Gather(slist *types.SampleList) { data, err := s.getProcVmstat() if err != nil { diff --git a/inputs/kubernetes/kubernetes.go b/inputs/kubernetes/kubernetes.go index 8aa18e83..185a20b7 100644 --- a/inputs/kubernetes/kubernetes.go +++ b/inputs/kubernetes/kubernetes.go @@ -32,10 +32,6 @@ func init() { }) } -func (k *Kubernetes) Init() error { return nil } -func (k *Kubernetes) Drop() {} -func (k *Kubernetes) Gather(slist *types.SampleList) {} - func (k *Kubernetes) GetInstances() []inputs.Instance { ret := make([]inputs.Instance, len(k.Instances)) for i := 0; i < len(k.Instances); i++ { diff --git a/inputs/linux_sysctl_fs/linux_sysctl_fs_linux.go b/inputs/linux_sysctl_fs/linux_sysctl_fs_linux.go index a4ad296c..5a95e492 100644 --- a/inputs/linux_sysctl_fs/linux_sysctl_fs_linux.go +++ b/inputs/linux_sysctl_fs/linux_sysctl_fs_linux.go @@ -33,10 +33,6 @@ func init() { }) } -func (s *SysctlFS) Init() error { return nil } -func (s *SysctlFS) Drop() {} -func (s *SysctlFS) GetInstances() []inputs.Instance { return nil } - func (s *SysctlFS) Gather(slist *types.SampleList) { fields := map[string]interface{}{} diff --git a/inputs/logstash/logstash.go b/inputs/logstash/logstash.go index 9f470bce..a6d0b3ca 100644 --- a/inputs/logstash/logstash.go +++ b/inputs/logstash/logstash.go @@ -31,10 +31,6 @@ func init() { }) } -func (l *Logstash) Init() error { return nil } -func (l *Logstash) Drop() {} -func (l *Logstash) Gather(slist *types.SampleList) {} - func (l *Logstash) GetInstances() []inputs.Instance { ret := make([]inputs.Instance, len(l.Instances)) for i := 0; i < len(l.Instances); i++ { diff --git a/inputs/mem/mem.go b/inputs/mem/mem.go index a8bbcc74..22976ad5 100644 --- a/inputs/mem/mem.go +++ b/inputs/mem/mem.go @@ -28,10 +28,6 @@ func init() { }) } -func (s *MemStats) Init() error { return nil } -func (s *MemStats) Drop() {} -func (s *MemStats) GetInstances() []inputs.Instance { return nil } - func (s *MemStats) Gather(slist *types.SampleList) { vm, err := s.ps.VMStat() if err != nil { diff --git a/inputs/mongodb/mongodb.go b/inputs/mongodb/mongodb.go index 38cda32e..690490af 100644 --- a/inputs/mongodb/mongodb.go +++ b/inputs/mongodb/mongodb.go @@ -24,9 +24,6 @@ func init() { }) } -func (r *MongoDB) Init() error { return nil } -func (r *MongoDB) Gather(slist *types.SampleList) {} - func (r *MongoDB) GetInstances() []inputs.Instance { ret := make([]inputs.Instance, len(r.Instances)) for i := 0; i < len(r.Instances); i++ { diff --git a/inputs/mysql/mysql.go b/inputs/mysql/mysql.go index 41e67a3c..c82efb59 100644 --- a/inputs/mysql/mysql.go +++ b/inputs/mysql/mysql.go @@ -158,10 +158,6 @@ func init() { }) } -func (m *MySQL) Init() error { return nil } -func (m *MySQL) Drop() {} -func (m *MySQL) Gather(slist *types.SampleList) {} - func (m *MySQL) GetInstances() []inputs.Instance { ret := make([]inputs.Instance, len(m.Instances)) for i := 0; i < len(m.Instances); i++ { diff --git a/inputs/net/net.go b/inputs/net/net.go index ed8332e3..2005daa7 100644 --- a/inputs/net/net.go +++ b/inputs/net/net.go @@ -33,9 +33,6 @@ func init() { }) } -func (s *NetIOStats) Drop() {} -func (s *NetIOStats) GetInstances() []inputs.Instance { return nil } - func (s *NetIOStats) Init() error { var err error diff --git a/inputs/net_response/net_response.go b/inputs/net_response/net_response.go index 24d27e3a..7a859849 100644 --- a/inputs/net_response/net_response.go +++ b/inputs/net_response/net_response.go @@ -93,10 +93,6 @@ func init() { }) } -func (n *NetResponse) Init() error { return nil } -func (n *NetResponse) Drop() {} -func (n *NetResponse) Gather(slist *types.SampleList) {} - func (n *NetResponse) GetInstances() []inputs.Instance { ret := make([]inputs.Instance, len(n.Instances)) for i := 0; i < len(n.Instances); i++ { diff --git a/inputs/netstat/netstat.go b/inputs/netstat/netstat.go index 650a8789..c9dfdde8 100644 --- a/inputs/netstat/netstat.go +++ b/inputs/netstat/netstat.go @@ -26,10 +26,6 @@ func init() { }) } -func (s *NetStats) Init() error { return nil } -func (s *NetStats) Drop() {} -func (s *NetStats) GetInstances() []inputs.Instance { return nil } - func (s *NetStats) Gather(slist *types.SampleList) { netconns, err := s.ps.NetConnections() if err != nil { diff --git a/inputs/nfsclient/nfsclient.go b/inputs/nfsclient/nfsclient.go index 98995cc1..dd30d5a7 100644 --- a/inputs/nfsclient/nfsclient.go +++ b/inputs/nfsclient/nfsclient.go @@ -212,8 +212,6 @@ func (s *NfsClient) Init() error { return nil } -func (r *NfsClient) Drop() {} - func (s *NfsClient) Gather(slist *types.SampleList) { file, err := os.Open(s.mountstatsPath) if err != nil { @@ -231,9 +229,6 @@ func (s *NfsClient) Gather(slist *types.SampleList) { log.Println("E!", err) } } -func (s *NfsClient) GetInstances() []inputs.Instance { - return nil -} func convertToUint64(line []string) ([]uint64, error) { /* A "line" of input data (a pre-split array of strings) is diff --git a/inputs/nginx_upstream_check/nginx_upstream_check.go b/inputs/nginx_upstream_check/nginx_upstream_check.go index 74a497ac..e887807f 100644 --- a/inputs/nginx_upstream_check/nginx_upstream_check.go +++ b/inputs/nginx_upstream_check/nginx_upstream_check.go @@ -32,10 +32,6 @@ func init() { }) } -func (r *NginxUpstreamCheck) Init() error { return nil } -func (r *NginxUpstreamCheck) Drop() {} -func (r *NginxUpstreamCheck) Gather(slist *types.SampleList) {} - func (r *NginxUpstreamCheck) GetInstances() []inputs.Instance { ret := make([]inputs.Instance, len(r.Instances)) for i := 0; i < len(r.Instances); i++ { diff --git a/inputs/ntp/ntp.go b/inputs/ntp/ntp.go index aaa0eef6..dd92b75a 100644 --- a/inputs/ntp/ntp.go +++ b/inputs/ntp/ntp.go @@ -24,9 +24,6 @@ func init() { }) } -func (n *NTPStat) Drop() {} -func (n *NTPStat) GetInstances() []inputs.Instance { return nil } - func (n *NTPStat) Init() error { if len(n.NTPServers) == 0 { return types.ErrInstancesEmpty diff --git a/inputs/nvidia_smi/nvidia_smi.go b/inputs/nvidia_smi/nvidia_smi.go index b25e94ad..21eab153 100644 --- a/inputs/nvidia_smi/nvidia_smi.go +++ b/inputs/nvidia_smi/nvidia_smi.go @@ -30,9 +30,6 @@ func init() { }) } -func (s *GPUStats) Drop() {} -func (s *GPUStats) GetInstances() []inputs.Instance { return nil } - func (s *GPUStats) Init() error { if s.NvidiaSmiCommand == "" { return types.ErrInstancesEmpty diff --git a/inputs/oracle/oracle_linux_amd64.go b/inputs/oracle/oracle_linux_amd64.go index b2e25620..6bea085e 100644 --- a/inputs/oracle/oracle_linux_amd64.go +++ b/inputs/oracle/oracle_linux_amd64.go @@ -59,9 +59,6 @@ func init() { }) } -func (o *Oracle) Init() error { return nil } -func (o *Oracle) Gather(slist *types.SampleList) {} - func (o *Oracle) Drop() { for i := 0; i < len(o.Instances); i++ { o.Instances[i].Drop() diff --git a/inputs/ping/ping.go b/inputs/ping/ping.go index 0148cebd..42be7889 100644 --- a/inputs/ping/ping.go +++ b/inputs/ping/ping.go @@ -89,10 +89,6 @@ func init() { }) } -func (p *Ping) Init() error { return nil } -func (p *Ping) Drop() {} -func (p *Ping) Gather(slist *types.SampleList) {} - func (p *Ping) GetInstances() []inputs.Instance { ret := make([]inputs.Instance, len(p.Instances)) for i := 0; i < len(p.Instances); i++ { diff --git a/inputs/processes/processes_notwindows.go b/inputs/processes/processes_notwindows.go index c211de45..1fe8b383 100644 --- a/inputs/processes/processes_notwindows.go +++ b/inputs/processes/processes_notwindows.go @@ -34,10 +34,6 @@ func init() { }) } -func (p *Processes) Init() error { return nil } -func (p *Processes) Drop() {} -func (p *Processes) GetInstances() []inputs.Instance { return nil } - func (p *Processes) Gather(slist *types.SampleList) { // Get an empty map of metric fields fields := getEmptyFields() diff --git a/inputs/procstat/procstat.go b/inputs/procstat/procstat.go index e4b8a77a..2e7f6fa4 100644 --- a/inputs/procstat/procstat.go +++ b/inputs/procstat/procstat.go @@ -70,10 +70,6 @@ func init() { }) } -func (s *Procstat) Init() error { return nil } -func (s *Procstat) Drop() {} -func (s *Procstat) Gather(slist *types.SampleList) {} - func (s *Procstat) GetInstances() []inputs.Instance { ret := make([]inputs.Instance, len(s.Instances)) for i := 0; i < len(s.Instances); i++ { diff --git a/inputs/prometheus/prometheus.go b/inputs/prometheus/prometheus.go index 92054833..3b0283df 100644 --- a/inputs/prometheus/prometheus.go +++ b/inputs/prometheus/prometheus.go @@ -135,10 +135,6 @@ func init() { }) } -func (p *Prometheus) Init() error { return nil } -func (p *Prometheus) Drop() {} -func (p *Prometheus) Gather(slist *types.SampleList) {} - func (p *Prometheus) GetInstances() []inputs.Instance { ret := make([]inputs.Instance, len(p.Instances)) for i := 0; i < len(p.Instances); i++ { diff --git a/inputs/rabbitmq/rabbitmq.go b/inputs/rabbitmq/rabbitmq.go index 60f86a8c..5f736ca6 100644 --- a/inputs/rabbitmq/rabbitmq.go +++ b/inputs/rabbitmq/rabbitmq.go @@ -29,10 +29,6 @@ func init() { }) } -func (r *RabbitMQ) Init() error { return nil } -func (r *RabbitMQ) Drop() {} -func (r *RabbitMQ) Gather(slist *types.SampleList) {} - func (r *RabbitMQ) GetInstances() []inputs.Instance { ret := make([]inputs.Instance, len(r.Instances)) for i := 0; i < len(r.Instances); i++ { diff --git a/inputs/redis/redis.go b/inputs/redis/redis.go index 7f4f15a6..f0cdd9f5 100644 --- a/inputs/redis/redis.go +++ b/inputs/redis/redis.go @@ -75,9 +75,6 @@ func init() { }) } -func (r *Redis) Init() error { return nil } -func (r *Redis) Gather(slist *types.SampleList) {} - func (r *Redis) GetInstances() []inputs.Instance { ret := make([]inputs.Instance, len(r.Instances)) for i := 0; i < len(r.Instances); i++ { diff --git a/inputs/redis_sentinel/redis_sentinel.go b/inputs/redis_sentinel/redis_sentinel.go index f4457248..b2775492 100644 --- a/inputs/redis_sentinel/redis_sentinel.go +++ b/inputs/redis_sentinel/redis_sentinel.go @@ -35,10 +35,6 @@ func init() { }) } -func (r *RedisSentinel) Init() error { return nil } -func (r *RedisSentinel) Drop() {} -func (r *RedisSentinel) Gather(slist *types.SampleList) {} - func (r *RedisSentinel) GetInstances() []inputs.Instance { ret := make([]inputs.Instance, len(r.Instances)) for i := 0; i < len(r.Instances); i++ { diff --git a/inputs/switch_legacy/switch_legacy.go b/inputs/switch_legacy/switch_legacy.go index 15a5d636..84ab97b6 100644 --- a/inputs/switch_legacy/switch_legacy.go +++ b/inputs/switch_legacy/switch_legacy.go @@ -33,9 +33,6 @@ func init() { }) } -func (s *Switch) Drop() {} -func (s *Switch) Gather(slist *types.SampleList) {} - func (s *Switch) MappingIP(ip string) string { val, has := s.Mappings[ip] if has { @@ -122,8 +119,6 @@ type Custom struct { OID string `toml:"oid"` } -func (ins *Instance) Init() error { return nil } - func (ins *Instance) RealInit() error { if len(ins.IPs) == 0 { return types.ErrInstancesEmpty diff --git a/inputs/system/system.go b/inputs/system/system.go index 3a7d4a35..89389f58 100644 --- a/inputs/system/system.go +++ b/inputs/system/system.go @@ -26,10 +26,6 @@ func init() { }) } -func (s *SystemStats) Init() error { return nil } -func (s *SystemStats) Drop() {} -func (s *SystemStats) GetInstances() []inputs.Instance { return nil } - func (s *SystemStats) Gather(slist *types.SampleList) { loadavg, err := load.Avg() if err != nil && !strings.Contains(err.Error(), "not implemented") { diff --git a/inputs/tomcat/tomcat.go b/inputs/tomcat/tomcat.go index 783967d6..b37d7b3e 100644 --- a/inputs/tomcat/tomcat.go +++ b/inputs/tomcat/tomcat.go @@ -139,10 +139,6 @@ func init() { }) } -func (t *Tomcat) Init() error { return nil } -func (t *Tomcat) Drop() {} -func (t *Tomcat) Gather(slist *types.SampleList) {} - func (t *Tomcat) GetInstances() []inputs.Instance { ret := make([]inputs.Instance, len(t.Instances)) for i := 0; i < len(t.Instances); i++ { diff --git a/inputs/tpl/tpl.go b/inputs/tpl/tpl.go index c7a1aa37..a3a86f54 100644 --- a/inputs/tpl/tpl.go +++ b/inputs/tpl/tpl.go @@ -3,7 +3,6 @@ package tpl import ( "flashcat.cloud/categraf/config" "flashcat.cloud/categraf/inputs" - "flashcat.cloud/categraf/types" ) const inputName = "plugin_tpl" @@ -19,11 +18,6 @@ func init() { }) } -func (pt *PluginTpl) Prefix() string { return inputName } -func (pt *PluginTpl) Init() error { return nil } -func (pt *PluginTpl) Drop() {} -func (pt *PluginTpl) Gather(slist *types.SampleList) {} - func (pt *PluginTpl) GetInstances() []inputs.Instance { ret := make([]inputs.Instance, len(pt.Instances)) for i := 0; i < len(pt.Instances); i++ { @@ -35,11 +29,3 @@ func (pt *PluginTpl) GetInstances() []inputs.Instance { type Instance struct { config.InstanceConfig } - -func (ins *Instance) Init() error { - return nil -} - -func (ins *Instance) Gather(slist *types.SampleList) { - -} diff --git a/inputs/zookeeper/zookeeper.go b/inputs/zookeeper/zookeeper.go index b543579c..6f15db8f 100644 --- a/inputs/zookeeper/zookeeper.go +++ b/inputs/zookeeper/zookeeper.go @@ -71,10 +71,6 @@ func init() { }) } -func (z *Zookeeper) Init() error { return nil } -func (z *Zookeeper) Drop() {} -func (z *Zookeeper) Gather(slist *types.SampleList) {} - func (z *Zookeeper) GetInstances() []inputs.Instance { ret := make([]inputs.Instance, len(z.Instances)) for i := 0; i < len(z.Instances); i++ {