Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix:the proc name is not be static when the proc start time is in 1 minute #192

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ load-generator
integration-tester
dist
/vendor
cmd/process-exporter/bin/
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ vet:

build:
@echo ">> building code"
cd cmd/process-exporter; CGO_ENABLED=0 go build -ldflags "$(VERSION_LDFLAGS)" -o ../../process-exporter -a -tags netgo
cd cmd/process-exporter; CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "$(VERSION_LDFLAGS)" -o ../../process-exporter -a -tags netgo

smoke:
@echo ">> smoke testing process-exporter"
Expand Down
36 changes: 31 additions & 5 deletions proc/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,22 +264,48 @@ func (t *Tracker) handleProc(proc Proc, updateTime time.Time) (*IDInfo, CollectE
}
}

var newProc *IDInfo
var static Static

// the exec name was changed,need recal the proc info
var recheck_name bool
if known {
last.update(metrics, updateTime, &cerrs, threads)
} else {
static, err := proc.GetStatic()
if d := time.Now().UTC().Sub(last.static.StartTime); d < 1*time.Minute {
log.Printf("the proc id:%+v was running %+v", procID, d)
recheck_name = true
}
}
if !known || recheck_name {
static, err = proc.GetStatic()
if err != nil {
if t.debug {
log.Printf("error reading static details for %+v: %v", procID, err)
}
return nil, cerrs
}

if recheck_name && last.static.Name != static.Name {
log.Printf("last info=%+v now info=%+v", last.static, static)
known = false // the exec name was changed,need recal the proc info
} else if recheck_name {
log.Println("the proc stat is not change,pid=", proc.GetPid())
}
}

var newProc *IDInfo
if known {
last.update(metrics, updateTime, &cerrs, threads)
} else {
// static, err := proc.GetStatic()
// if err != nil {
// if t.debug {
// log.Printf("error reading static details for %+v: %v", procID, err)
// }
// return nil, cerrs
// }
newProc = &IDInfo{procID, static, metrics, threads}
if t.debug {
log.Printf("found new proc: %s", newProc)
}

// Is this a new process with the same pid as one we already know?
// Then delete it from the known map, otherwise the cleanup in Update()
// will remove the ProcIds entry we're creating here.
Expand Down