diff --git a/collector/diskstats_linux.go b/collector/diskstats_linux.go index 5da7aa6a..79b8992d 100644 --- a/collector/diskstats_linux.go +++ b/collector/diskstats_linux.go @@ -217,7 +217,7 @@ func parseDiskStats(r io.Reader) (map[string]map[int]string, error) { ) for scanner.Scan() { - parts := strings.Fields(string(scanner.Text())) + parts := strings.Fields(scanner.Text()) if len(parts) < 4 { // we strip major, minor and dev return nil, fmt.Errorf("invalid line in %s: %s", procFilePath("diskstats"), scanner.Text()) } diff --git a/collector/filefd_linux.go b/collector/filefd_linux.go index 180c6425..2c55a527 100644 --- a/collector/filefd_linux.go +++ b/collector/filefd_linux.go @@ -76,7 +76,7 @@ func parseFileFDStats(r io.Reader, fileName string) (map[string]string, error) { var scanner = bufio.NewScanner(r) scanner.Scan() // The file-nr proc file is separated by tabs, not spaces. - line := strings.Split(string(scanner.Text()), "\u0009") + line := strings.Split(scanner.Text(), "\u0009") var fileFDStat = map[string]string{} // The file-nr proc is only 1 line with 3 values. fileFDStat["allocated"] = line[0] diff --git a/collector/interrupts_linux.go b/collector/interrupts_linux.go index 2364bc6f..3fc3aa79 100644 --- a/collector/interrupts_linux.go +++ b/collector/interrupts_linux.go @@ -73,11 +73,10 @@ func parseInterrupts(r io.Reader) (map[string]interrupt, error) { if !scanner.Scan() { return nil, errors.New("interrupts empty") } - cpuNum := len(strings.Fields(string(scanner.Text()))) // one header per cpu + cpuNum := len(strings.Fields(scanner.Text())) // one header per cpu for scanner.Scan() { - line := scanner.Text() - parts := strings.Fields(string(line)) + parts := strings.Fields(scanner.Text()) if len(parts) < cpuNum+2 { // irq + one column per cpu + details, continue // we ignore ERR and MIS for now } diff --git a/collector/meminfo_linux.go b/collector/meminfo_linux.go index 1a8556fd..3a625a5f 100644 --- a/collector/meminfo_linux.go +++ b/collector/meminfo_linux.go @@ -39,12 +39,12 @@ func parseMemInfo(r io.Reader) (map[string]float64, error) { var ( memInfo = map[string]float64{} scanner = bufio.NewScanner(r) - re = regexp.MustCompile("\\((.*)\\)") + re = regexp.MustCompile(`\((.*)\)`) ) for scanner.Scan() { line := scanner.Text() - parts := strings.Fields(string(line)) + parts := strings.Fields(line) fv, err := strconv.ParseFloat(parts[1], 64) if err != nil { return nil, fmt.Errorf("invalid value in meminfo: %s", err) diff --git a/collector/meminfo_numa_linux.go b/collector/meminfo_numa_linux.go index 960b3d40..ba3bec27 100644 --- a/collector/meminfo_numa_linux.go +++ b/collector/meminfo_numa_linux.go @@ -123,7 +123,7 @@ func parseMemInfoNuma(r io.Reader) ([]meminfoMetric, error) { var ( memInfo []meminfoMetric scanner = bufio.NewScanner(r) - re = regexp.MustCompile("\\((.*)\\)") + re = regexp.MustCompile(`\((.*)\)`) ) for scanner.Scan() { @@ -131,7 +131,7 @@ func parseMemInfoNuma(r io.Reader) ([]meminfoMetric, error) { if line == "" { continue } - parts := strings.Fields(string(line)) + parts := strings.Fields(line) fv, err := strconv.ParseFloat(parts[3], 64) if err != nil { @@ -165,7 +165,7 @@ func parseMemInfoNumaStat(r io.Reader, nodeNumber string) ([]meminfoMetric, erro if line == "" { continue } - parts := strings.Fields(string(line)) + parts := strings.Fields(line) if len(parts) != 2 { return nil, fmt.Errorf("line scan did not return 2 fields: %s", line) } diff --git a/collector/netdev_linux.go b/collector/netdev_linux.go index 912aa740..82657a0b 100644 --- a/collector/netdev_linux.go +++ b/collector/netdev_linux.go @@ -44,7 +44,7 @@ func parseNetDevStats(r io.Reader, ignore *regexp.Regexp) (map[string]map[string scanner := bufio.NewScanner(r) scanner.Scan() // skip first header scanner.Scan() - parts := strings.Split(string(scanner.Text()), "|") + parts := strings.Split(scanner.Text(), "|") if len(parts) != 3 { // interface + receive + transmit return nil, fmt.Errorf("invalid header line in net/dev: %s", scanner.Text()) @@ -53,7 +53,7 @@ func parseNetDevStats(r io.Reader, ignore *regexp.Regexp) (map[string]map[string header := strings.Fields(parts[1]) netDev := map[string]map[string]string{} for scanner.Scan() { - line := strings.TrimLeft(string(scanner.Text()), " ") + line := strings.TrimLeft(scanner.Text(), " ") parts := procNetDevFieldSep.Split(line, -1) if len(parts) != 2*len(header)+1 { return nil, fmt.Errorf("invalid line in net/dev: %s", scanner.Text()) diff --git a/collector/netdev_linux_test.go b/collector/netdev_linux_test.go index 9f27e433..2adc12de 100644 --- a/collector/netdev_linux_test.go +++ b/collector/netdev_linux_test.go @@ -47,7 +47,7 @@ func TestNetDevStats(t *testing.T) { t.Errorf("want count of devices to be %d, got %d", want, got) } - if _, ok := netStats["veth4B09XN"]["transmit_bytes"]; ok != false { + if _, ok := netStats["veth4B09XN"]["transmit_bytes"]; ok { t.Error("want fixture interface veth4B09XN to not exist, but it does") } } diff --git a/collector/netstat_linux.go b/collector/netstat_linux.go index 8b3d6882..65b7897c 100644 --- a/collector/netstat_linux.go +++ b/collector/netstat_linux.go @@ -93,9 +93,9 @@ func parseNetStats(r io.Reader, fileName string) (map[string]map[string]string, ) for scanner.Scan() { - nameParts := strings.Split(string(scanner.Text()), " ") + nameParts := strings.Split(scanner.Text(), " ") scanner.Scan() - valueParts := strings.Split(string(scanner.Text()), " ") + valueParts := strings.Split(scanner.Text(), " ") // Remove trailing :. protocol := nameParts[0][:len(nameParts[0])-1] netStats[protocol] = map[string]string{} diff --git a/collector/sockstat_linux.go b/collector/sockstat_linux.go index 2e8d4893..77873f2b 100644 --- a/collector/sockstat_linux.go +++ b/collector/sockstat_linux.go @@ -85,7 +85,7 @@ func parseSockStats(r io.Reader, fileName string) (map[string]map[string]string, ) for scanner.Scan() { - line := strings.Split(string(scanner.Text()), " ") + line := strings.Split(scanner.Text(), " ") // Remove trailing ':'. protocol := line[0][:len(line[0])-1] sockStat[protocol] = map[string]string{} diff --git a/collector/zfs.go b/collector/zfs.go index bbe6cd86..7b0b85ae 100644 --- a/collector/zfs.go +++ b/collector/zfs.go @@ -87,7 +87,7 @@ func (c *zfsCollector) constSysctlMetric(subsystem string, sysctl zfsSysctl, val return prometheus.MustNewConstMetric( prometheus.NewDesc( - prometheus.BuildFQName(Namespace, string(subsystem), metricName), + prometheus.BuildFQName(Namespace, subsystem, metricName), string(sysctl), nil, nil,