Skip to content

Commit e65bc86

Browse files
committed
Switch logging from glog to github.com/prometheus/log.
1 parent 9f046cd commit e65bc86

13 files changed

+36
-44
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-2
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 (
@@ -154,7 +154,7 @@ func (c *diskstatsCollector) Update(ch chan<- prometheus.Metric) (err error) {
154154

155155
for dev, stats := range diskStats {
156156
if c.ignoredDevicesPattern.MatchString(dev) {
157-
glog.V(1).Infof("Ignoring device: %s", dev)
157+
log.Debugf("Ignoring device: %s", dev)
158158
continue
159159
}
160160

collector/filesystem.go

+2-3
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 (
@@ -40,7 +40,6 @@ func NewFilesystemCollector() (Collector, error) {
4040
var filesystemLabelNames = []string{"filesystem"}
4141

4242
return &filesystemCollector{
43-
4443
ignoredMountPointsPattern: regexp.MustCompile(*ignoredMountPoints),
4544
size: prometheus.NewGaugeVec(
4645
prometheus.GaugeOpts{
@@ -98,7 +97,7 @@ func (c *filesystemCollector) Update(ch chan<- prometheus.Metric) (err error) {
9897
}
9998
for _, mp := range mps {
10099
if c.ignoredMountPointsPattern.MatchString(mp) {
101-
glog.V(1).Infof("Ignoring mount point: %s", mp)
100+
log.Debugf("Ignoring mount point: %s", mp)
102101
continue
103102
}
104103
buf := new(syscall.Statfs_t)

collector/gmond.go

+5-4
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

@@ -44,7 +45,7 @@ func NewGmondCollector() (Collector, error) {
4445

4546
func (c *gmondCollector) Update(ch chan<- prometheus.Metric) (err error) {
4647
conn, err := net.Dial(gangliaProto, gangliaAddress)
47-
glog.V(1).Infof("gmondCollector Update")
48+
log.Debugf("gmondCollector Update")
4849
if err != nil {
4950
return fmt.Errorf("Can't connect to gmond: %s", err)
5051
}
@@ -90,7 +91,7 @@ func (c *gmondCollector) setMetric(name, cluster string, metric ganglia.Metric)
9091
break
9192
}
9293
}
93-
glog.V(1).Infof("Register %s: %s", name, desc)
94+
log.Debugf("Register %s: %s", name, desc)
9495
c.metrics[name] = prometheus.NewGaugeVec(
9596
prometheus.GaugeOpts{
9697
Namespace: gangliaNamespace,
@@ -100,7 +101,7 @@ func (c *gmondCollector) setMetric(name, cluster string, metric ganglia.Metric)
100101
[]string{"cluster"},
101102
)
102103
}
103-
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)
104105
c.metrics[name].WithLabelValues(cluster).Set(metric.Value)
105106
}
106107

collector/lastlogin.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ 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"
@@ -28,7 +28,6 @@ func init() {
2828
// load, seconds since last login and a list of tags as specified by config.
2929
func NewLastLoginCollector() (Collector, error) {
3030
return &lastLoginCollector{
31-
3231
metric: prometheus.NewGauge(prometheus.GaugeOpts{
3332
Namespace: Namespace,
3433
Subsystem: lastLoginSubsystem,
@@ -43,7 +42,7 @@ func (c *lastLoginCollector) Update(ch chan<- prometheus.Metric) (err error) {
4342
if err != nil {
4443
return fmt.Errorf("Couldn't get last seen: %s", err)
4544
}
46-
glog.V(1).Infof("Set node_last_login_time: %f", last)
45+
log.Debugf("Set node_last_login_time: %f", last)
4746
c.metric.Set(last)
4847
c.metric.Collect(ch)
4948
return err

collector/loadavg.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ 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 (
@@ -41,7 +41,7 @@ func (c *loadavgCollector) Update(ch chan<- prometheus.Metric) (err error) {
4141
if err != nil {
4242
return fmt.Errorf("Couldn't get load: %s", err)
4343
}
44-
glog.V(1).Infof("Set node_load: %f", load)
44+
log.Debugf("Set node_load: %f", load)
4545
c.metric.Set(load)
4646
c.metric.Collect(ch)
4747
return err

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/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-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
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

@@ -66,11 +66,11 @@ func (c *runitCollector) Update(ch chan<- prometheus.Metric) error {
6666
for _, service := range services {
6767
status, err := service.Status()
6868
if err != nil {
69-
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)
7070
continue
7171
}
7272

73-
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)
7474
c.state.WithLabelValues(service.Name).Set(float64(status.State))
7575
c.stateDesired.WithLabelValues(service.Name).Set(float64(status.Want))
7676
if status.NormallyUp {

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
}

collector/time.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ package collector
55
import (
66
"time"
77

8-
"github.com/golang/glog"
98
"github.com/prometheus/client_golang/prometheus"
9+
"github.com/prometheus/log"
1010
)
1111

1212
type timeCollector struct {
@@ -31,7 +31,7 @@ func NewTimeCollector() (Collector, error) {
3131

3232
func (c *timeCollector) Update(ch chan<- prometheus.Metric) (err error) {
3333
now := time.Now()
34-
glog.V(1).Infof("Set time: %f", now.Unix())
34+
log.Debugf("Set time: %f", now.Unix())
3535
c.metric.Set(float64(now.Unix()))
3636
c.metric.Collect(ch)
3737
return err

node_exporter.go

+10-9
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ import (
1313
"syscall"
1414
"time"
1515

16-
"github.com/golang/glog"
1716
"github.com/prometheus/client_golang/prometheus"
17+
"github.com/prometheus/log"
18+
1819
"github.com/prometheus/node_exporter/collector"
1920
)
2021

@@ -93,10 +94,10 @@ func Execute(name string, c collector.Collector, ch chan<- prometheus.Metric) {
9394
var result string
9495

9596
if err != nil {
96-
glog.Infof("ERROR: %s failed after %fs: %s", name, duration.Seconds(), err)
97+
log.Infof("ERROR: %s failed after %fs: %s", name, duration.Seconds(), err)
9798
result = "error"
9899
} else {
99-
glog.Infof("OK: %s success after %fs.", name, duration.Seconds())
100+
log.Infof("OK: %s success after %fs.", name, duration.Seconds())
100101
result = "success"
101102
}
102103
scrapeDurations.WithLabelValues(name, result).Observe(duration.Seconds())
@@ -135,12 +136,12 @@ func main() {
135136
}
136137
collectors, err := loadCollectors()
137138
if err != nil {
138-
glog.Fatalf("Couldn't load collectors: %s", err)
139+
log.Fatalf("Couldn't load collectors: %s", err)
139140
}
140141

141-
glog.Infof("Enabled collectors:")
142+
log.Infof("Enabled collectors:")
142143
for n, _ := range collectors {
143-
glog.Infof(" - %s", n)
144+
log.Infof(" - %s", n)
144145
}
145146

146147
nodeCollector := NodeCollector{collectors: collectors}
@@ -152,7 +153,7 @@ func main() {
152153
handler := prometheus.Handler()
153154
if *authUser != "" || *authPass != "" {
154155
if *authUser == "" || *authPass == "" {
155-
glog.Fatal("You need to specify -auth.user and -auth.pass to enable basic auth")
156+
log.Fatal("You need to specify -auth.user and -auth.pass to enable basic auth")
156157
}
157158
handler = &basicAuthHandler{
158159
handler: prometheus.Handler().ServeHTTP,
@@ -172,9 +173,9 @@ func main() {
172173
</html>`))
173174
})
174175

175-
glog.Infof("Starting node_exporter v%s at %s", Version, *listenAddress)
176+
log.Infof("Starting node_exporter v%s at %s", Version, *listenAddress)
176177
err = http.ListenAndServe(*listenAddress, nil)
177178
if err != nil {
178-
glog.Fatal(err)
179+
log.Fatal(err)
179180
}
180181
}

0 commit comments

Comments
 (0)