From cfcaeee1458f1e8dd66e155bff98716ce8d8ce76 Mon Sep 17 00:00:00 2001 From: Julian Kornberger Date: Wed, 19 Feb 2020 14:34:05 +0100 Subject: [PATCH] Use strconv.Itoa() instead of fmt.Sprintf() (#1566) Signed-off-by: Julian Kornberger --- collector/cpu_dragonfly.go | 4 ++-- collector/cpu_linux.go | 4 ++-- collector/interrupts_openbsd.go | 2 +- collector/perf_linux.go | 8 ++++---- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/collector/cpu_dragonfly.go b/collector/cpu_dragonfly.go index beef390f..4ccb729d 100644 --- a/collector/cpu_dragonfly.go +++ b/collector/cpu_dragonfly.go @@ -17,7 +17,7 @@ package collector import ( "errors" - "fmt" + "strconv" "unsafe" "github.com/go-kit/kit/log" @@ -131,7 +131,7 @@ func (c *statCollector) Update(ch chan<- prometheus.Metric) error { // Export order: user nice sys intr idle cpuFields := []string{"user", "nice", "sys", "interrupt", "idle"} for i, value := range cpuTimes { - cpux := fmt.Sprintf("%d", i/fieldsCount) + cpux := strconv.Itoa(i / fieldsCount) ch <- prometheus.MustNewConstMetric(c.cpu, prometheus.CounterValue, value, cpux, cpuFields[i%fieldsCount]) } diff --git a/collector/cpu_linux.go b/collector/cpu_linux.go index 1cb6f2c1..f5e9ce89 100644 --- a/collector/cpu_linux.go +++ b/collector/cpu_linux.go @@ -106,7 +106,7 @@ func (c *cpuCollector) updateInfo(ch chan<- prometheus.Metric) error { 1, cpu.PhysicalID, cpu.CoreID, - fmt.Sprintf("%d", cpu.Processor), + strconv.Itoa(int(cpu.Processor)), cpu.VendorID, cpu.CPUFamily, cpu.Model, @@ -202,7 +202,7 @@ func (c *cpuCollector) updateStat(ch chan<- prometheus.Metric) error { } for cpuID, cpuStat := range stats.CPU { - cpuNum := fmt.Sprintf("%d", cpuID) + cpuNum := strconv.Itoa(cpuID) ch <- prometheus.MustNewConstMetric(c.cpu, prometheus.CounterValue, cpuStat.User, cpuNum, "user") ch <- prometheus.MustNewConstMetric(c.cpu, prometheus.CounterValue, cpuStat.Nice, cpuNum, "nice") ch <- prometheus.MustNewConstMetric(c.cpu, prometheus.CounterValue, cpuStat.System, cpuNum, "system") diff --git a/collector/interrupts_openbsd.go b/collector/interrupts_openbsd.go index 5a61e68c..c9aae3ca 100644 --- a/collector/interrupts_openbsd.go +++ b/collector/interrupts_openbsd.go @@ -108,7 +108,7 @@ func (c *interruptsCollector) Update(ch chan<- prometheus.Metric) error { ch <- c.desc.mustNewConstMetric( value, strconv.Itoa(cpuNo), - fmt.Sprintf("%d", interrupt.vector), + strconv.Itoa(interrupt.vector), dev, ) } diff --git a/collector/perf_linux.go b/collector/perf_linux.go index 0e8a3cca..e8a52b43 100644 --- a/collector/perf_linux.go +++ b/collector/perf_linux.go @@ -14,8 +14,8 @@ package collector import ( - "fmt" "runtime" + "strconv" "github.com/go-kit/kit/log" "github.com/hodgesds/perf-utils" @@ -334,7 +334,7 @@ func (c *perfCollector) Update(ch chan<- prometheus.Metric) error { func (c *perfCollector) updateHardwareStats(ch chan<- prometheus.Metric) error { for cpu, profiler := range c.perfHwProfilers { - cpuStr := fmt.Sprintf("%d", cpu) + cpuStr := strconv.Itoa(cpu) hwProfile, err := profiler.Profile() if err != nil { return err @@ -405,7 +405,7 @@ func (c *perfCollector) updateHardwareStats(ch chan<- prometheus.Metric) error { func (c *perfCollector) updateSoftwareStats(ch chan<- prometheus.Metric) error { for cpu, profiler := range c.perfSwProfilers { - cpuStr := fmt.Sprintf("%d", cpu) + cpuStr := strconv.Itoa(cpu) swProfile, err := profiler.Profile() if err != nil { return err @@ -460,7 +460,7 @@ func (c *perfCollector) updateSoftwareStats(ch chan<- prometheus.Metric) error { func (c *perfCollector) updateCacheStats(ch chan<- prometheus.Metric) error { for cpu, profiler := range c.perfCacheProfilers { - cpuStr := fmt.Sprintf("%d", cpu) + cpuStr := strconv.Itoa(cpu) cacheProfile, err := profiler.Profile() if err != nil { return err