From 3c91e22d9a18c97c26033dc2aa96855fd47bbc62 Mon Sep 17 00:00:00 2001 From: Arunvel Sriram Date: Thu, 13 Aug 2020 20:30:24 +0530 Subject: [PATCH] Log and continue if err occurs when getting stats --- pkg/collector/sftp_collector.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pkg/collector/sftp_collector.go b/pkg/collector/sftp_collector.go index a222d3b..c7c4ef7 100644 --- a/pkg/collector/sftp_collector.go +++ b/pkg/collector/sftp_collector.go @@ -71,21 +71,21 @@ func (s SFTPCollector) Collect(ch chan<- prometheus.Metric) { fsStats, err := sftpClient.FSStats() if err != nil { log.WithFields(log.Fields{"event": "getting FS stats"}).Error(err) - return - } - for _, stat := range fsStats { - ch <- prometheus.MustNewConstMetric(fsTotalSpace, prometheus.GaugeValue, stat.TotalSpace, stat.Path) - ch <- prometheus.MustNewConstMetric(fsFreeSpace, prometheus.GaugeValue, stat.FreeSpace, stat.Path) + } else { + for _, stat := range fsStats { + ch <- prometheus.MustNewConstMetric(fsTotalSpace, prometheus.GaugeValue, stat.TotalSpace, stat.Path) + ch <- prometheus.MustNewConstMetric(fsFreeSpace, prometheus.GaugeValue, stat.FreeSpace, stat.Path) + } } objectStats, err := sftpClient.ObjectStats() if err != nil { log.WithFields(log.Fields{"event": "getting object stats"}).Error(err) - return - } - for _, stat := range objectStats { - ch <- prometheus.MustNewConstMetric(objectCount, prometheus.GaugeValue, stat.ObjectCount, stat.Path) - ch <- prometheus.MustNewConstMetric(objectSize, prometheus.GaugeValue, stat.ObjectSize, stat.Path) + } else { + for _, stat := range objectStats { + ch <- prometheus.MustNewConstMetric(objectCount, prometheus.GaugeValue, stat.ObjectCount, stat.Path) + ch <- prometheus.MustNewConstMetric(objectSize, prometheus.GaugeValue, stat.ObjectSize, stat.Path) + } } }