Migrated everything to new client_golang.
This commit is contained in:
parent
e8ebcede5b
commit
0563ecd29d
11 changed files with 388 additions and 246 deletions
|
|
@ -19,18 +19,48 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
cpuMetrics = prometheus.NewCounter()
|
||||
intrMetric = prometheus.NewCounter()
|
||||
ctxtMetric = prometheus.NewCounter()
|
||||
btimeMetric = prometheus.NewGauge()
|
||||
forksMetric = prometheus.NewCounter()
|
||||
procsRunningMetric = prometheus.NewGauge()
|
||||
procsBlockedMetric = prometheus.NewGauge()
|
||||
cpuMetrics = prometheus.NewCounterVec(
|
||||
prometheus.CounterOpts{
|
||||
Namespace: Namespace,
|
||||
Name: "cpu",
|
||||
Help: "Seconds the cpus spent in each mode.",
|
||||
},
|
||||
[]string{"cpu", "mode"},
|
||||
)
|
||||
intrMetric = prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: Namespace,
|
||||
Name: "intr",
|
||||
Help: "Total number of interrupts serviced.",
|
||||
})
|
||||
ctxtMetric = prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: Namespace,
|
||||
Name: "context_switches",
|
||||
Help: "Total number of context switches.",
|
||||
})
|
||||
forksMetric = prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: Namespace,
|
||||
Name: "forks",
|
||||
Help: "Total number of forks.",
|
||||
})
|
||||
btimeMetric = prometheus.NewGauge(prometheus.GaugeOpts{
|
||||
Namespace: Namespace,
|
||||
Name: "boot_time",
|
||||
Help: "Node boot time, in unixtime.",
|
||||
})
|
||||
procsRunningMetric = prometheus.NewGauge(prometheus.GaugeOpts{
|
||||
Namespace: Namespace,
|
||||
Name: "procs_running",
|
||||
Help: "Number of processes in runnable state.",
|
||||
})
|
||||
procsBlockedMetric = prometheus.NewGauge(prometheus.GaugeOpts{
|
||||
Namespace: Namespace,
|
||||
Name: "procs_blocked",
|
||||
Help: "Number of processes blocked waiting for I/O to complete.",
|
||||
})
|
||||
)
|
||||
|
||||
type statCollector struct {
|
||||
registry prometheus.Registry
|
||||
config Config
|
||||
config Config
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
|
@ -39,53 +69,31 @@ func init() {
|
|||
|
||||
// Takes a config struct and prometheus registry and returns a new Collector exposing
|
||||
// network device stats.
|
||||
func NewStatCollector(config Config, registry prometheus.Registry) (Collector, error) {
|
||||
func NewStatCollector(config Config) (Collector, error) {
|
||||
c := statCollector{
|
||||
config: config,
|
||||
registry: registry,
|
||||
config: config,
|
||||
}
|
||||
if _, err := prometheus.RegisterOrGet(cpuMetrics); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, err := prometheus.RegisterOrGet(intrMetric); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, err := prometheus.RegisterOrGet(ctxtMetric); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, err := prometheus.RegisterOrGet(forksMetric); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, err := prometheus.RegisterOrGet(btimeMetric); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, err := prometheus.RegisterOrGet(procsRunningMetric); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, err := prometheus.RegisterOrGet(procsBlockedMetric); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
registry.Register(
|
||||
"node_cpu",
|
||||
"Seconds the cpus spent in each mode.",
|
||||
prometheus.NilLabels,
|
||||
cpuMetrics,
|
||||
)
|
||||
registry.Register(
|
||||
"node_intr",
|
||||
"Total number of interrupts serviced",
|
||||
prometheus.NilLabels,
|
||||
intrMetric,
|
||||
)
|
||||
registry.Register(
|
||||
"node_context_switches",
|
||||
"Total number of context switches.",
|
||||
prometheus.NilLabels,
|
||||
ctxtMetric,
|
||||
)
|
||||
registry.Register(
|
||||
"node_forks",
|
||||
"Total number of forks.",
|
||||
prometheus.NilLabels,
|
||||
forksMetric,
|
||||
)
|
||||
registry.Register(
|
||||
"node_boot_time",
|
||||
"Node boot time, in unixtime.",
|
||||
prometheus.NilLabels,
|
||||
btimeMetric,
|
||||
)
|
||||
registry.Register(
|
||||
"node_procs_running",
|
||||
"Number of processes in runnable state.",
|
||||
prometheus.NilLabels,
|
||||
procsRunningMetric,
|
||||
)
|
||||
registry.Register(
|
||||
"node_procs_blocked",
|
||||
"Number of processes blocked waiting for I/O to complete.",
|
||||
prometheus.NilLabels,
|
||||
procsBlockedMetric,
|
||||
)
|
||||
return &c, nil
|
||||
}
|
||||
|
||||
|
|
@ -113,9 +121,9 @@ func (c *statCollector) Update() (updates int, err error) {
|
|||
if err != nil {
|
||||
return updates, err
|
||||
}
|
||||
// Convert from ticks to seconds
|
||||
// Convert from ticks to seconds
|
||||
value /= float64(C.sysconf(C._SC_CLK_TCK))
|
||||
cpuMetrics.Set(map[string]string{"cpu": parts[0], "mode": cpuFields[i]}, value)
|
||||
cpuMetrics.With(prometheus.Labels{"cpu": parts[0], "mode": cpuFields[i]}).Set(value)
|
||||
}
|
||||
case parts[0] == "intr":
|
||||
// Only expose the overall number, use the 'interrupts' collector for more detail.
|
||||
|
|
@ -123,37 +131,37 @@ func (c *statCollector) Update() (updates int, err error) {
|
|||
if err != nil {
|
||||
return updates, err
|
||||
}
|
||||
intrMetric.Set(prometheus.NilLabels, value)
|
||||
intrMetric.Set(value)
|
||||
case parts[0] == "ctxt":
|
||||
value, err := strconv.ParseFloat(parts[1], 64)
|
||||
if err != nil {
|
||||
return updates, err
|
||||
}
|
||||
ctxtMetric.Set(prometheus.NilLabels, value)
|
||||
ctxtMetric.Set(value)
|
||||
case parts[0] == "processes":
|
||||
value, err := strconv.ParseFloat(parts[1], 64)
|
||||
if err != nil {
|
||||
return updates, err
|
||||
}
|
||||
forksMetric.Set(prometheus.NilLabels, value)
|
||||
forksMetric.Set(value)
|
||||
case parts[0] == "btime":
|
||||
value, err := strconv.ParseFloat(parts[1], 64)
|
||||
if err != nil {
|
||||
return updates, err
|
||||
}
|
||||
btimeMetric.Set(prometheus.NilLabels, value)
|
||||
btimeMetric.Set(value)
|
||||
case parts[0] == "procs_running":
|
||||
value, err := strconv.ParseFloat(parts[1], 64)
|
||||
if err != nil {
|
||||
return updates, err
|
||||
}
|
||||
procsRunningMetric.Set(prometheus.NilLabels, value)
|
||||
procsRunningMetric.Set(value)
|
||||
case parts[0] == "procs_blocked":
|
||||
value, err := strconv.ParseFloat(parts[1], 64)
|
||||
if err != nil {
|
||||
return updates, err
|
||||
}
|
||||
procsBlockedMetric.Set(prometheus.NilLabels, value)
|
||||
procsBlockedMetric.Set(value)
|
||||
}
|
||||
}
|
||||
return updates, err
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue