Merge pull request #178 from prometheus/cpu

Do a make format run.
This commit is contained in:
Julius Volz 2015-12-19 09:22:16 +01:00
commit 3d7658eea5
11 changed files with 49 additions and 53 deletions

View File

@ -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

View File

@ -40,4 +40,3 @@ func NewInterruptsCollector() (Collector, error) {
),
}, nil
}

View File

@ -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{}
)

View File

@ -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"),

View File

@ -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 {

View File

@ -77,4 +77,3 @@ func (c *netDevCollector) Update(ch chan<- prometheus.Metric) (err error) {
}
return nil
}

View File

@ -17,8 +17,8 @@ package collector
import (
"errors"
"strconv"
"regexp"
"strconv"
"github.com/prometheus/common/log"
)

View File

@ -27,7 +27,7 @@ import (
)
var (
procNetDevFieldSep = regexp.MustCompile("[ :] *")
procNetDevFieldSep = regexp.MustCompile("[ :] *")
)
func getNetDevStats(ignore *regexp.Regexp) (map[string]map[string]string, error) {

View File

@ -17,8 +17,8 @@ package collector
import (
"errors"
"strconv"
"regexp"
"strconv"
"github.com/prometheus/common/log"
)

View File

@ -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

View File

@ -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},
},
},