mirror of
https://github.com/prometheus-community/windows_exporter
synced 2025-02-27 17:40:40 +00:00
perf: run perfsprint fixes
Signed-off-by: Ben Reedy <breed808@breed808.com>
This commit is contained in:
parent
a49dee606b
commit
1239fbf719
@ -8,6 +8,7 @@ linters:
|
||||
- loggercheck
|
||||
- nilnil
|
||||
- nilerr
|
||||
- perfsprint
|
||||
- prealloc
|
||||
- revive
|
||||
- unconvert
|
||||
|
@ -3,7 +3,6 @@
|
||||
package container
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/Microsoft/hcsshim"
|
||||
@ -326,14 +325,14 @@ func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
||||
}
|
||||
|
||||
if len(hnsEndpoints) == 0 {
|
||||
_ = level.Info(c.logger).Log("msg", fmt.Sprintf("No network stats for containers to collect"))
|
||||
_ = level.Info(c.logger).Log("msg", "No network stats for containers to collect")
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, endpoint := range hnsEndpoints {
|
||||
endpointStats, err := hcsshim.GetHNSEndpointStats(endpoint.Id)
|
||||
if err != nil {
|
||||
_ = level.Warn(c.logger).Log("msg", fmt.Sprintf("Failed to collect network stats for interface %s", endpoint.Id), "err", err)
|
||||
_ = level.Warn(c.logger).Log("msg", "Failed to collect network stats for interface "+endpoint.Id, "err", err)
|
||||
continue
|
||||
}
|
||||
|
||||
@ -342,7 +341,7 @@ func (c *collector) collect(ch chan<- prometheus.Metric) error {
|
||||
endpointId := strings.ToUpper(endpoint.Id)
|
||||
|
||||
if !ok {
|
||||
_ = level.Warn(c.logger).Log("msg", fmt.Sprintf("Failed to collect network stats for container %s", containerId))
|
||||
_ = level.Warn(c.logger).Log("msg", "Failed to collect network stats for container "+containerId)
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,7 @@ func getIISVersion(logger log.Logger) simple_version {
|
||||
defer func() {
|
||||
err = k.Close()
|
||||
if err != nil {
|
||||
_ = level.Warn(logger).Log("msg", fmt.Sprintf("Failed to close registry key"), "err", err)
|
||||
_ = level.Warn(logger).Log("msg", "Failed to close registry key", "err", err)
|
||||
}
|
||||
}()
|
||||
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -269,12 +270,12 @@ func (c *collector) collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metri
|
||||
c.OSInformation,
|
||||
prometheus.GaugeValue,
|
||||
1.0,
|
||||
fmt.Sprintf("Microsoft %s", pn), // Caption
|
||||
"Microsoft "+pn, // Caption
|
||||
fmt.Sprintf("%d.%d.%s", nwgi.VersionMajor, nwgi.VersionMinor, bn), // Version
|
||||
fmt.Sprintf("%d", nwgi.VersionMajor), // Major Version
|
||||
fmt.Sprintf("%d", nwgi.VersionMinor), // Minor Version
|
||||
bn, // Build number
|
||||
fmt.Sprintf("%d", revision), // Revision
|
||||
strconv.FormatUint(uint64(nwgi.VersionMajor), 10), // Major Version
|
||||
strconv.FormatUint(uint64(nwgi.VersionMinor), 10), // Minor Version
|
||||
bn, // Build number
|
||||
strconv.FormatUint(revision, 10), // Revision
|
||||
)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
|
@ -210,7 +210,7 @@ func (c *collector) collectWMI(ch chan<- prometheus.Metric) error {
|
||||
return err
|
||||
}
|
||||
for _, service := range dst {
|
||||
pid := fmt.Sprintf("%d", uint64(service.ProcessId))
|
||||
pid := strconv.FormatUint(uint64(service.ProcessId), 10)
|
||||
|
||||
runAs := ""
|
||||
if service.StartName != nil {
|
||||
@ -319,7 +319,7 @@ func (c *collector) collectAPI(ch chan<- prometheus.Metric) error {
|
||||
return
|
||||
}
|
||||
|
||||
pid := fmt.Sprintf("%d", uint64(serviceStatus.ProcessId))
|
||||
pid := strconv.FormatUint(uint64(serviceStatus.ProcessId), 10)
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.Information,
|
||||
|
@ -16,6 +16,7 @@
|
||||
package textfile
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
@ -100,7 +101,7 @@ func (c *collector) Build() error {
|
||||
c.directories = strings.Trim(*c.textFileDirectories, ",")
|
||||
}
|
||||
|
||||
_ = level.Info(c.logger).Log("msg", fmt.Sprintf("textfile collector directories: %s", c.directories))
|
||||
_ = level.Info(c.logger).Log("msg", "textfile collector directories: "+c.directories)
|
||||
|
||||
c.MtimeDesc = prometheus.NewDesc(
|
||||
prometheus.BuildFQName(types.Namespace, "textfile", "mtime_seconds"),
|
||||
@ -296,12 +297,12 @@ func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric)
|
||||
for _, directory := range strings.Split(c.directories, ",") {
|
||||
err := filepath.WalkDir(directory, func(path string, dirEntry os.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
_ = level.Error(c.logger).Log("msg", fmt.Sprintf("Error reading directory: %s", path), "err", err)
|
||||
_ = level.Error(c.logger).Log("msg", "Error reading directory: "+path, "err", err)
|
||||
errorMetric = 1.0
|
||||
return nil
|
||||
}
|
||||
if !dirEntry.IsDir() && strings.HasSuffix(dirEntry.Name(), ".prom") {
|
||||
_ = level.Debug(c.logger).Log("msg", fmt.Sprintf("Processing file: %s", path))
|
||||
_ = level.Debug(c.logger).Log("msg", "Processing file: "+path)
|
||||
families_array, err := scrapeFile(path, c.logger)
|
||||
if err != nil {
|
||||
_ = level.Error(c.logger).Log("msg", fmt.Sprintf("Error scraping file: %q. Skip File.", path), "err", err)
|
||||
@ -325,7 +326,7 @@ func (c *collector) Collect(_ *types.ScrapeContext, ch chan<- prometheus.Metric)
|
||||
return nil
|
||||
})
|
||||
if err != nil && directory != "" {
|
||||
_ = level.Error(c.logger).Log("msg", fmt.Sprintf("Error reading textfile collector directory: %s", c.directories), "err", err)
|
||||
_ = level.Error(c.logger).Log("msg", "Error reading textfile collector directory: "+c.directories, "err", err)
|
||||
errorMetric = 1.0
|
||||
}
|
||||
}
|
||||
@ -379,18 +380,18 @@ func scrapeFile(path string, log log.Logger) ([]*dto.MetricFamily, error) {
|
||||
families_array = append(families_array, mf)
|
||||
for _, m := range mf.Metric {
|
||||
if m.TimestampMs != nil {
|
||||
return nil, fmt.Errorf("textfile contains unsupported client-side timestamps")
|
||||
return nil, errors.New("textfile contains unsupported client-side timestamps")
|
||||
}
|
||||
}
|
||||
if mf.Help == nil {
|
||||
help := fmt.Sprintf("Metric read from %s", path)
|
||||
help := "Metric read from " + path
|
||||
mf.Help = &help
|
||||
}
|
||||
}
|
||||
|
||||
// If duplicate metrics are detected in a *single* file, skip processing of file metrics
|
||||
if duplicateMetricEntry(families_array) {
|
||||
return nil, fmt.Errorf("duplicate metrics detected")
|
||||
return nil, errors.New("duplicate metrics detected")
|
||||
}
|
||||
return families_array, nil
|
||||
}
|
||||
@ -400,7 +401,7 @@ func checkBOM(encoding utfbom.Encoding) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf(encoding.String())
|
||||
return errors.New(encoding.String())
|
||||
}
|
||||
|
||||
func getDefaultPath() string {
|
||||
|
@ -1,6 +1,9 @@
|
||||
package config
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// flatten flattens the nested struct.
|
||||
//
|
||||
@ -46,7 +49,7 @@ func flattenSlice(data []interface{}) map[string]string {
|
||||
ret[fmt.Sprintf("%d,%s", idx, fk)] = fv
|
||||
}
|
||||
default:
|
||||
ret[fmt.Sprint(idx)] = fmt.Sprint(typed)
|
||||
ret[strconv.Itoa(idx)] = fmt.Sprint(typed)
|
||||
}
|
||||
}
|
||||
return ret
|
||||
|
@ -1,6 +1,7 @@
|
||||
package perflib
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
@ -17,7 +18,7 @@ const (
|
||||
|
||||
func UnmarshalObject(obj *PerfObject, vs interface{}, logger log.Logger) error {
|
||||
if obj == nil {
|
||||
return fmt.Errorf("counter not found")
|
||||
return errors.New("counter not found")
|
||||
}
|
||||
rv := reflect.ValueOf(vs)
|
||||
if rv.Kind() != reflect.Ptr || rv.IsNil() {
|
||||
|
@ -2,7 +2,7 @@ package wmi
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
|
||||
"reflect"
|
||||
|
||||
"github.com/go-kit/log"
|
||||
@ -47,7 +47,7 @@ func QueryAll(src interface{}, logger log.Logger) string {
|
||||
b.WriteString("SELECT * FROM ")
|
||||
b.WriteString(className(src))
|
||||
|
||||
_ = level.Debug(logger).Log("msg", fmt.Sprintf("Generated WMI query %s", b.String()))
|
||||
_ = level.Debug(logger).Log("msg", "Generated WMI query "+b.String())
|
||||
return b.String()
|
||||
}
|
||||
|
||||
@ -56,7 +56,7 @@ func QueryAllForClass(_ interface{}, class string, logger log.Logger) string {
|
||||
b.WriteString("SELECT * FROM ")
|
||||
b.WriteString(class)
|
||||
|
||||
_ = level.Debug(logger).Log("msg", fmt.Sprintf("Generated WMI query %s", b.String()))
|
||||
_ = level.Debug(logger).Log("msg", "Generated WMI query "+b.String())
|
||||
return b.String()
|
||||
}
|
||||
|
||||
@ -70,7 +70,7 @@ func QueryAllWhere(src interface{}, where string, logger log.Logger) string {
|
||||
b.WriteString(where)
|
||||
}
|
||||
|
||||
_ = level.Debug(logger).Log("msg", fmt.Sprintf("Generated WMI query %s", b.String()))
|
||||
_ = level.Debug(logger).Log("msg", "Generated WMI query "+b.String())
|
||||
return b.String()
|
||||
}
|
||||
|
||||
@ -84,6 +84,6 @@ func QueryAllForClassWhere(_ interface{}, class string, where string, logger log
|
||||
b.WriteString(where)
|
||||
}
|
||||
|
||||
_ = level.Debug(logger).Log("msg", fmt.Sprintf("Generated WMI query %s", b.String()))
|
||||
_ = level.Debug(logger).Log("msg", "Generated WMI query "+b.String())
|
||||
return b.String()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user