mirror of
https://github.com/prometheus/node_exporter.git
synced 2025-03-05 21:00:12 -08:00
Switch logging from glog to github.com/prometheus/log.
This commit is contained in:
parent
9f046cd88e
commit
e65bc868fc
|
@ -2,5 +2,4 @@ FROM golang:onbuild
|
||||||
MAINTAINER Prometheus Team <prometheus-developers@googlegroups.com>
|
MAINTAINER Prometheus Team <prometheus-developers@googlegroups.com>
|
||||||
|
|
||||||
ENTRYPOINT [ "go-wrapper", "run" ]
|
ENTRYPOINT [ "go-wrapper", "run" ]
|
||||||
CMD [ "-logtostderr" ]
|
|
||||||
EXPOSE 9100
|
EXPOSE 9100
|
||||||
|
|
|
@ -10,12 +10,6 @@ collectors.
|
||||||
make
|
make
|
||||||
./node_exporter <flags>
|
./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
|
## Running tests
|
||||||
|
|
||||||
make test
|
make test
|
||||||
|
|
|
@ -12,8 +12,8 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/prometheus/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -154,7 +154,7 @@ func (c *diskstatsCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
||||||
|
|
||||||
for dev, stats := range diskStats {
|
for dev, stats := range diskStats {
|
||||||
if c.ignoredDevicesPattern.MatchString(dev) {
|
if c.ignoredDevicesPattern.MatchString(dev) {
|
||||||
glog.V(1).Infof("Ignoring device: %s", dev)
|
log.Debugf("Ignoring device: %s", dev)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,8 +11,8 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/prometheus/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -40,7 +40,6 @@ func NewFilesystemCollector() (Collector, error) {
|
||||||
var filesystemLabelNames = []string{"filesystem"}
|
var filesystemLabelNames = []string{"filesystem"}
|
||||||
|
|
||||||
return &filesystemCollector{
|
return &filesystemCollector{
|
||||||
|
|
||||||
ignoredMountPointsPattern: regexp.MustCompile(*ignoredMountPoints),
|
ignoredMountPointsPattern: regexp.MustCompile(*ignoredMountPoints),
|
||||||
size: prometheus.NewGaugeVec(
|
size: prometheus.NewGaugeVec(
|
||||||
prometheus.GaugeOpts{
|
prometheus.GaugeOpts{
|
||||||
|
@ -98,7 +97,7 @@ func (c *filesystemCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
||||||
}
|
}
|
||||||
for _, mp := range mps {
|
for _, mp := range mps {
|
||||||
if c.ignoredMountPointsPattern.MatchString(mp) {
|
if c.ignoredMountPointsPattern.MatchString(mp) {
|
||||||
glog.V(1).Infof("Ignoring mount point: %s", mp)
|
log.Debugf("Ignoring mount point: %s", mp)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
buf := new(syscall.Statfs_t)
|
buf := new(syscall.Statfs_t)
|
||||||
|
|
|
@ -11,8 +11,9 @@ import (
|
||||||
"regexp"
|
"regexp"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/prometheus/log"
|
||||||
|
|
||||||
"github.com/prometheus/node_exporter/collector/ganglia"
|
"github.com/prometheus/node_exporter/collector/ganglia"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -44,7 +45,7 @@ func NewGmondCollector() (Collector, error) {
|
||||||
|
|
||||||
func (c *gmondCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
func (c *gmondCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
||||||
conn, err := net.Dial(gangliaProto, gangliaAddress)
|
conn, err := net.Dial(gangliaProto, gangliaAddress)
|
||||||
glog.V(1).Infof("gmondCollector Update")
|
log.Debugf("gmondCollector Update")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Can't connect to gmond: %s", err)
|
return fmt.Errorf("Can't connect to gmond: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -90,7 +91,7 @@ func (c *gmondCollector) setMetric(name, cluster string, metric ganglia.Metric)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
glog.V(1).Infof("Register %s: %s", name, desc)
|
log.Debugf("Register %s: %s", name, desc)
|
||||||
c.metrics[name] = prometheus.NewGaugeVec(
|
c.metrics[name] = prometheus.NewGaugeVec(
|
||||||
prometheus.GaugeOpts{
|
prometheus.GaugeOpts{
|
||||||
Namespace: gangliaNamespace,
|
Namespace: gangliaNamespace,
|
||||||
|
@ -100,7 +101,7 @@ func (c *gmondCollector) setMetric(name, cluster string, metric ganglia.Metric)
|
||||||
[]string{"cluster"},
|
[]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)
|
c.metrics[name].WithLabelValues(cluster).Set(metric.Value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,8 +10,8 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/prometheus/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
const lastLoginSubsystem = "last_login"
|
const lastLoginSubsystem = "last_login"
|
||||||
|
@ -28,7 +28,6 @@ func init() {
|
||||||
// load, seconds since last login and a list of tags as specified by config.
|
// load, seconds since last login and a list of tags as specified by config.
|
||||||
func NewLastLoginCollector() (Collector, error) {
|
func NewLastLoginCollector() (Collector, error) {
|
||||||
return &lastLoginCollector{
|
return &lastLoginCollector{
|
||||||
|
|
||||||
metric: prometheus.NewGauge(prometheus.GaugeOpts{
|
metric: prometheus.NewGauge(prometheus.GaugeOpts{
|
||||||
Namespace: Namespace,
|
Namespace: Namespace,
|
||||||
Subsystem: lastLoginSubsystem,
|
Subsystem: lastLoginSubsystem,
|
||||||
|
@ -43,7 +42,7 @@ func (c *lastLoginCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Couldn't get last seen: %s", err)
|
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.Set(last)
|
||||||
c.metric.Collect(ch)
|
c.metric.Collect(ch)
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -8,8 +8,8 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/prometheus/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -41,7 +41,7 @@ func (c *loadavgCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Couldn't get load: %s", err)
|
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.Set(load)
|
||||||
c.metric.Collect(ch)
|
c.metric.Collect(ch)
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -11,8 +11,8 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/prometheus/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -21,7 +21,6 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
type meminfoCollector struct {
|
type meminfoCollector struct {
|
||||||
|
|
||||||
metrics map[string]prometheus.Gauge
|
metrics map[string]prometheus.Gauge
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +41,7 @@ func (c *meminfoCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Couldn't get meminfo: %s", err)
|
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 {
|
for k, v := range memInfo {
|
||||||
if _, ok := c.metrics[k]; !ok {
|
if _, ok := c.metrics[k]; !ok {
|
||||||
c.metrics[k] = prometheus.NewGauge(prometheus.GaugeOpts{
|
c.metrics[k] = prometheus.NewGauge(prometheus.GaugeOpts{
|
||||||
|
|
|
@ -8,8 +8,8 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/beevik/ntp"
|
"github.com/beevik/ntp"
|
||||||
"github.com/golang/glog"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/prometheus/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
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)
|
return fmt.Errorf("Couldn't get ntp drift: %s", err)
|
||||||
}
|
}
|
||||||
drift := t.Sub(time.Now())
|
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.Set(drift.Seconds())
|
||||||
c.drift.Collect(ch)
|
c.drift.Collect(ch)
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
package collector
|
package collector
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/golang/glog"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/prometheus/log"
|
||||||
"github.com/soundcloud/go-runit/runit"
|
"github.com/soundcloud/go-runit/runit"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -66,11 +66,11 @@ func (c *runitCollector) Update(ch chan<- prometheus.Metric) error {
|
||||||
for _, service := range services {
|
for _, service := range services {
|
||||||
status, err := service.Status()
|
status, err := service.Status()
|
||||||
if err != nil {
|
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
|
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.state.WithLabelValues(service.Name).Set(float64(status.State))
|
||||||
c.stateDesired.WithLabelValues(service.Name).Set(float64(status.Want))
|
c.stateDesired.WithLabelValues(service.Name).Set(float64(status.Want))
|
||||||
if status.NormallyUp {
|
if status.NormallyUp {
|
||||||
|
|
|
@ -13,8 +13,8 @@ import (
|
||||||
|
|
||||||
dto "github.com/prometheus/client_model/go"
|
dto "github.com/prometheus/client_model/go"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
|
"github.com/prometheus/log"
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/client_golang/text"
|
"github.com/prometheus/client_golang/text"
|
||||||
|
@ -37,7 +37,7 @@ func NewTextFileCollector() (Collector, error) {
|
||||||
if *textFileDirectory == "" {
|
if *textFileDirectory == "" {
|
||||||
// This collector is enabled by default, so do not fail if
|
// This collector is enabled by default, so do not fail if
|
||||||
// the flag is not passed.
|
// the flag is not passed.
|
||||||
glog.Infof("No directory specified, see --textfile.directory")
|
log.Infof("No directory specified, see --textfile.directory")
|
||||||
} else {
|
} else {
|
||||||
prometheus.SetMetricFamilyInjectionHook(parseTextFiles)
|
prometheus.SetMetricFamilyInjectionHook(parseTextFiles)
|
||||||
}
|
}
|
||||||
|
@ -65,13 +65,13 @@ func parseTextFiles() []*dto.MetricFamily {
|
||||||
path := filepath.Join(*textFileDirectory, f.Name())
|
path := filepath.Join(*textFileDirectory, f.Name())
|
||||||
file, err := os.Open(path)
|
file, err := os.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Error opening %s: %v", path, err)
|
log.Errorf("Error opening %s: %v", path, err)
|
||||||
error = 1.0
|
error = 1.0
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
parsedFamilies, err := parser.TextToMetricFamilies(file)
|
parsedFamilies, err := parser.TextToMetricFamilies(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Error parsing %s: %v", path, err)
|
log.Errorf("Error parsing %s: %v", path, err)
|
||||||
error = 1.0
|
error = 1.0
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,8 @@ package collector
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/prometheus/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type timeCollector struct {
|
type timeCollector struct {
|
||||||
|
@ -31,7 +31,7 @@ func NewTimeCollector() (Collector, error) {
|
||||||
|
|
||||||
func (c *timeCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
func (c *timeCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
||||||
now := time.Now()
|
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.Set(float64(now.Unix()))
|
||||||
c.metric.Collect(ch)
|
c.metric.Collect(ch)
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -13,8 +13,9 @@ import (
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/prometheus/log"
|
||||||
|
|
||||||
"github.com/prometheus/node_exporter/collector"
|
"github.com/prometheus/node_exporter/collector"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -93,10 +94,10 @@ func Execute(name string, c collector.Collector, ch chan<- prometheus.Metric) {
|
||||||
var result string
|
var result string
|
||||||
|
|
||||||
if err != nil {
|
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"
|
result = "error"
|
||||||
} else {
|
} else {
|
||||||
glog.Infof("OK: %s success after %fs.", name, duration.Seconds())
|
log.Infof("OK: %s success after %fs.", name, duration.Seconds())
|
||||||
result = "success"
|
result = "success"
|
||||||
}
|
}
|
||||||
scrapeDurations.WithLabelValues(name, result).Observe(duration.Seconds())
|
scrapeDurations.WithLabelValues(name, result).Observe(duration.Seconds())
|
||||||
|
@ -135,12 +136,12 @@ func main() {
|
||||||
}
|
}
|
||||||
collectors, err := loadCollectors()
|
collectors, err := loadCollectors()
|
||||||
if err != nil {
|
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 {
|
for n, _ := range collectors {
|
||||||
glog.Infof(" - %s", n)
|
log.Infof(" - %s", n)
|
||||||
}
|
}
|
||||||
|
|
||||||
nodeCollector := NodeCollector{collectors: collectors}
|
nodeCollector := NodeCollector{collectors: collectors}
|
||||||
|
@ -152,7 +153,7 @@ func main() {
|
||||||
handler := prometheus.Handler()
|
handler := prometheus.Handler()
|
||||||
if *authUser != "" || *authPass != "" {
|
if *authUser != "" || *authPass != "" {
|
||||||
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 = &basicAuthHandler{
|
||||||
handler: prometheus.Handler().ServeHTTP,
|
handler: prometheus.Handler().ServeHTTP,
|
||||||
|
@ -172,9 +173,9 @@ func main() {
|
||||||
</html>`))
|
</html>`))
|
||||||
})
|
})
|
||||||
|
|
||||||
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)
|
err = http.ListenAndServe(*listenAddress, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue