diff --git a/collector/cpu_freebsd.go b/collector/cpu_freebsd.go index a04007a1..c4504b7a 100644 --- a/collector/cpu_freebsd.go +++ b/collector/cpu_freebsd.go @@ -100,11 +100,11 @@ func (c *statCollector) Update(ch chan<- prometheus.Metric) (err error) { for i := 0; i < int(ncpus); i++ { pcpu := C.kvm_getpcpu(kd, C.int(i)) cp_time := ((*C.struct_pcpu)(unsafe.Pointer(pcpu))).pc_cp_time - c.cpu.With(prometheus.Labels{"cpu": strconv.Itoa(i), "mode": "user"}).Set(float64(cp_time[C.CP_USER])/clockrate) - c.cpu.With(prometheus.Labels{"cpu": strconv.Itoa(i), "mode": "nice"}).Set(float64(cp_time[C.CP_NICE])/clockrate) - c.cpu.With(prometheus.Labels{"cpu": strconv.Itoa(i), "mode": "system"}).Set(float64(cp_time[C.CP_SYS])/clockrate) - c.cpu.With(prometheus.Labels{"cpu": strconv.Itoa(i), "mode": "interrupt"}).Set(float64(cp_time[C.CP_INTR])/clockrate) - c.cpu.With(prometheus.Labels{"cpu": strconv.Itoa(i), "mode": "idle"}).Set(float64(cp_time[C.CP_IDLE])/clockrate) + c.cpu.With(prometheus.Labels{"cpu": strconv.Itoa(i), "mode": "user"}).Set(float64(cp_time[C.CP_USER]) / clockrate) + c.cpu.With(prometheus.Labels{"cpu": strconv.Itoa(i), "mode": "nice"}).Set(float64(cp_time[C.CP_NICE]) / clockrate) + c.cpu.With(prometheus.Labels{"cpu": strconv.Itoa(i), "mode": "system"}).Set(float64(cp_time[C.CP_SYS]) / clockrate) + c.cpu.With(prometheus.Labels{"cpu": strconv.Itoa(i), "mode": "interrupt"}).Set(float64(cp_time[C.CP_INTR]) / clockrate) + c.cpu.With(prometheus.Labels{"cpu": strconv.Itoa(i), "mode": "idle"}).Set(float64(cp_time[C.CP_IDLE]) / clockrate) } c.cpu.Collect(ch) return err diff --git a/collector/interrupts_common.go b/collector/interrupts_common.go index c9b548ea..3c6248f3 100644 --- a/collector/interrupts_common.go +++ b/collector/interrupts_common.go @@ -40,4 +40,3 @@ func NewInterruptsCollector() (Collector, error) { ), }, nil } - diff --git a/collector/interrupts_openbsd.go b/collector/interrupts_openbsd.go index c6ded5a8..787bea83 100644 --- a/collector/interrupts_openbsd.go +++ b/collector/interrupts_openbsd.go @@ -94,7 +94,6 @@ sysctl_intr(struct intr *intr, int idx) */ import "C" - var ( interruptLabelNames = []string{"CPU", "type", "devices"} ) @@ -126,7 +125,7 @@ type interrupt struct { func getInterrupts() (map[string]interrupt, error) { var ( - cintr C.struct_intr + cintr C.struct_intr interrupts = map[string]interrupt{} ) diff --git a/collector/ipvs_test.go b/collector/ipvs_test.go index aae010fa..935e82f7 100644 --- a/collector/ipvs_test.go +++ b/collector/ipvs_test.go @@ -36,7 +36,7 @@ var ( OutgoingBytes: 0, } expectedIPVSBackendStatuses = []procfs.IPVSBackendStatus{ - procfs.IPVSBackendStatus{ + { LocalAddress: net.ParseIP("192.168.0.22"), LocalPort: 3306, RemoteAddress: net.ParseIP("192.168.82.22"), @@ -46,7 +46,7 @@ var ( ActiveConn: 248, InactConn: 2, }, - procfs.IPVSBackendStatus{ + { LocalAddress: net.ParseIP("192.168.0.22"), LocalPort: 3306, RemoteAddress: net.ParseIP("192.168.83.24"), @@ -56,7 +56,7 @@ var ( ActiveConn: 248, InactConn: 2, }, - procfs.IPVSBackendStatus{ + { LocalAddress: net.ParseIP("192.168.0.22"), LocalPort: 3306, RemoteAddress: net.ParseIP("192.168.83.21"), @@ -66,7 +66,7 @@ var ( ActiveConn: 248, InactConn: 1, }, - procfs.IPVSBackendStatus{ + { LocalAddress: net.ParseIP("192.168.0.57"), LocalPort: 3306, RemoteAddress: net.ParseIP("192.168.84.22"), @@ -76,7 +76,7 @@ var ( ActiveConn: 0, InactConn: 0, }, - procfs.IPVSBackendStatus{ + { LocalAddress: net.ParseIP("192.168.0.57"), LocalPort: 3306, RemoteAddress: net.ParseIP("192.168.82.21"), @@ -86,7 +86,7 @@ var ( ActiveConn: 1499, InactConn: 0, }, - procfs.IPVSBackendStatus{ + { LocalAddress: net.ParseIP("192.168.0.57"), LocalPort: 3306, RemoteAddress: net.ParseIP("192.168.50.21"), @@ -96,7 +96,7 @@ var ( ActiveConn: 1498, InactConn: 0, }, - procfs.IPVSBackendStatus{ + { LocalAddress: net.ParseIP("192.168.0.55"), LocalPort: 3306, RemoteAddress: net.ParseIP("192.168.50.26"), @@ -106,7 +106,7 @@ var ( ActiveConn: 0, InactConn: 0, }, - procfs.IPVSBackendStatus{ + { LocalAddress: net.ParseIP("192.168.0.55"), LocalPort: 3306, RemoteAddress: net.ParseIP("192.168.49.32"), diff --git a/collector/mdadm_test.go b/collector/mdadm_test.go index 75108b36..7a90364a 100644 --- a/collector/mdadm_test.go +++ b/collector/mdadm_test.go @@ -25,13 +25,13 @@ func TestMdadm(t *testing.T) { } refs := map[string]mdStatus{ - "md3": mdStatus{"md3", true, 8, 8, 5853468288, 5853468288}, - "md127": mdStatus{"md127", true, 2, 2, 312319552, 312319552}, - "md0": mdStatus{"md0", true, 2, 2, 248896, 248896}, - "md4": mdStatus{"md4", false, 2, 2, 4883648, 4883648}, - "md6": mdStatus{"md6", true, 1, 2, 195310144, 16775552}, - "md8": mdStatus{"md8", true, 2, 2, 195310144, 16775552}, - "md7": mdStatus{"md7", true, 3, 4, 7813735424, 7813735424}, + "md3": {"md3", true, 8, 8, 5853468288, 5853468288}, + "md127": {"md127", true, 2, 2, 312319552, 312319552}, + "md0": {"md0", true, 2, 2, 248896, 248896}, + "md4": {"md4", false, 2, 2, 4883648, 4883648}, + "md6": {"md6", true, 1, 2, 195310144, 16775552}, + "md8": {"md8", true, 2, 2, 195310144, 16775552}, + "md7": {"md7", true, 3, 4, 7813735424, 7813735424}, } for _, md := range mdStates { diff --git a/collector/netdev_common.go b/collector/netdev_common.go index e7605737..4356a578 100644 --- a/collector/netdev_common.go +++ b/collector/netdev_common.go @@ -77,4 +77,3 @@ func (c *netDevCollector) Update(ch chan<- prometheus.Metric) (err error) { } return nil } - diff --git a/collector/netdev_freebsd.go b/collector/netdev_freebsd.go index 88208570..96c3cda7 100644 --- a/collector/netdev_freebsd.go +++ b/collector/netdev_freebsd.go @@ -17,8 +17,8 @@ package collector import ( "errors" - "strconv" "regexp" + "strconv" "github.com/prometheus/common/log" ) diff --git a/collector/netdev_linux.go b/collector/netdev_linux.go index 3e1bd3fa..4d1ef796 100644 --- a/collector/netdev_linux.go +++ b/collector/netdev_linux.go @@ -27,7 +27,7 @@ import ( ) var ( - procNetDevFieldSep = regexp.MustCompile("[ :] *") + procNetDevFieldSep = regexp.MustCompile("[ :] *") ) func getNetDevStats(ignore *regexp.Regexp) (map[string]map[string]string, error) { diff --git a/collector/netdev_openbsd.go b/collector/netdev_openbsd.go index dc2f36f2..0e9c9009 100644 --- a/collector/netdev_openbsd.go +++ b/collector/netdev_openbsd.go @@ -17,8 +17,8 @@ package collector import ( "errors" - "strconv" "regexp" + "strconv" "github.com/prometheus/common/log" ) diff --git a/collector/stat_linux.go b/collector/stat_linux.go index 0eab92fc..0a486814 100644 --- a/collector/stat_linux.go +++ b/collector/stat_linux.go @@ -38,7 +38,6 @@ type statCollector struct { procsBlocked *prometheus.Desc } - func init() { Factories["stat"] = NewStatCollector } @@ -48,39 +47,39 @@ func init() { func NewStatCollector() (Collector, error) { return &statCollector{ cpu: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "", "cpu"), - "Seconds the cpus spent in each mode.", + prometheus.BuildFQName(Namespace, "", "cpu"), + "Seconds the cpus spent in each mode.", []string{"cpu", "mode"}, nil, ), intr: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "", "intr"), + prometheus.BuildFQName(Namespace, "", "intr"), "Total number of interrupts serviced.", - nil, nil, + nil, nil, ), ctxt: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "", "context_switches"), + prometheus.BuildFQName(Namespace, "", "context_switches"), "Total number of context switches.", - nil, nil, + nil, nil, ), forks: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "", "forks"), + prometheus.BuildFQName(Namespace, "", "forks"), "Total number of forks.", - nil, nil, + nil, nil, ), btime: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "", "boot_time"), + prometheus.BuildFQName(Namespace, "", "boot_time"), "Node boot time, in unixtime.", - nil, nil, + nil, nil, ), - procsRunning: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "", "procs_running"), + procsRunning: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "", "procs_running"), "Number of processes in runnable state.", - nil, nil, + nil, nil, ), - procsBlocked: prometheus.NewDesc( - prometheus.BuildFQName(Namespace, "", "procs_blocked"), + procsBlocked: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, "", "procs_blocked"), "Number of processes blocked waiting for I/O to complete.", - nil, nil, + nil, nil, ), }, nil } @@ -119,7 +118,7 @@ func (c *statCollector) Update(ch chan<- prometheus.Metric) (err error) { } // Convert from ticks to seconds value /= userHz - ch <- prometheus.MustNewConstMetric(c.cpu, prometheus.CounterValue, value, parts[0], cpuFields[i]) + ch <- prometheus.MustNewConstMetric(c.cpu, prometheus.CounterValue, value, parts[0], cpuFields[i]) } case parts[0] == "intr": // Only expose the overall number, use the 'interrupts' collector for more detail. @@ -127,37 +126,37 @@ func (c *statCollector) Update(ch chan<- prometheus.Metric) (err error) { if err != nil { return err } - ch <- prometheus.MustNewConstMetric(c.intr, prometheus.CounterValue, value) + ch <- prometheus.MustNewConstMetric(c.intr, prometheus.CounterValue, value) case parts[0] == "ctxt": value, err := strconv.ParseFloat(parts[1], 64) if err != nil { return err } - ch <- prometheus.MustNewConstMetric(c.ctxt, prometheus.CounterValue, value) + ch <- prometheus.MustNewConstMetric(c.ctxt, prometheus.CounterValue, value) case parts[0] == "processes": value, err := strconv.ParseFloat(parts[1], 64) if err != nil { return err } - ch <- prometheus.MustNewConstMetric(c.forks, prometheus.CounterValue, value) + ch <- prometheus.MustNewConstMetric(c.forks, prometheus.CounterValue, value) case parts[0] == "btime": value, err := strconv.ParseFloat(parts[1], 64) if err != nil { return err } - ch <- prometheus.MustNewConstMetric(c.btime, prometheus.GaugeValue, value) + ch <- prometheus.MustNewConstMetric(c.btime, prometheus.GaugeValue, value) case parts[0] == "procs_running": value, err := strconv.ParseFloat(parts[1], 64) if err != nil { return err } - ch <- prometheus.MustNewConstMetric(c.procsRunning, prometheus.GaugeValue, value) + ch <- prometheus.MustNewConstMetric(c.procsRunning, prometheus.GaugeValue, value) case parts[0] == "procs_blocked": value, err := strconv.ParseFloat(parts[1], 64) if err != nil { return err } - ch <- prometheus.MustNewConstMetric(c.procsBlocked, prometheus.GaugeValue, value) + ch <- prometheus.MustNewConstMetric(c.procsBlocked, prometheus.GaugeValue, value) } } return err diff --git a/collector/textfile.go b/collector/textfile.go index 8f226eac..b2496054 100644 --- a/collector/textfile.go +++ b/collector/textfile.go @@ -128,7 +128,7 @@ func (c *textFileCollector) parseTextFiles() []*dto.MetricFamily { mtimeMetricFamily.Metric = append(mtimeMetricFamily.Metric, &dto.Metric{ Label: []*dto.LabelPair{ - &dto.LabelPair{ + { Name: proto.String("file"), Value: proto.String(filename), }, @@ -145,7 +145,7 @@ func (c *textFileCollector) parseTextFiles() []*dto.MetricFamily { Help: proto.String("1 if there was an error opening or reading a file, 0 otherwise"), Type: dto.MetricType_GAUGE.Enum(), Metric: []*dto.Metric{ - &dto.Metric{ + { Gauge: &dto.Gauge{Value: &error}, }, },