Skip to content

Commit

Permalink
Use levelled logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Alfonso Acosta committed Feb 8, 2016
1 parent c20707a commit c7a60b6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
17 changes: 9 additions & 8 deletions probe/endpoint/procspy/background_reader_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package procspy
import (
"bytes"
"fmt"
"log"
"math"
"sync"
"time"

log "github.com/Sirupsen/logrus"

"github.com/weaveworks/scope/probe/process"
)

Expand All @@ -28,8 +29,6 @@ type backgroundReader struct {
readySockets map[uint64]*Proc
}

// starts a rate-limited background goroutine to read the expensive files from
// proc.
func newBackgroundReader(walker process.Walker) *backgroundReader {
br := &backgroundReader{
walker: walker,
Expand All @@ -39,6 +38,8 @@ func newBackgroundReader(walker process.Walker) *backgroundReader {
return br
}

// starts a rate-limited background goroutine to read the expensive files from
// proc.
func (br *backgroundReader) start() error {
br.mtx.Lock()
defer br.mtx.Unlock()
Expand Down Expand Up @@ -72,7 +73,7 @@ func (br *backgroundReader) loop() {
start := time.Now()
sockets, err := walkProcPid(br.walkingBuf, br.walker, ticker.C, fdBlockSize)
if err != nil {
log.Printf("background reader: error walking /proc: %s\n", err)
log.Errorf("background /proc reader: error walking /proc: %s\n", err)
continue
}

Expand All @@ -96,10 +97,10 @@ func (br *backgroundReader) loop() {
walkTime := time.Now().Sub(start)
walkTimeF := float64(walkTime)

log.Printf("debug: background reader: full pass took %s\n", walkTime)
log.Debugf("background /proc reader: full pass took %s\n", walkTime)
if walkTimeF/targetWalkTimeF > 1.5 {
log.Printf(
"warn: background reader: full pass took %s: 50%% more than expected (%s)\n",
log.Warnf(
"background /proc reader: full pass took %s: 50%% more than expected (%s)\n",
walkTime,
targetWalkTime,
)
Expand All @@ -108,7 +109,7 @@ func (br *backgroundReader) loop() {
// Adjust rate limit to more-accurately meet the target walk time in next iteration
scaledRateLimit := targetWalkTimeF / walkTimeF * float64(rateLimit)
rateLimit = time.Duration(math.Min(scaledRateLimit, maxRateLimitF))
log.Printf("debug: background reader: new rate limit %s\n", rateLimit)
log.Debugf("background /proc reader: new rate limit %s\n", rateLimit)

ticker.Stop()
ticker = time.NewTicker(rateLimit)
Expand Down
1 change: 1 addition & 0 deletions prog/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/weaveworks/scope/probe/controls"
"github.com/weaveworks/scope/probe/docker"
"github.com/weaveworks/scope/probe/endpoint"
"github.com/weaveworks/scope/probe/endpoint/procspy"
"github.com/weaveworks/scope/probe/host"
"github.com/weaveworks/scope/probe/kubernetes"
"github.com/weaveworks/scope/probe/overlay"
Expand Down

0 comments on commit c7a60b6

Please sign in to comment.