From cd532e08cbc188fc089a9e722b25c2a187fe9b12 Mon Sep 17 00:00:00 2001 From: Michael Baird Date: Tue, 13 Jun 2017 16:14:45 -0500 Subject: [PATCH] Add -b option to lsof to avoid kernel blocks. --- docs/administration.md | 2 ++ server.go | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/docs/administration.md b/docs/administration.md index 322b68e12..e562f94ce 100644 --- a/docs/administration.md +++ b/docs/administration.md @@ -157,3 +157,5 @@ We currently track the following events Garbage Collection: Event count when Garbage Collection occurs. Goroutines: Number of running Goroutines. + +OpenFiles: Number of open file handles associated with running Pilosa process ID. \ No newline at end of file diff --git a/server.go b/server.go index 7f2027f10..57f3291eb 100644 --- a/server.go +++ b/server.go @@ -513,12 +513,15 @@ func CountOpenFiles() int { case "unix": fallthrough case "freebsd": - out, err := exec.Command("/bin/sh", "-c", fmt.Sprintf("lsof -p %v", os.Getpid())).Output() + // -b option avoid kernel blocks + pid := os.Getpid() + out, err := exec.Command("/bin/sh", "-c", fmt.Sprintf("lsof -b -p %v", pid)).Output() if err != nil { log.Fatal(err) } - lines := strings.Split(string(out), "\n") - count = len(lines) - 1 + // only count lines with our pid, avoiding warning messages from -b + lines := strings.Split(string(out), strconv.Itoa(pid)) + count = len(lines) case "windows": // TODO: count open file handles on windows default: