Skip to content

Commit

Permalink
Remove -threads option, make it the default now. Fix integration test…
Browse files Browse the repository at this point in the history
… intermittent failure.
  • Loading branch information
ncabatoff committed Sep 3, 2018
1 parent 9280e79 commit 990f810
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 59 deletions.
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ walking the process tree upwards. In other words, resource usage of
subprocesses is added to their parent's usage unless the subprocess identifies
as a different group name.

-threads (default:false) means that metrics will be broken down by thread name
as well as group name.

-recheck (default:false) means that on each scrape the process names are
re-evaluated. This is disabled by default as an optimization, but since
processes can choose to change their names, this may result in a process
Expand Down Expand Up @@ -300,9 +297,6 @@ The extra label `state` can have these values: `Running`, `Sleeping`, `Waiting`,

## Group Thread Metrics

Since publishing thread metrics adds a lot of overhead, these metrics are disabled
by default. Use the -threads command-line argument to enable them.

All these metrics start with `namedprocess_namegroup_` and have at minimum
the labels `groupname` and `threadname`. `threadname` is field comm(2) from
/proc/[pid]/stat. Just as groupname breaks the set of processes down into
Expand Down
67 changes: 30 additions & 37 deletions cmd/process-exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,6 @@ func main() {
"comma-seperated list, alternating process name and capturing regex to apply to cmdline")
children = flag.Bool("children", true,
"if a proc is tracked, track with it any children that aren't part of their own group")
threads = flag.Bool("threads", false,
"report on per-threadname metrics as well")
man = flag.Bool("man", false,
"print manual")
configPath = flag.String("config.path", "",
Expand Down Expand Up @@ -349,7 +347,7 @@ func main() {
matchnamer = namemapper
}

pc, err := NewProcessCollector(*procfsPath, *children, *threads, matchnamer, *recheck, *debug)
pc, err := NewProcessCollector(*procfsPath, *children, matchnamer, *recheck, *debug)
if err != nil {
log.Fatalf("Error initializing: %v", err)
}
Expand Down Expand Up @@ -391,7 +389,6 @@ type (
NamedProcessCollector struct {
scrapeChan chan scrapeRequest
*proc.Grouper
threads bool
source proc.Source
scrapeErrors int
scrapeProcReadErrors int
Expand All @@ -403,7 +400,6 @@ type (
func NewProcessCollector(
procfsPath string,
children bool,
threads bool,
n common.MatchNamer,
recheck bool,
debug bool,
Expand All @@ -414,9 +410,8 @@ func NewProcessCollector(
}
p := &NamedProcessCollector{
scrapeChan: make(chan scrapeRequest),
Grouper: proc.NewGrouper(n, children, threads, recheck, debug),
Grouper: proc.NewGrouper(n, children, recheck, debug),
source: fs,
threads: threads,
debug: debug,
}

Expand Down Expand Up @@ -534,36 +529,34 @@ func (p *NamedProcessCollector) scrape(ch chan<- prometheus.Metric) {
prometheus.GaugeValue, float64(count), gname, wchan)
}

if p.threads {
for _, thr := range gcounts.Threads {
ch <- prometheus.MustNewConstMetric(threadCountDesc,
prometheus.GaugeValue, float64(thr.NumThreads),
gname, thr.Name)
ch <- prometheus.MustNewConstMetric(threadCpuSecsDesc,
prometheus.CounterValue, float64(thr.CPUUserTime),
gname, thr.Name, "user")
ch <- prometheus.MustNewConstMetric(threadCpuSecsDesc,
prometheus.CounterValue, float64(thr.CPUSystemTime),
gname, thr.Name, "system")
ch <- prometheus.MustNewConstMetric(threadIoBytesDesc,
prometheus.CounterValue, float64(thr.ReadBytes),
gname, thr.Name, "read")
ch <- prometheus.MustNewConstMetric(threadIoBytesDesc,
prometheus.CounterValue, float64(thr.WriteBytes),
gname, thr.Name, "write")
ch <- prometheus.MustNewConstMetric(threadMajorPageFaultsDesc,
prometheus.CounterValue, float64(thr.MajorPageFaults),
gname, thr.Name)
ch <- prometheus.MustNewConstMetric(threadMinorPageFaultsDesc,
prometheus.CounterValue, float64(thr.MinorPageFaults),
gname, thr.Name)
ch <- prometheus.MustNewConstMetric(threadContextSwitchesDesc,
prometheus.CounterValue, float64(thr.CtxSwitchVoluntary),
gname, thr.Name, "voluntary")
ch <- prometheus.MustNewConstMetric(threadContextSwitchesDesc,
prometheus.CounterValue, float64(thr.CtxSwitchNonvoluntary),
gname, thr.Name, "nonvoluntary")
}
for _, thr := range gcounts.Threads {
ch <- prometheus.MustNewConstMetric(threadCountDesc,
prometheus.GaugeValue, float64(thr.NumThreads),
gname, thr.Name)
ch <- prometheus.MustNewConstMetric(threadCpuSecsDesc,
prometheus.CounterValue, float64(thr.CPUUserTime),
gname, thr.Name, "user")
ch <- prometheus.MustNewConstMetric(threadCpuSecsDesc,
prometheus.CounterValue, float64(thr.CPUSystemTime),
gname, thr.Name, "system")
ch <- prometheus.MustNewConstMetric(threadIoBytesDesc,
prometheus.CounterValue, float64(thr.ReadBytes),
gname, thr.Name, "read")
ch <- prometheus.MustNewConstMetric(threadIoBytesDesc,
prometheus.CounterValue, float64(thr.WriteBytes),
gname, thr.Name, "write")
ch <- prometheus.MustNewConstMetric(threadMajorPageFaultsDesc,
prometheus.CounterValue, float64(thr.MajorPageFaults),
gname, thr.Name)
ch <- prometheus.MustNewConstMetric(threadMinorPageFaultsDesc,
prometheus.CounterValue, float64(thr.MinorPageFaults),
gname, thr.Name)
ch <- prometheus.MustNewConstMetric(threadContextSwitchesDesc,
prometheus.CounterValue, float64(thr.CtxSwitchVoluntary),
gname, thr.Name, "voluntary")
ch <- prometheus.MustNewConstMetric(threadContextSwitchesDesc,
prometheus.CounterValue, float64(thr.CtxSwitchNonvoluntary),
gname, thr.Name, "nonvoluntary")
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions proc/grouper.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ type (
func lessThreads(x, y Threads) bool { return seq.Compare(x, y) < 0 }

// NewGrouper creates a grouper.
func NewGrouper(namer common.MatchNamer, trackChildren, trackThreads, alwaysRecheck, debug bool) *Grouper {
func NewGrouper(namer common.MatchNamer, trackChildren, alwaysRecheck, debug bool) *Grouper {
g := Grouper{
groupAccum: make(map[string]Counts),
threadAccum: make(map[string]map[string]Threads),
tracker: NewTracker(namer, trackChildren, trackThreads, alwaysRecheck, debug),
tracker: NewTracker(namer, trackChildren, alwaysRecheck, debug),
debug: debug,
}
return &g
Expand Down
8 changes: 4 additions & 4 deletions proc/grouper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func TestGrouperBasic(t *testing.T) {
},
}

gr := NewGrouper(newNamer(n1, n2), false, false, false, false)
gr := NewGrouper(newNamer(n1, n2), false, false, false)
for i, tc := range tests {
got := rungroup(t, gr, procInfoIter(tc.procs...))
if diff := cmp.Diff(got, tc.want); diff != "" {
Expand Down Expand Up @@ -128,7 +128,7 @@ func TestGrouperProcJoin(t *testing.T) {
},
}

gr := NewGrouper(newNamer(n1), false, false, false, false)
gr := NewGrouper(newNamer(n1), false, false, false)
for i, tc := range tests {
got := rungroup(t, gr, procInfoIter(tc.procs...))
if diff := cmp.Diff(got, tc.want); diff != "" {
Expand Down Expand Up @@ -171,7 +171,7 @@ func TestGrouperNonDecreasing(t *testing.T) {
},
}

gr := NewGrouper(newNamer(n1), false, false, false, false)
gr := NewGrouper(newNamer(n1), false, false, false)
for i, tc := range tests {
got := rungroup(t, gr, procInfoIter(tc.procs...))
if diff := cmp.Diff(got, tc.want); diff != "" {
Expand Down Expand Up @@ -224,7 +224,7 @@ func TestGrouperThreads(t *testing.T) {
}

opts := cmpopts.SortSlices(lessThreads)
gr := NewGrouper(newNamer(n), false, true, false, false)
gr := NewGrouper(newNamer(n), false, false, false)
for i, tc := range tests {
got := rungroup(t, gr, procInfoIter(tc.proc))
if diff := cmp.Diff(got, tc.want, opts); diff != "" {
Expand Down
8 changes: 2 additions & 6 deletions proc/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ type (
// trackChildren makes Tracker track descendants of procs the
// namer wanted tracked.
trackChildren bool
// trackThreads makes Tracker track per-thread metrics.
trackThreads bool
// never ignore processes, i.e. always re-check untracked processes in case comm has changed
alwaysRecheck bool
username map[int]string
Expand Down Expand Up @@ -87,8 +85,7 @@ type (
States
// Wchans is how many threads are in each non-zero wchan.
Wchans map[string]int
// Threads are the thread updates for this process, if the Tracker
// has trackThreads==true.
// Threads are the thread updates for this process.
Threads []ThreadUpdate
}

Expand Down Expand Up @@ -138,13 +135,12 @@ func (tp *trackedProc) getUpdate() Update {
}

// NewTracker creates a Tracker.
func NewTracker(namer common.MatchNamer, trackChildren, trackThreads, alwaysRecheck, debug bool) *Tracker {
func NewTracker(namer common.MatchNamer, trackChildren, alwaysRecheck, debug bool) *Tracker {
return &Tracker{
namer: namer,
tracked: make(map[ID]*trackedProc),
procIds: make(map[int]ID),
trackChildren: trackChildren,
trackThreads: trackThreads,
alwaysRecheck: alwaysRecheck,
username: make(map[int]string),
debug: debug,
Expand Down
8 changes: 4 additions & 4 deletions proc/tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestTrackerBasic(t *testing.T) {
},
}
// Note that n3 should not be tracked according to our namer.
tr := NewTracker(newNamer(n1, n2, n4), false, false, false, false)
tr := NewTracker(newNamer(n1, n2, n4), false, false, false)

opts := cmpopts.SortSlices(lessUpdateGroupName)
for i, tc := range tests {
Expand Down Expand Up @@ -78,7 +78,7 @@ func TestTrackerChildren(t *testing.T) {
},
}
// Only n2 and children of n2s should be tracked
tr := NewTracker(newNamer(n2), true, false, false, false)
tr := NewTracker(newNamer(n2), true, false, false)

for i, tc := range tests {
_, got, err := tr.Update(procInfoIter(tc.procs...))
Expand Down Expand Up @@ -111,7 +111,7 @@ func TestTrackerMetrics(t *testing.T) {
Filedesc{2, 20}, tm, 1, States{Running: 1}, msi{}, nil},
},
}
tr := NewTracker(newNamer(n), false, false, false, false)
tr := NewTracker(newNamer(n), false, false, false)

for i, tc := range tests {
_, got, err := tr.Update(procInfoIter(tc.proc))
Expand Down Expand Up @@ -169,7 +169,7 @@ func TestTrackerThreads(t *testing.T) {
},
},
}
tr := NewTracker(newNamer(n), false, true, false, false)
tr := NewTracker(newNamer(n), false, false, false)

opts := cmpopts.SortSlices(lessThreadUpdate)
for i, tc := range tests {
Expand Down

0 comments on commit 990f810

Please # to comment.