Commit 8480652c authored by Azat Khuziyakhmetov's avatar Azat Khuziyakhmetov
Browse files

added cgroup assignment of the job

parent 6a96dab7
......@@ -35,6 +35,7 @@ type Procstat struct {
StartFrom int
SystemdUnit string
CGroup string `toml:"cgroup"`
CGFallback bool
PidTag bool
WinService string `toml:"win_service"`
......@@ -79,6 +80,9 @@ var sampleConfig = `
## If none of monitoring options is selected. Then we monitor all processes.
## the lowest process UID to be monitored
start_from = 1000
## If you want to use CGroups as a fallback to assign JOBIDs instead of
## environment variables, then assign next conf to true (tested on Slurm)
CGFallback = true
## the list of users to be ignored
#ignore_users = ["influxdb"]
......@@ -278,34 +282,55 @@ func (p *Procstat) addMetric(proc Process, acc telegraf.Accumulator) {
pid := proc.PID()
pidenviron := "/proc/" + strconv.Itoa(int(pid)) + "/environ"
// ToDo: maybe better use Go functions instead of calling "strings"
stringsCmd := exec.Command("strings", pidenviron)
stringsOut, _ := stringsCmd.Output()
jobid_pat := regexp.MustCompile(".*JOBID=.*")
jobid_varexpr := jobid_pat.FindAllString(string(stringsOut), -1)
if len(jobid_varexpr) > 0 {
for i, _ := range jobid_varexpr {
jobid_slice := strings.Split(jobid_varexpr[i], "=")
if jobid_slice[0] == "MOAB_JOBID" {
jobid1 := jobid_slice[1]
proc.Tags()["jobid1"] = jobid1
} else if jobid_slice[0] == "PBS_JOBID" {
jobid2 := jobid_slice[1]
proc.Tags()["jobid2"] = jobid2
} else if jobid_slice[0] == "SLURM_JOBID" {
jobid := jobid_slice[1]
proc.Tags()["jobid1"] = jobid
proc.Tags()["jobid2"] = jobid
} else if jobid_slice[0] == "LSB_JOBID" {
jobid := jobid_slice[1]
proc.Tags()["jobid1"] = jobid
proc.Tags()["jobid2"] = jobid
efile, err := ioutil.ReadFile(pidenviron)
envjobfound := false
if err == nil {
jobid_pat := regexp.MustCompile("((SLURM|LSF|MOAB|PBS)_JOBID=([0-9]+))")
jobid_varexpr := jobid_pat.FindAllString(string(efile), -1)
if len(jobid_varexpr) > 0 {
for i, _ := range jobid_varexpr {
envjobfound = true
jobid_slice := strings.Split(jobid_varexpr[i], "=")
if jobid_slice[0] == "MOAB_JOBID" {
jobid1 := jobid_slice[1]
proc.Tags()["jobid1"] = jobid1
} else if jobid_slice[0] == "PBS_JOBID" {
jobid2 := jobid_slice[1]
proc.Tags()["jobid2"] = jobid2
} else if jobid_slice[0] == "SLURM_JOBID" {
jobid := jobid_slice[1]
proc.Tags()["jobid1"] = jobid
proc.Tags()["jobid2"] = jobid
} else if jobid_slice[0] == "LSB_JOBID" {
jobid := jobid_slice[1]
proc.Tags()["jobid1"] = jobid
proc.Tags()["jobid2"] = jobid
} else {
envjobfound = false
}
}
}
}
if envjobfound == false && p.CGFallback == true {
pidcgroup := "/proc/" + strconv.Itoa(int(pid)) + "/cgroup"
cgfile, err := ioutil.ReadFile(pidcgroup)
if err == nil {
jobid_pat := regexp.MustCompile("job_[0-9]+")
jobid_varexpr := jobid_pat.FindString(string(cgfile))
if len(jobid_varexpr) > 0 {
jobid_slice := strings.Split(jobid_varexpr, "_")
jobid := jobid_slice[1]
proc.Tags()["jobid1"] = jobid
proc.Tags()["jobid2"] = jobid
}
}
}
acc.AddFields("pfit-uprocstat", fields, proc.Tags())
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment