Skip to content

Commit

Permalink
Merge pull request #79 from prometheus/migrate-logging
Browse files Browse the repository at this point in the history
Switch logging from glog to github.com/prometheus/log
  • Loading branch information
juliusv committed May 28, 2015
2 parents c1992f1 + e65bc86 commit 94d2259
Show file tree
Hide file tree
Showing 19 changed files with 37 additions and 65 deletions.
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ FROM golang:onbuild
MAINTAINER Prometheus Team <prometheus-developers@googlegroups.com>

ENTRYPOINT [ "go-wrapper", "run" ]
CMD [ "-logtostderr" ]
EXPOSE 9100
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ collectors.
make
./node_exporter <flags>

The node_exporter uses the [glog][glog] library for logging. With the default
parameters, nothing will be logged. Use `-logtostderr` to enable logging to
stderr and `--help` to see more options about logging.

[glog]: https://godoc.org/github.com/golang/glog

## Running tests

make test
Expand Down
5 changes: 2 additions & 3 deletions collector/diskstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"strconv"
"strings"

"github.com/golang/glog"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/log"
)

const (
Expand All @@ -26,7 +26,6 @@ var (
)

type diskstatsCollector struct {

ignoredDevicesPattern *regexp.Regexp
metrics []prometheus.Collector
}
Expand Down Expand Up @@ -155,7 +154,7 @@ func (c *diskstatsCollector) Update(ch chan<- prometheus.Metric) (err error) {

for dev, stats := range diskStats {
if c.ignoredDevicesPattern.MatchString(dev) {
glog.V(1).Infof("Ignoring device: %s", dev)
log.Debugf("Ignoring device: %s", dev)
continue
}

Expand Down
6 changes: 2 additions & 4 deletions collector/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"strings"
"syscall"

"github.com/golang/glog"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/log"
)

const (
Expand All @@ -25,7 +25,6 @@ var (
)

type filesystemCollector struct {

ignoredMountPointsPattern *regexp.Regexp

size, free, avail, files, filesFree *prometheus.GaugeVec
Expand All @@ -41,7 +40,6 @@ func NewFilesystemCollector() (Collector, error) {
var filesystemLabelNames = []string{"filesystem"}

return &filesystemCollector{

ignoredMountPointsPattern: regexp.MustCompile(*ignoredMountPoints),
size: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Expand Down Expand Up @@ -99,7 +97,7 @@ func (c *filesystemCollector) Update(ch chan<- prometheus.Metric) (err error) {
}
for _, mp := range mps {
if c.ignoredMountPointsPattern.MatchString(mp) {
glog.V(1).Infof("Ignoring mount point: %s", mp)
log.Debugf("Ignoring mount point: %s", mp)
continue
}
buf := new(syscall.Statfs_t)
Expand Down
10 changes: 5 additions & 5 deletions collector/gmond.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import (
"regexp"
"time"

"github.com/golang/glog"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/log"

"github.com/prometheus/node_exporter/collector/ganglia"
)

Expand All @@ -25,7 +26,6 @@ const (

type gmondCollector struct {
metrics map[string]*prometheus.GaugeVec

}

func init() {
Expand All @@ -45,7 +45,7 @@ func NewGmondCollector() (Collector, error) {

func (c *gmondCollector) Update(ch chan<- prometheus.Metric) (err error) {
conn, err := net.Dial(gangliaProto, gangliaAddress)
glog.V(1).Infof("gmondCollector Update")
log.Debugf("gmondCollector Update")
if err != nil {
return fmt.Errorf("Can't connect to gmond: %s", err)
}
Expand Down Expand Up @@ -91,7 +91,7 @@ func (c *gmondCollector) setMetric(name, cluster string, metric ganglia.Metric)
break
}
}
glog.V(1).Infof("Register %s: %s", name, desc)
log.Debugf("Register %s: %s", name, desc)
c.metrics[name] = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: gangliaNamespace,
Expand All @@ -101,7 +101,7 @@ func (c *gmondCollector) setMetric(name, cluster string, metric ganglia.Metric)
[]string{"cluster"},
)
}
glog.V(1).Infof("Set %s{cluster=%q}: %f", name, cluster, metric.Value)
log.Debugf("Set %s{cluster=%q}: %f", name, cluster, metric.Value)
c.metrics[name].WithLabelValues(cluster).Set(metric.Value)
}

Expand Down
2 changes: 0 additions & 2 deletions collector/interrupts.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const (
)

type interruptsCollector struct {

metric *prometheus.CounterVec
}

Expand All @@ -30,7 +29,6 @@ func init() {
// interrupts stats
func NewInterruptsCollector() (Collector, error) {
return &interruptsCollector{

metric: prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: Namespace,
Expand Down
6 changes: 2 additions & 4 deletions collector/lastlogin.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ import (
"strings"
"time"

"github.com/golang/glog"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/log"
)

const lastLoginSubsystem = "last_login"

type lastLoginCollector struct {

metric prometheus.Gauge
}

Expand All @@ -29,7 +28,6 @@ func init() {
// load, seconds since last login and a list of tags as specified by config.
func NewLastLoginCollector() (Collector, error) {
return &lastLoginCollector{

metric: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: Namespace,
Subsystem: lastLoginSubsystem,
Expand All @@ -44,7 +42,7 @@ func (c *lastLoginCollector) Update(ch chan<- prometheus.Metric) (err error) {
if err != nil {
return fmt.Errorf("Couldn't get last seen: %s", err)
}
glog.V(1).Infof("Set node_last_login_time: %f", last)
log.Debugf("Set node_last_login_time: %f", last)
c.metric.Set(last)
c.metric.Collect(ch)
return err
Expand Down
6 changes: 2 additions & 4 deletions collector/loadavg.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ import (
"strconv"
"strings"

"github.com/golang/glog"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/log"
)

const (
procLoad = "/proc/loadavg"
)

type loadavgCollector struct {

metric prometheus.Gauge
}

Expand All @@ -29,7 +28,6 @@ func init() {
// load, seconds since last login and a list of tags as specified by config.
func NewLoadavgCollector() (Collector, error) {
return &loadavgCollector{

metric: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: Namespace,
Name: "load1",
Expand All @@ -43,7 +41,7 @@ func (c *loadavgCollector) Update(ch chan<- prometheus.Metric) (err error) {
if err != nil {
return fmt.Errorf("Couldn't get load: %s", err)
}
glog.V(1).Infof("Set node_load: %f", load)
log.Debugf("Set node_load: %f", load)
c.metric.Set(load)
c.metric.Collect(ch)
return err
Expand Down
3 changes: 1 addition & 2 deletions collector/megacli.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ func init() {
// RAID status through megacli.
func NewMegaCliCollector() (Collector, error) {
return &megaCliCollector{

cli: *megacliCommand,
cli: *megacliCommand,
driveTemperature: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: Namespace,
Name: "megacli_drive_temperature_celsius",
Expand Down
5 changes: 2 additions & 3 deletions collector/meminfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"strconv"
"strings"

"github.com/golang/glog"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/log"
)

const (
Expand All @@ -21,7 +21,6 @@ const (
)

type meminfoCollector struct {

metrics map[string]prometheus.Gauge
}

Expand All @@ -42,7 +41,7 @@ func (c *meminfoCollector) Update(ch chan<- prometheus.Metric) (err error) {
if err != nil {
return fmt.Errorf("Couldn't get meminfo: %s", err)
}
glog.V(1).Infof("Set node_mem: %#v", memInfo)
log.Debugf("Set node_mem: %#v", memInfo)
for k, v := range memInfo {
if _, ok := c.metrics[k]; !ok {
c.metrics[k] = prometheus.NewGauge(prometheus.GaugeOpts{
Expand Down
1 change: 0 additions & 1 deletion collector/netdev.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ var (
)

type netDevCollector struct {

metrics map[string]*prometheus.GaugeVec
}

Expand Down
1 change: 0 additions & 1 deletion collector/netstat.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const (
)

type netStatCollector struct {

metrics map[string]prometheus.Gauge
}

Expand Down
4 changes: 2 additions & 2 deletions collector/ntp.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"time"

"github.com/beevik/ntp"
"github.com/golang/glog"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/log"
)

var (
Expand Down Expand Up @@ -46,7 +46,7 @@ func (c *ntpCollector) Update(ch chan<- prometheus.Metric) (err error) {
return fmt.Errorf("Couldn't get ntp drift: %s", err)
}
drift := t.Sub(time.Now())
glog.V(1).Infof("Set ntp_drift_seconds: %f", drift.Seconds())
log.Debugf("Set ntp_drift_seconds: %f", drift.Seconds())
c.drift.Set(drift.Seconds())
c.drift.Collect(ch)
return err
Expand Down
9 changes: 3 additions & 6 deletions collector/runit.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
package collector

import (
"github.com/golang/glog"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/log"
"github.com/soundcloud/go-runit/runit"
)

type runitCollector struct {


state, stateDesired, stateNormal *prometheus.GaugeVec
}

Expand All @@ -26,7 +24,6 @@ func NewRunitCollector() (Collector, error) {
)

return &runitCollector{

state: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: Namespace,
Expand Down Expand Up @@ -69,11 +66,11 @@ func (c *runitCollector) Update(ch chan<- prometheus.Metric) error {
for _, service := range services {
status, err := service.Status()
if err != nil {
glog.V(1).Infof("Couldn't get status for %s: %s, skipping...", service.Name, err)
log.Debugf("Couldn't get status for %s: %s, skipping...", service.Name, err)
continue
}

glog.V(1).Infof("%s is %d on pid %d for %d seconds", service.Name, status.State, status.Pid, status.Duration)
log.Debugf("%s is %d on pid %d for %d seconds", service.Name, status.State, status.Pid, status.Duration)
c.state.WithLabelValues(service.Name).Set(float64(status.State))
c.stateDesired.WithLabelValues(service.Name).Set(float64(status.Want))
if status.NormallyUp {
Expand Down
2 changes: 0 additions & 2 deletions collector/stat.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const (
)

type statCollector struct {

cpu *prometheus.CounterVec
intr prometheus.Counter
ctxt prometheus.Counter
Expand All @@ -35,7 +34,6 @@ func init() {
// network device stats.
func NewStatCollector() (Collector, error) {
return &statCollector{

cpu: prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: Namespace,
Expand Down
2 changes: 0 additions & 2 deletions collector/tcpstat.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ const (
)

type tcpStatCollector struct {

metric *prometheus.GaugeVec
}

Expand All @@ -47,7 +46,6 @@ func init() {
// a new Collector exposing network stats.
func NewTCPStatCollector() (Collector, error) {
return &tcpStatCollector{

metric: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: Namespace,
Expand Down
8 changes: 4 additions & 4 deletions collector/textfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (

dto "github.com/prometheus/client_model/go"

"github.com/golang/glog"
"github.com/golang/protobuf/proto"
"github.com/prometheus/log"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/text"
Expand All @@ -37,7 +37,7 @@ func NewTextFileCollector() (Collector, error) {
if *textFileDirectory == "" {
// This collector is enabled by default, so do not fail if
// the flag is not passed.
glog.Infof("No directory specified, see --textfile.directory")
log.Infof("No directory specified, see --textfile.directory")
} else {
prometheus.SetMetricFamilyInjectionHook(parseTextFiles)
}
Expand Down Expand Up @@ -65,13 +65,13 @@ func parseTextFiles() []*dto.MetricFamily {
path := filepath.Join(*textFileDirectory, f.Name())
file, err := os.Open(path)
if err != nil {
glog.Errorf("Error opening %s: %v", path, err)
log.Errorf("Error opening %s: %v", path, err)
error = 1.0
continue
}
parsedFamilies, err := parser.TextToMetricFamilies(file)
if err != nil {
glog.Errorf("Error parsing %s: %v", path, err)
log.Errorf("Error parsing %s: %v", path, err)
error = 1.0
continue
}
Expand Down
Loading

0 comments on commit 94d2259

Please sign in to comment.