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