Trim exec path in middle (#22)
This commit is contained in:
parent
826c161de6
commit
15c70a8254
|
@ -239,8 +239,10 @@ func getProcInfo(pids []int, metric *CgroupMetric, logger log.Logger) {
|
|||
}
|
||||
if len(executable) > *collectProcMaxExec {
|
||||
level.Debug(logger).Log("msg", "Executable will be truncated", "executable", executable, "len", len(executable), "pid", p)
|
||||
executable = executable[len(executable)-*collectProcMaxExec:]
|
||||
executable = fmt.Sprintf("...%s", executable)
|
||||
trim := *collectProcMaxExec / 2
|
||||
executable_prefix := executable[0:trim]
|
||||
executable_suffix := executable[len(executable)-trim:]
|
||||
executable = fmt.Sprintf("%s...%s", executable_prefix, executable_suffix)
|
||||
}
|
||||
metricLock.Lock()
|
||||
executables[executable] += 1
|
||||
|
@ -479,6 +481,7 @@ func metricsHandler(logger log.Logger) http.HandlerFunc {
|
|||
|
||||
exporter := NewExporter(paths, logger)
|
||||
registry.MustRegister(exporter)
|
||||
registry.MustRegister(version.NewCollector(fmt.Sprintf("%s_exporter", namespace)))
|
||||
|
||||
gatherers := prometheus.Gatherers{registry}
|
||||
if !*disableExporterMetrics {
|
||||
|
|
|
@ -96,15 +96,15 @@ func TestGetProcInfo(t *testing.T) {
|
|||
t.Errorf("Expected 2 /bin/bash processes, got %v", val)
|
||||
}
|
||||
}
|
||||
varLen := 4
|
||||
varLen := 6
|
||||
collectProcMaxExec = &varLen
|
||||
getProcInfo([]int{95521, 95525}, &metric, logger)
|
||||
if val, ok := metric.processExec["...bash"]; !ok {
|
||||
if val, ok := metric.processExec["/bi...ash"]; !ok {
|
||||
t.Errorf("Process /bin/bash not in metrics, found: %v", metric.processExec)
|
||||
return
|
||||
} else {
|
||||
if val != 2 {
|
||||
t.Errorf("Expected 2 .../bash processes, got %v", val)
|
||||
t.Errorf("Expected 2 /b...sh processes, got %v", val)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue