From 732f8398104e9586dfed4837dcdfb55868fc33e4 Mon Sep 17 00:00:00 2001 From: Karsten Weiss Date: Sun, 14 May 2017 12:51:57 +0200 Subject: [PATCH 1/9] sysctl_bsd.go: golint fixes. Typo fix. --- collector/sysctl_bsd.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/collector/sysctl_bsd.go b/collector/sysctl_bsd.go index 1cc5ec6f..1aed5530 100644 --- a/collector/sysctl_bsd.go +++ b/collector/sysctl_bsd.go @@ -94,7 +94,7 @@ func (b bsdSysctl) Value() (float64, error) { if len(raw) != (C.sizeof_time_t + C.sizeof_suseconds_t) { // Shouldn't get here, unless the ABI changes... return 0, fmt.Errorf( - "Length of bytes recieved from sysctl (%d) does not match expected bytes (%d).", + "length of bytes received from sysctl (%d) does not match expected bytes (%d)", len(raw), C.sizeof_time_t+C.sizeof_suseconds_t, ) From af358ec800c9d3183a0d3a815a5be9f15f1eeb48 Mon Sep 17 00:00:00 2001 From: Karsten Weiss Date: Sun, 14 May 2017 12:54:52 +0200 Subject: [PATCH 2/9] golint fixes: if block ends with a return statement, so drop this else and outdent its block. --- collector/loadavg_solaris.go | 3 +-- collector/loadavg_unix.go | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/collector/loadavg_solaris.go b/collector/loadavg_solaris.go index 97253ca0..f9192aa0 100644 --- a/collector/loadavg_solaris.go +++ b/collector/loadavg_solaris.go @@ -34,7 +34,6 @@ func getLoad() ([]float64, error) { samples := C.getloadavg(&loadavg[0], 3) if samples > 0 { return []float64{float64(loadavg[0]), float64(loadavg[1]), float64(loadavg[2])}, nil - } else { - return nil, errors.New("failed to get load average") } + return nil, errors.New("failed to get load average") } diff --git a/collector/loadavg_unix.go b/collector/loadavg_unix.go index 4392611a..df6d652e 100644 --- a/collector/loadavg_unix.go +++ b/collector/loadavg_unix.go @@ -28,7 +28,6 @@ func getLoad() ([]float64, error) { samples := C.getloadavg(&loadavg[0], 3) if samples > 0 { return []float64{float64(loadavg[0]), float64(loadavg[1]), float64(loadavg[2])}, nil - } else { - return nil, errors.New("failed to get load average") } + return nil, errors.New("failed to get load average") } From b73af728539ce9212a9ea4016645ca6b370d218b Mon Sep 17 00:00:00 2001 From: Karsten Weiss Date: Sun, 14 May 2017 13:07:54 +0200 Subject: [PATCH 3/9] Explicitly check for the rc 3 in call to getloadavg(). Reorder logic. --- collector/loadavg_solaris.go | 6 +++--- collector/loadavg_unix.go | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/collector/loadavg_solaris.go b/collector/loadavg_solaris.go index f9192aa0..bf428d8a 100644 --- a/collector/loadavg_solaris.go +++ b/collector/loadavg_solaris.go @@ -32,8 +32,8 @@ import "C" func getLoad() ([]float64, error) { var loadavg [3]C.double samples := C.getloadavg(&loadavg[0], 3) - if samples > 0 { - return []float64{float64(loadavg[0]), float64(loadavg[1]), float64(loadavg[2])}, nil + if samples != 3 { + return nil, errors.New("failed to get load average") } - return nil, errors.New("failed to get load average") + return []float64{float64(loadavg[0]), float64(loadavg[1]), float64(loadavg[2])}, nil } diff --git a/collector/loadavg_unix.go b/collector/loadavg_unix.go index df6d652e..4d658852 100644 --- a/collector/loadavg_unix.go +++ b/collector/loadavg_unix.go @@ -26,8 +26,8 @@ import "C" func getLoad() ([]float64, error) { var loadavg [3]C.double samples := C.getloadavg(&loadavg[0], 3) - if samples > 0 { - return []float64{float64(loadavg[0]), float64(loadavg[1]), float64(loadavg[2])}, nil + if samples != 3 { + return nil, errors.New("failed to get load average") } - return nil, errors.New("failed to get load average") + return []float64{float64(loadavg[0]), float64(loadavg[1]), float64(loadavg[2])}, nil } From 6720cfdbfe991b7f9b474c38fb801a29df217a3b Mon Sep 17 00:00:00 2001 From: Karsten Weiss Date: Sun, 14 May 2017 13:16:26 +0200 Subject: [PATCH 4/9] golint: Fix comment on exported function NewDevstatCollector. --- collector/devstat_dragonfly.go | 3 +-- collector/devstat_freebsd.go | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/collector/devstat_dragonfly.go b/collector/devstat_dragonfly.go index af1e0ee4..63715b25 100644 --- a/collector/devstat_dragonfly.go +++ b/collector/devstat_dragonfly.go @@ -102,8 +102,7 @@ func init() { Factories["devstat"] = NewDevstatCollector } -// Takes a prometheus registry and returns a new Collector exposing -// Device stats. +// NewDevstatCollector returns a new Collector exposing Device stats. func NewDevstatCollector() (Collector, error) { return &devstatCollector{ bytesDesc: prometheus.NewDesc( diff --git a/collector/devstat_freebsd.go b/collector/devstat_freebsd.go index 9b4760e4..f029d0f1 100644 --- a/collector/devstat_freebsd.go +++ b/collector/devstat_freebsd.go @@ -48,8 +48,7 @@ func init() { Factories["devstat"] = NewDevstatCollector } -// Takes a prometheus registry and returns a new Collector exposing -// Device stats. +// NewDevstatCollector returns a new Collector exposing Device stats. func NewDevstatCollector() (Collector, error) { return &devstatCollector{ devinfo: &C.struct_devinfo{}, From fff03c6c0ca402ca9872be54b2e236f0a0df9016 Mon Sep 17 00:00:00 2001 From: Karsten Weiss Date: Sun, 14 May 2017 13:23:57 +0200 Subject: [PATCH 5/9] Fix NewTCPStatCollector doc string. --- collector/tcpstat_linux.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/collector/tcpstat_linux.go b/collector/tcpstat_linux.go index 794fb130..9f665a74 100644 --- a/collector/tcpstat_linux.go +++ b/collector/tcpstat_linux.go @@ -61,8 +61,7 @@ func init() { Factories["tcpstat"] = NewTCPStatCollector } -// NewTCPStatCollector takes a returns -// a new Collector exposing network stats. +// NewTCPStatCollector returns a new Collector exposing network stats. func NewTCPStatCollector() (Collector, error) { return &tcpStatCollector{ desc: typedDesc{prometheus.NewDesc( From b05c7d8dab6fb2f0edcd51ea13ef956786481647 Mon Sep 17 00:00:00 2001 From: Karsten Weiss Date: Sun, 14 May 2017 13:29:26 +0200 Subject: [PATCH 6/9] cpu_darwin.go: Fix doc strings. --- collector/cpu_darwin.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/collector/cpu_darwin.go b/collector/cpu_darwin.go index 174e541f..205b6f34 100644 --- a/collector/cpu_darwin.go +++ b/collector/cpu_darwin.go @@ -44,7 +44,7 @@ import ( */ import "C" -// default value. from time.h +// ClocksPerSec default value. from time.h const ClocksPerSec = float64(128) type statCollector struct { @@ -55,8 +55,7 @@ func init() { Factories["cpu"] = NewCPUCollector } -// Takes a prometheus registry and returns a new Collector exposing -// CPU stats. +// NewCPUCollector returns a new Collector exposing CPU stats. func NewCPUCollector() (Collector, error) { return &statCollector{ cpu: prometheus.NewDesc( From b3e7420a27ef31dd5aca98dcff575fa319c3b6c9 Mon Sep 17 00:00:00 2001 From: Karsten Weiss Date: Sun, 14 May 2017 13:30:05 +0200 Subject: [PATCH 7/9] cpu_darwin.go: s/cpu_ticks/cpuTicks/g --- collector/cpu_darwin.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/collector/cpu_darwin.go b/collector/cpu_darwin.go index 205b6f34..4e3374f9 100644 --- a/collector/cpu_darwin.go +++ b/collector/cpu_darwin.go @@ -91,17 +91,17 @@ func (c *statCollector) Update(ch chan<- prometheus.Metric) error { // the body of struct processor_cpu_load_info // aka processor_cpu_load_info_data_t - var cpu_ticks [C.CPU_STATE_MAX]uint32 + var cpuTicks [C.CPU_STATE_MAX]uint32 // copy the cpuload array to a []byte buffer // where we can binary.Read the data - size := int(ncpu) * binary.Size(cpu_ticks) + size := int(ncpu) * binary.Size(cpuTicks) buf := (*[1 << 30]byte)(unsafe.Pointer(cpuload))[:size:size] bbuf := bytes.NewBuffer(buf) for i := 0; i < int(ncpu); i++ { - err := binary.Read(bbuf, binary.LittleEndian, &cpu_ticks) + err := binary.Read(bbuf, binary.LittleEndian, &cpuTicks) if err != nil { return err } @@ -111,7 +111,7 @@ func (c *statCollector) Update(ch chan<- prometheus.Metric) error { "nice": C.CPU_STATE_NICE, "idle": C.CPU_STATE_IDLE, } { - ch <- prometheus.MustNewConstMetric(c.cpu, prometheus.CounterValue, float64(cpu_ticks[v])/ClocksPerSec, "cpu"+strconv.Itoa(i), k) + ch <- prometheus.MustNewConstMetric(c.cpu, prometheus.CounterValue, float64(cpuTicks[v])/ClocksPerSec, "cpu"+strconv.Itoa(i), k) } } return nil From bca09abf1c50cf39d6b57c693c7216857e7214cc Mon Sep 17 00:00:00 2001 From: Karsten Weiss Date: Sun, 14 May 2017 13:32:35 +0200 Subject: [PATCH 8/9] golint: Fix NewStatCollector() doc string. --- collector/cpu_dragonfly.go | 3 +-- collector/cpu_freebsd.go | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/collector/cpu_dragonfly.go b/collector/cpu_dragonfly.go index db690b0a..a4961117 100644 --- a/collector/cpu_dragonfly.go +++ b/collector/cpu_dragonfly.go @@ -91,8 +91,7 @@ func init() { Factories["cpu"] = NewStatCollector } -// Takes a prometheus registry and returns a new Collector exposing -// CPU stats. +// NewStatCollector returns a new Collector exposing CPU stats. func NewStatCollector() (Collector, error) { return &statCollector{ cpu: prometheus.NewDesc( diff --git a/collector/cpu_freebsd.go b/collector/cpu_freebsd.go index 72dc1f5d..e5d0bee7 100644 --- a/collector/cpu_freebsd.go +++ b/collector/cpu_freebsd.go @@ -89,8 +89,7 @@ func init() { Factories["cpu"] = NewStatCollector } -// Takes a prometheus registry and returns a new Collector exposing -// CPU stats. +// NewStatCollector returns a new Collector exposing CPU stats. func NewStatCollector() (Collector, error) { return &statCollector{ cpu: typedDesc{prometheus.NewDesc( From b2f4fd5776e30eb481ebde189fb27651c8fb16b4 Mon Sep 17 00:00:00 2001 From: Karsten Weiss Date: Sun, 14 May 2017 19:50:19 +0200 Subject: [PATCH 9/9] Remove unused devstatCollector struct member 'bytes_total'. This also fixes this golint issue: devstat_freebsd.go:40:2: don't use underscores in Go names; struct field bytes_total should be bytesTotal --- collector/devstat_freebsd.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/collector/devstat_freebsd.go b/collector/devstat_freebsd.go index f029d0f1..5983f5a1 100644 --- a/collector/devstat_freebsd.go +++ b/collector/devstat_freebsd.go @@ -36,12 +36,11 @@ type devstatCollector struct { mu sync.Mutex devinfo *C.struct_devinfo - bytes typedDesc - bytes_total typedDesc - transfers typedDesc - duration typedDesc - busyTime typedDesc - blocks typedDesc + bytes typedDesc + transfers typedDesc + duration typedDesc + busyTime typedDesc + blocks typedDesc } func init() {