diff --git a/Dockerfile b/Dockerfile index 7e89cfd1..c7dd968c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,5 +2,4 @@ FROM golang:onbuild MAINTAINER Prometheus Team ENTRYPOINT [ "go-wrapper", "run" ] -CMD [ "-logtostderr" ] EXPOSE 9100 diff --git a/README.md b/README.md index b19fe372..4627b678 100644 --- a/README.md +++ b/README.md @@ -10,12 +10,6 @@ collectors. make ./node_exporter -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 diff --git a/collector/diskstats.go b/collector/diskstats.go index 1f61db20..57c703bc 100644 --- a/collector/diskstats.go +++ b/collector/diskstats.go @@ -12,8 +12,8 @@ import ( "strconv" "strings" - "github.com/golang/glog" "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/log" ) const ( @@ -26,7 +26,6 @@ var ( ) type diskstatsCollector struct { - ignoredDevicesPattern *regexp.Regexp metrics []prometheus.Collector } @@ -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 } diff --git a/collector/filesystem.go b/collector/filesystem.go index 0640571a..d6b635b2 100644 --- a/collector/filesystem.go +++ b/collector/filesystem.go @@ -11,8 +11,8 @@ import ( "strings" "syscall" - "github.com/golang/glog" "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/log" ) const ( @@ -25,7 +25,6 @@ var ( ) type filesystemCollector struct { - ignoredMountPointsPattern *regexp.Regexp size, free, avail, files, filesFree *prometheus.GaugeVec @@ -41,7 +40,6 @@ func NewFilesystemCollector() (Collector, error) { var filesystemLabelNames = []string{"filesystem"} return &filesystemCollector{ - ignoredMountPointsPattern: regexp.MustCompile(*ignoredMountPoints), size: prometheus.NewGaugeVec( prometheus.GaugeOpts{ @@ -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) diff --git a/collector/gmond.go b/collector/gmond.go index 4694d085..67701268 100644 --- a/collector/gmond.go +++ b/collector/gmond.go @@ -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" ) @@ -25,7 +26,6 @@ const ( type gmondCollector struct { metrics map[string]*prometheus.GaugeVec - } func init() { @@ -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) } @@ -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, @@ -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) } diff --git a/collector/interrupts.go b/collector/interrupts.go index 6ec40737..aebe184b 100644 --- a/collector/interrupts.go +++ b/collector/interrupts.go @@ -18,7 +18,6 @@ const ( ) type interruptsCollector struct { - metric *prometheus.CounterVec } @@ -30,7 +29,6 @@ func init() { // interrupts stats func NewInterruptsCollector() (Collector, error) { return &interruptsCollector{ - metric: prometheus.NewCounterVec( prometheus.CounterOpts{ Namespace: Namespace, diff --git a/collector/lastlogin.go b/collector/lastlogin.go index 05aee4a1..1a0c39dd 100644 --- a/collector/lastlogin.go +++ b/collector/lastlogin.go @@ -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 } @@ -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, @@ -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 diff --git a/collector/loadavg.go b/collector/loadavg.go index 8f40e1dc..bdf72988 100644 --- a/collector/loadavg.go +++ b/collector/loadavg.go @@ -8,8 +8,8 @@ import ( "strconv" "strings" - "github.com/golang/glog" "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/log" ) const ( @@ -17,7 +17,6 @@ const ( ) type loadavgCollector struct { - metric prometheus.Gauge } @@ -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", @@ -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 diff --git a/collector/megacli.go b/collector/megacli.go index e83eb49b..f66da864 100644 --- a/collector/megacli.go +++ b/collector/megacli.go @@ -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", diff --git a/collector/meminfo.go b/collector/meminfo.go index 434e5bc6..5ed920b1 100644 --- a/collector/meminfo.go +++ b/collector/meminfo.go @@ -11,8 +11,8 @@ import ( "strconv" "strings" - "github.com/golang/glog" "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/log" ) const ( @@ -21,7 +21,6 @@ const ( ) type meminfoCollector struct { - metrics map[string]prometheus.Gauge } @@ -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{ diff --git a/collector/netdev.go b/collector/netdev.go index 1df32919..a630ff16 100644 --- a/collector/netdev.go +++ b/collector/netdev.go @@ -24,7 +24,6 @@ var ( ) type netDevCollector struct { - metrics map[string]*prometheus.GaugeVec } diff --git a/collector/netstat.go b/collector/netstat.go index 6e93b6a6..67b9fba1 100644 --- a/collector/netstat.go +++ b/collector/netstat.go @@ -19,7 +19,6 @@ const ( ) type netStatCollector struct { - metrics map[string]prometheus.Gauge } diff --git a/collector/ntp.go b/collector/ntp.go index 844ecd49..53b181fa 100644 --- a/collector/ntp.go +++ b/collector/ntp.go @@ -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 ( @@ -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 diff --git a/collector/runit.go b/collector/runit.go index abb23f1a..72ab685c 100644 --- a/collector/runit.go +++ b/collector/runit.go @@ -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 } @@ -26,7 +24,6 @@ func NewRunitCollector() (Collector, error) { ) return &runitCollector{ - state: prometheus.NewGaugeVec( prometheus.GaugeOpts{ Namespace: Namespace, @@ -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 { diff --git a/collector/stat.go b/collector/stat.go index 68b7e409..80ceb3d8 100644 --- a/collector/stat.go +++ b/collector/stat.go @@ -17,7 +17,6 @@ const ( ) type statCollector struct { - cpu *prometheus.CounterVec intr prometheus.Counter ctxt prometheus.Counter @@ -35,7 +34,6 @@ func init() { // network device stats. func NewStatCollector() (Collector, error) { return &statCollector{ - cpu: prometheus.NewCounterVec( prometheus.CounterOpts{ Namespace: Namespace, diff --git a/collector/tcpstat.go b/collector/tcpstat.go index 1584f8f9..2753b45c 100644 --- a/collector/tcpstat.go +++ b/collector/tcpstat.go @@ -35,7 +35,6 @@ const ( ) type tcpStatCollector struct { - metric *prometheus.GaugeVec } @@ -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, diff --git a/collector/textfile.go b/collector/textfile.go index 382274b7..0950ad94 100644 --- a/collector/textfile.go +++ b/collector/textfile.go @@ -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" @@ -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) } @@ -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 } diff --git a/collector/time.go b/collector/time.go index 6a0ba69d..9c848046 100644 --- a/collector/time.go +++ b/collector/time.go @@ -5,12 +5,11 @@ package collector import ( "time" - "github.com/golang/glog" "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/log" ) type timeCollector struct { - metric prometheus.Counter } @@ -22,7 +21,6 @@ func init() { // the current system time in seconds since epoch. func NewTimeCollector() (Collector, error) { return &timeCollector{ - metric: prometheus.NewCounter(prometheus.CounterOpts{ Namespace: Namespace, Name: "time", @@ -33,7 +31,7 @@ func NewTimeCollector() (Collector, error) { func (c *timeCollector) Update(ch chan<- prometheus.Metric) (err error) { now := time.Now() - glog.V(1).Infof("Set time: %f", now.Unix()) + log.Debugf("Set time: %f", now.Unix()) c.metric.Set(float64(now.Unix())) c.metric.Collect(ch) return err diff --git a/node_exporter.go b/node_exporter.go index 7c7911a1..dcd6bb45 100644 --- a/node_exporter.go +++ b/node_exporter.go @@ -13,8 +13,9 @@ import ( "syscall" "time" - "github.com/golang/glog" "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/log" + "github.com/prometheus/node_exporter/collector" ) @@ -93,10 +94,10 @@ func Execute(name string, c collector.Collector, ch chan<- prometheus.Metric) { var result string if err != nil { - glog.Infof("ERROR: %s failed after %fs: %s", name, duration.Seconds(), err) + log.Infof("ERROR: %s failed after %fs: %s", name, duration.Seconds(), err) result = "error" } else { - glog.Infof("OK: %s success after %fs.", name, duration.Seconds()) + log.Infof("OK: %s success after %fs.", name, duration.Seconds()) result = "success" } scrapeDurations.WithLabelValues(name, result).Observe(duration.Seconds()) @@ -135,12 +136,12 @@ func main() { } collectors, err := loadCollectors() if err != nil { - glog.Fatalf("Couldn't load collectors: %s", err) + log.Fatalf("Couldn't load collectors: %s", err) } - glog.Infof("Enabled collectors:") + log.Infof("Enabled collectors:") for n, _ := range collectors { - glog.Infof(" - %s", n) + log.Infof(" - %s", n) } nodeCollector := NodeCollector{collectors: collectors} @@ -152,7 +153,7 @@ func main() { handler := prometheus.Handler() if *authUser != "" || *authPass != "" { if *authUser == "" || *authPass == "" { - glog.Fatal("You need to specify -auth.user and -auth.pass to enable basic auth") + log.Fatal("You need to specify -auth.user and -auth.pass to enable basic auth") } handler = &basicAuthHandler{ handler: prometheus.Handler().ServeHTTP, @@ -172,9 +173,9 @@ func main() { `)) }) - glog.Infof("Starting node_exporter v%s at %s", Version, *listenAddress) + log.Infof("Starting node_exporter v%s at %s", Version, *listenAddress) err = http.ListenAndServe(*listenAddress, nil) if err != nil { - glog.Fatal(err) + log.Fatal(err) } }