Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
IN-2226: fix whitelist cpu and disk metrics (#100)
* fix: whitelist node cpu and disk metrics

* add .ignore file
  • Loading branch information
blockloop committed Feb 19, 2019
1 parent 129bae8 commit 9fd146d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions .ignore
@@ -0,0 +1 @@
vendor/
7 changes: 2 additions & 5 deletions internal/log/log.go
Expand Up @@ -5,15 +5,12 @@ import (
"log"
"log/syslog"
"os"

"github.com/pkg/errors"
)

// Level is a log level such a Debug or Error
type Level int

const (
initFailed = "failed to initialize syslog logger"
syslogFlags = log.Llongfile
normalFlags = log.LUTC | log.Ldate | log.Ltime | log.Llongfile

Expand All @@ -39,13 +36,13 @@ func SetLevel(l Level) {
func InitSyslog() (err error) {
dl, err := syslog.NewLogger(syslog.LOG_NOTICE, syslogFlags)
if err != nil {
return errors.Wrap(err, initFailed)
return fmt.Errorf("InitSyslog failed to initialize debug logger: %+v", err)
}
debuglog = dl

el, err := syslog.NewLogger(syslog.LOG_ERR, syslogFlags)
if err != nil {
return errors.Wrap(err, initFailed)
return fmt.Errorf("InitSyslog failed to initialize error logger: %+v", err)
}
errlog = el

Expand Down
7 changes: 7 additions & 0 deletions pkg/collector/node.go
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"strings"

"github.com/digitalocean/do-agent/internal/log"

"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/node_exporter/collector"
Expand All @@ -20,6 +22,9 @@ var whitelist = []string{
"node_memory_swaptotal_bytes",
"node_filesystem_size_bytes",
"node_filesystem_free_bytes",
"node_disk_read_bytes_total",
"node_disk_written_bytes_total",
"node_cpu_seconds_total",
"node_load1",
"node_load5",
"node_load15",
Expand Down Expand Up @@ -75,6 +80,8 @@ func (n *NodeCollector) Collect(ch chan<- prometheus.Metric) {
for _, s := range whitelist {
if strings.Contains(d, fmt.Sprintf(`fqname: "%s"`, s)) {
ch <- m
} else {
log.Debug("Node metric not whitelisted. Ignoring: %q", d)
}
}
}
Expand Down

0 comments on commit 9fd146d

Please sign in to comment.