Merge pull request #583 from knweiss/golint

Golint fixes
This commit is contained in:
Tobias Schmidt 2017-07-10 23:49:36 +02:00 committed by GitHub
commit 921319c7eb
9 changed files with 21 additions and 30 deletions

View file

@ -44,7 +44,7 @@ import (
*/ */
import "C" import "C"
// default value. from time.h // ClocksPerSec default value. from time.h
const ClocksPerSec = float64(128) const ClocksPerSec = float64(128)
type statCollector struct { type statCollector struct {
@ -55,8 +55,7 @@ func init() {
Factories["cpu"] = NewCPUCollector Factories["cpu"] = NewCPUCollector
} }
// Takes a prometheus registry and returns a new Collector exposing // NewCPUCollector returns a new Collector exposing CPU stats.
// CPU stats.
func NewCPUCollector() (Collector, error) { func NewCPUCollector() (Collector, error) {
return &statCollector{ return &statCollector{
cpu: prometheus.NewDesc( cpu: prometheus.NewDesc(
@ -92,17 +91,17 @@ func (c *statCollector) Update(ch chan<- prometheus.Metric) error {
// the body of struct processor_cpu_load_info // the body of struct processor_cpu_load_info
// aka processor_cpu_load_info_data_t // 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 // copy the cpuload array to a []byte buffer
// where we can binary.Read the data // 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] buf := (*[1 << 30]byte)(unsafe.Pointer(cpuload))[:size:size]
bbuf := bytes.NewBuffer(buf) bbuf := bytes.NewBuffer(buf)
for i := 0; i < int(ncpu); i++ { 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 { if err != nil {
return err return err
} }
@ -112,7 +111,7 @@ func (c *statCollector) Update(ch chan<- prometheus.Metric) error {
"nice": C.CPU_STATE_NICE, "nice": C.CPU_STATE_NICE,
"idle": C.CPU_STATE_IDLE, "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 return nil

View file

@ -91,8 +91,7 @@ func init() {
Factories["cpu"] = NewStatCollector Factories["cpu"] = NewStatCollector
} }
// Takes a prometheus registry and returns a new Collector exposing // NewStatCollector returns a new Collector exposing CPU stats.
// CPU stats.
func NewStatCollector() (Collector, error) { func NewStatCollector() (Collector, error) {
return &statCollector{ return &statCollector{
cpu: prometheus.NewDesc( cpu: prometheus.NewDesc(

View file

@ -89,8 +89,7 @@ func init() {
Factories["cpu"] = NewStatCollector Factories["cpu"] = NewStatCollector
} }
// Takes a prometheus registry and returns a new Collector exposing // NewStatCollector returns a new Collector exposing CPU stats.
// CPU stats.
func NewStatCollector() (Collector, error) { func NewStatCollector() (Collector, error) {
return &statCollector{ return &statCollector{
cpu: typedDesc{prometheus.NewDesc( cpu: typedDesc{prometheus.NewDesc(

View file

@ -102,8 +102,7 @@ func init() {
Factories["devstat"] = NewDevstatCollector Factories["devstat"] = NewDevstatCollector
} }
// Takes a prometheus registry and returns a new Collector exposing // NewDevstatCollector returns a new Collector exposing Device stats.
// Device stats.
func NewDevstatCollector() (Collector, error) { func NewDevstatCollector() (Collector, error) {
return &devstatCollector{ return &devstatCollector{
bytesDesc: prometheus.NewDesc( bytesDesc: prometheus.NewDesc(

View file

@ -36,20 +36,18 @@ type devstatCollector struct {
mu sync.Mutex mu sync.Mutex
devinfo *C.struct_devinfo devinfo *C.struct_devinfo
bytes typedDesc bytes typedDesc
bytes_total typedDesc transfers typedDesc
transfers typedDesc duration typedDesc
duration typedDesc busyTime typedDesc
busyTime typedDesc blocks typedDesc
blocks typedDesc
} }
func init() { func init() {
Factories["devstat"] = NewDevstatCollector Factories["devstat"] = NewDevstatCollector
} }
// Takes a prometheus registry and returns a new Collector exposing // NewDevstatCollector returns a new Collector exposing Device stats.
// Device stats.
func NewDevstatCollector() (Collector, error) { func NewDevstatCollector() (Collector, error) {
return &devstatCollector{ return &devstatCollector{
devinfo: &C.struct_devinfo{}, devinfo: &C.struct_devinfo{},

View file

@ -32,9 +32,8 @@ import "C"
func getLoad() ([]float64, error) { func getLoad() ([]float64, error) {
var loadavg [3]C.double var loadavg [3]C.double
samples := C.getloadavg(&loadavg[0], 3) samples := C.getloadavg(&loadavg[0], 3)
if samples > 0 { if samples != 3 {
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")
} }
return []float64{float64(loadavg[0]), float64(loadavg[1]), float64(loadavg[2])}, nil
} }

View file

@ -26,9 +26,8 @@ import "C"
func getLoad() ([]float64, error) { func getLoad() ([]float64, error) {
var loadavg [3]C.double var loadavg [3]C.double
samples := C.getloadavg(&loadavg[0], 3) samples := C.getloadavg(&loadavg[0], 3)
if samples > 0 { if samples != 3 {
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")
} }
return []float64{float64(loadavg[0]), float64(loadavg[1]), float64(loadavg[2])}, nil
} }

View file

@ -94,7 +94,7 @@ func (b bsdSysctl) Value() (float64, error) {
if len(raw) != (C.sizeof_time_t + C.sizeof_suseconds_t) { if len(raw) != (C.sizeof_time_t + C.sizeof_suseconds_t) {
// Shouldn't get here, unless the ABI changes... // Shouldn't get here, unless the ABI changes...
return 0, fmt.Errorf( 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), len(raw),
C.sizeof_time_t+C.sizeof_suseconds_t, C.sizeof_time_t+C.sizeof_suseconds_t,
) )

View file

@ -61,8 +61,7 @@ func init() {
Factories["tcpstat"] = NewTCPStatCollector Factories["tcpstat"] = NewTCPStatCollector
} }
// NewTCPStatCollector takes a returns // NewTCPStatCollector returns a new Collector exposing network stats.
// a new Collector exposing network stats.
func NewTCPStatCollector() (Collector, error) { func NewTCPStatCollector() (Collector, error) {
return &tcpStatCollector{ return &tcpStatCollector{
desc: typedDesc{prometheus.NewDesc( desc: typedDesc{prometheus.NewDesc(