mirror of
https://github.com/ClusterCockpit/cc-metric-collector.git
synced 2024-12-25 23:19:06 +01:00
Add collector for the top5 processes in %cpu
This commit is contained in:
parent
b84dc08cd6
commit
14bc29f766
39
collectors/topprocsMetric.go
Normal file
39
collectors/topprocsMetric.go
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
package collectors
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os/exec"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
const NUM_PROCS = 5
|
||||||
|
|
||||||
|
type TopProcsCollector struct {
|
||||||
|
MetricCollector
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *TopProcsCollector) Init() {
|
||||||
|
m.name = "TopProcsCollector"
|
||||||
|
m.setup()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *TopProcsCollector) Read(interval time.Duration) {
|
||||||
|
command := exec.Command("/usr/bin/ps", "-Ao", "comm", "--sort=-pcpu")
|
||||||
|
command.Wait()
|
||||||
|
stdout, err := command.Output()
|
||||||
|
if err != nil {
|
||||||
|
log.Print(m.name, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
lines := strings.Split(string(stdout), "\n")
|
||||||
|
for i := 1; i < NUM_PROCS+1; i++ {
|
||||||
|
m.node[fmt.Sprintf("topproc%d", i)] = lines[i]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *TopProcsCollector) Close() {
|
||||||
|
return
|
||||||
|
}
|
@ -16,6 +16,7 @@
|
|||||||
"netstat",
|
"netstat",
|
||||||
"ibstat",
|
"ibstat",
|
||||||
"lustrestat",
|
"lustrestat",
|
||||||
"cpustat"
|
"cpustat",
|
||||||
|
"topprocs"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ var Collectors = map[string]collectors.MetricGetter{
|
|||||||
"ibstat": &collectors.InfinibandCollector{},
|
"ibstat": &collectors.InfinibandCollector{},
|
||||||
"lustrestat": &collectors.LustreCollector{},
|
"lustrestat": &collectors.LustreCollector{},
|
||||||
"cpustat": &collectors.CpustatCollector{},
|
"cpustat": &collectors.CpustatCollector{},
|
||||||
|
"topprocs": &collectors.TopProcsCollector{},
|
||||||
}
|
}
|
||||||
|
|
||||||
var Sinks = map[string]sinks.SinkFuncs{
|
var Sinks = map[string]sinks.SinkFuncs{
|
||||||
|
Loading…
Reference in New Issue
Block a user