Skip to content

Commit 94d2259

Browse files
committed
Merge pull request #79 from prometheus/migrate-logging
Switch logging from glog to github.com/prometheus/log
2 parents c1992f1 + e65bc86 commit 94d2259

19 files changed

+37
-65
lines changed

Dockerfile

-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ FROM golang:onbuild
22
MAINTAINER Prometheus Team <[email protected]>
33

44
ENTRYPOINT [ "go-wrapper", "run" ]
5-
CMD [ "-logtostderr" ]
65
EXPOSE 9100

README.md

-6
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ collectors.
1010
make
1111
./node_exporter <flags>
1212

13-
The node_exporter uses the [glog][glog] library for logging. With the default
14-
parameters, nothing will be logged. Use `-logtostderr` to enable logging to
15-
stderr and `--help` to see more options about logging.
16-
17-
[glog]: https://godoc.org/github.com/golang/glog
18-
1913
## Running tests
2014

2115
make test

collector/diskstats.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import (
1212
"strconv"
1313
"strings"
1414

15-
"github.com/golang/glog"
1615
"github.com/prometheus/client_golang/prometheus"
16+
"github.com/prometheus/log"
1717
)
1818

1919
const (
@@ -26,7 +26,6 @@ var (
2626
)
2727

2828
type diskstatsCollector struct {
29-
3029
ignoredDevicesPattern *regexp.Regexp
3130
metrics []prometheus.Collector
3231
}
@@ -155,7 +154,7 @@ func (c *diskstatsCollector) Update(ch chan<- prometheus.Metric) (err error) {
155154

156155
for dev, stats := range diskStats {
157156
if c.ignoredDevicesPattern.MatchString(dev) {
158-
glog.V(1).Infof("Ignoring device: %s", dev)
157+
log.Debugf("Ignoring device: %s", dev)
159158
continue
160159
}
161160

collector/filesystem.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
"strings"
1212
"syscall"
1313

14-
"github.com/golang/glog"
1514
"github.com/prometheus/client_golang/prometheus"
15+
"github.com/prometheus/log"
1616
)
1717

1818
const (
@@ -25,7 +25,6 @@ var (
2525
)
2626

2727
type filesystemCollector struct {
28-
2928
ignoredMountPointsPattern *regexp.Regexp
3029

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

4342
return &filesystemCollector{
44-
4543
ignoredMountPointsPattern: regexp.MustCompile(*ignoredMountPoints),
4644
size: prometheus.NewGaugeVec(
4745
prometheus.GaugeOpts{
@@ -99,7 +97,7 @@ func (c *filesystemCollector) Update(ch chan<- prometheus.Metric) (err error) {
9997
}
10098
for _, mp := range mps {
10199
if c.ignoredMountPointsPattern.MatchString(mp) {
102-
glog.V(1).Infof("Ignoring mount point: %s", mp)
100+
log.Debugf("Ignoring mount point: %s", mp)
103101
continue
104102
}
105103
buf := new(syscall.Statfs_t)

collector/gmond.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ import (
1111
"regexp"
1212
"time"
1313

14-
"github.com/golang/glog"
1514
"github.com/prometheus/client_golang/prometheus"
15+
"github.com/prometheus/log"
16+
1617
"github.com/prometheus/node_exporter/collector/ganglia"
1718
)
1819

@@ -25,7 +26,6 @@ const (
2526

2627
type gmondCollector struct {
2728
metrics map[string]*prometheus.GaugeVec
28-
2929
}
3030

3131
func init() {
@@ -45,7 +45,7 @@ func NewGmondCollector() (Collector, error) {
4545

4646
func (c *gmondCollector) Update(ch chan<- prometheus.Metric) (err error) {
4747
conn, err := net.Dial(gangliaProto, gangliaAddress)
48-
glog.V(1).Infof("gmondCollector Update")
48+
log.Debugf("gmondCollector Update")
4949
if err != nil {
5050
return fmt.Errorf("Can't connect to gmond: %s", err)
5151
}
@@ -91,7 +91,7 @@ func (c *gmondCollector) setMetric(name, cluster string, metric ganglia.Metric)
9191
break
9292
}
9393
}
94-
glog.V(1).Infof("Register %s: %s", name, desc)
94+
log.Debugf("Register %s: %s", name, desc)
9595
c.metrics[name] = prometheus.NewGaugeVec(
9696
prometheus.GaugeOpts{
9797
Namespace: gangliaNamespace,
@@ -101,7 +101,7 @@ func (c *gmondCollector) setMetric(name, cluster string, metric ganglia.Metric)
101101
[]string{"cluster"},
102102
)
103103
}
104-
glog.V(1).Infof("Set %s{cluster=%q}: %f", name, cluster, metric.Value)
104+
log.Debugf("Set %s{cluster=%q}: %f", name, cluster, metric.Value)
105105
c.metrics[name].WithLabelValues(cluster).Set(metric.Value)
106106
}
107107

collector/interrupts.go

-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ const (
1818
)
1919

2020
type interruptsCollector struct {
21-
2221
metric *prometheus.CounterVec
2322
}
2423

@@ -30,7 +29,6 @@ func init() {
3029
// interrupts stats
3130
func NewInterruptsCollector() (Collector, error) {
3231
return &interruptsCollector{
33-
3432
metric: prometheus.NewCounterVec(
3533
prometheus.CounterOpts{
3634
Namespace: Namespace,

collector/lastlogin.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@ import (
1010
"strings"
1111
"time"
1212

13-
"github.com/golang/glog"
1413
"github.com/prometheus/client_golang/prometheus"
14+
"github.com/prometheus/log"
1515
)
1616

1717
const lastLoginSubsystem = "last_login"
1818

1919
type lastLoginCollector struct {
20-
2120
metric prometheus.Gauge
2221
}
2322

@@ -29,7 +28,6 @@ func init() {
2928
// load, seconds since last login and a list of tags as specified by config.
3029
func NewLastLoginCollector() (Collector, error) {
3130
return &lastLoginCollector{
32-
3331
metric: prometheus.NewGauge(prometheus.GaugeOpts{
3432
Namespace: Namespace,
3533
Subsystem: lastLoginSubsystem,
@@ -44,7 +42,7 @@ func (c *lastLoginCollector) Update(ch chan<- prometheus.Metric) (err error) {
4442
if err != nil {
4543
return fmt.Errorf("Couldn't get last seen: %s", err)
4644
}
47-
glog.V(1).Infof("Set node_last_login_time: %f", last)
45+
log.Debugf("Set node_last_login_time: %f", last)
4846
c.metric.Set(last)
4947
c.metric.Collect(ch)
5048
return err

collector/loadavg.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@ import (
88
"strconv"
99
"strings"
1010

11-
"github.com/golang/glog"
1211
"github.com/prometheus/client_golang/prometheus"
12+
"github.com/prometheus/log"
1313
)
1414

1515
const (
1616
procLoad = "/proc/loadavg"
1717
)
1818

1919
type loadavgCollector struct {
20-
2120
metric prometheus.Gauge
2221
}
2322

@@ -29,7 +28,6 @@ func init() {
2928
// load, seconds since last login and a list of tags as specified by config.
3029
func NewLoadavgCollector() (Collector, error) {
3130
return &loadavgCollector{
32-
3331
metric: prometheus.NewGauge(prometheus.GaugeOpts{
3432
Namespace: Namespace,
3533
Name: "load1",
@@ -43,7 +41,7 @@ func (c *loadavgCollector) Update(ch chan<- prometheus.Metric) (err error) {
4341
if err != nil {
4442
return fmt.Errorf("Couldn't get load: %s", err)
4543
}
46-
glog.V(1).Infof("Set node_load: %f", load)
44+
log.Debugf("Set node_load: %f", load)
4745
c.metric.Set(load)
4846
c.metric.Collect(ch)
4947
return err

collector/megacli.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ func init() {
3838
// RAID status through megacli.
3939
func NewMegaCliCollector() (Collector, error) {
4040
return &megaCliCollector{
41-
42-
cli: *megacliCommand,
41+
cli: *megacliCommand,
4342
driveTemperature: prometheus.NewGaugeVec(prometheus.GaugeOpts{
4443
Namespace: Namespace,
4544
Name: "megacli_drive_temperature_celsius",

collector/meminfo.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
"strconv"
1212
"strings"
1313

14-
"github.com/golang/glog"
1514
"github.com/prometheus/client_golang/prometheus"
15+
"github.com/prometheus/log"
1616
)
1717

1818
const (
@@ -21,7 +21,6 @@ const (
2121
)
2222

2323
type meminfoCollector struct {
24-
2524
metrics map[string]prometheus.Gauge
2625
}
2726

@@ -42,7 +41,7 @@ func (c *meminfoCollector) Update(ch chan<- prometheus.Metric) (err error) {
4241
if err != nil {
4342
return fmt.Errorf("Couldn't get meminfo: %s", err)
4443
}
45-
glog.V(1).Infof("Set node_mem: %#v", memInfo)
44+
log.Debugf("Set node_mem: %#v", memInfo)
4645
for k, v := range memInfo {
4746
if _, ok := c.metrics[k]; !ok {
4847
c.metrics[k] = prometheus.NewGauge(prometheus.GaugeOpts{

collector/netdev.go

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ var (
2424
)
2525

2626
type netDevCollector struct {
27-
2827
metrics map[string]*prometheus.GaugeVec
2928
}
3029

collector/netstat.go

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ const (
1919
)
2020

2121
type netStatCollector struct {
22-
2322
metrics map[string]prometheus.Gauge
2423
}
2524

collector/ntp.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"time"
99

1010
"github.com/beevik/ntp"
11-
"github.com/golang/glog"
1211
"github.com/prometheus/client_golang/prometheus"
12+
"github.com/prometheus/log"
1313
)
1414

1515
var (
@@ -46,7 +46,7 @@ func (c *ntpCollector) Update(ch chan<- prometheus.Metric) (err error) {
4646
return fmt.Errorf("Couldn't get ntp drift: %s", err)
4747
}
4848
drift := t.Sub(time.Now())
49-
glog.V(1).Infof("Set ntp_drift_seconds: %f", drift.Seconds())
49+
log.Debugf("Set ntp_drift_seconds: %f", drift.Seconds())
5050
c.drift.Set(drift.Seconds())
5151
c.drift.Collect(ch)
5252
return err

collector/runit.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
package collector
44

55
import (
6-
"github.com/golang/glog"
76
"github.com/prometheus/client_golang/prometheus"
7+
"github.com/prometheus/log"
88
"github.com/soundcloud/go-runit/runit"
99
)
1010

1111
type runitCollector struct {
12-
13-
1412
state, stateDesired, stateNormal *prometheus.GaugeVec
1513
}
1614

@@ -26,7 +24,6 @@ func NewRunitCollector() (Collector, error) {
2624
)
2725

2826
return &runitCollector{
29-
3027
state: prometheus.NewGaugeVec(
3128
prometheus.GaugeOpts{
3229
Namespace: Namespace,
@@ -69,11 +66,11 @@ func (c *runitCollector) Update(ch chan<- prometheus.Metric) error {
6966
for _, service := range services {
7067
status, err := service.Status()
7168
if err != nil {
72-
glog.V(1).Infof("Couldn't get status for %s: %s, skipping...", service.Name, err)
69+
log.Debugf("Couldn't get status for %s: %s, skipping...", service.Name, err)
7370
continue
7471
}
7572

76-
glog.V(1).Infof("%s is %d on pid %d for %d seconds", service.Name, status.State, status.Pid, status.Duration)
73+
log.Debugf("%s is %d on pid %d for %d seconds", service.Name, status.State, status.Pid, status.Duration)
7774
c.state.WithLabelValues(service.Name).Set(float64(status.State))
7875
c.stateDesired.WithLabelValues(service.Name).Set(float64(status.Want))
7976
if status.NormallyUp {

collector/stat.go

-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ const (
1717
)
1818

1919
type statCollector struct {
20-
2120
cpu *prometheus.CounterVec
2221
intr prometheus.Counter
2322
ctxt prometheus.Counter
@@ -35,7 +34,6 @@ func init() {
3534
// network device stats.
3635
func NewStatCollector() (Collector, error) {
3736
return &statCollector{
38-
3937
cpu: prometheus.NewCounterVec(
4038
prometheus.CounterOpts{
4139
Namespace: Namespace,

collector/tcpstat.go

-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ const (
3535
)
3636

3737
type tcpStatCollector struct {
38-
3938
metric *prometheus.GaugeVec
4039
}
4140

@@ -47,7 +46,6 @@ func init() {
4746
// a new Collector exposing network stats.
4847
func NewTCPStatCollector() (Collector, error) {
4948
return &tcpStatCollector{
50-
5149
metric: prometheus.NewGaugeVec(
5250
prometheus.GaugeOpts{
5351
Namespace: Namespace,

collector/textfile.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import (
1313

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

16-
"github.com/golang/glog"
1716
"github.com/golang/protobuf/proto"
17+
"github.com/prometheus/log"
1818

1919
"github.com/prometheus/client_golang/prometheus"
2020
"github.com/prometheus/client_golang/text"
@@ -37,7 +37,7 @@ func NewTextFileCollector() (Collector, error) {
3737
if *textFileDirectory == "" {
3838
// This collector is enabled by default, so do not fail if
3939
// the flag is not passed.
40-
glog.Infof("No directory specified, see --textfile.directory")
40+
log.Infof("No directory specified, see --textfile.directory")
4141
} else {
4242
prometheus.SetMetricFamilyInjectionHook(parseTextFiles)
4343
}
@@ -65,13 +65,13 @@ func parseTextFiles() []*dto.MetricFamily {
6565
path := filepath.Join(*textFileDirectory, f.Name())
6666
file, err := os.Open(path)
6767
if err != nil {
68-
glog.Errorf("Error opening %s: %v", path, err)
68+
log.Errorf("Error opening %s: %v", path, err)
6969
error = 1.0
7070
continue
7171
}
7272
parsedFamilies, err := parser.TextToMetricFamilies(file)
7373
if err != nil {
74-
glog.Errorf("Error parsing %s: %v", path, err)
74+
log.Errorf("Error parsing %s: %v", path, err)
7575
error = 1.0
7676
continue
7777
}

0 commit comments

Comments
 (0)