aboutsummaryrefslogtreecommitdiff
path: root/node_exporter.go
diff options
context:
space:
mode:
authorTravis Truman <travis_truman@cable.comcast.com>2015-11-05 09:20:01 -0500
committerTravis Truman <travis_truman@cable.comcast.com>2015-11-05 09:20:01 -0500
commit78cc7412770d1288fa5225832a570dfa1e1b56b0 (patch)
tree3c92f210b174122a3abbfbd3c419c501850f8b88 /node_exporter.go
parent0a0babf3bea4c7dad860f7dc2433288b65eba7ff (diff)
downloadprometheus_node_collector-78cc7412770d1288fa5225832a570dfa1e1b56b0.tar.bz2
prometheus_node_collector-78cc7412770d1288fa5225832a570dfa1e1b56b0.tar.xz
prometheus_node_collector-78cc7412770d1288fa5225832a570dfa1e1b56b0.zip
Closes #100 by removing support for HTTP basic auth
Diffstat (limited to 'node_exporter.go')
-rw-r--r--node_exporter.go29
1 files changed, 0 insertions, 29 deletions
diff --git a/node_exporter.go b/node_exporter.go
index ef500f7..434dd3d 100644
--- a/node_exporter.go
+++ b/node_exporter.go
@@ -43,8 +43,6 @@ var (
43 metricsPath = flag.String("web.telemetry-path", "/metrics", "Path under which to expose metrics.") 43 metricsPath = flag.String("web.telemetry-path", "/metrics", "Path under which to expose metrics.")
44 enabledCollectors = flag.String("collectors.enabled", "diskstats,filefd,filesystem,loadavg,mdadm,meminfo,netdev,netstat,sockstat,stat,textfile,time,uname", "Comma-separated list of collectors to use.") 44 enabledCollectors = flag.String("collectors.enabled", "diskstats,filefd,filesystem,loadavg,mdadm,meminfo,netdev,netstat,sockstat,stat,textfile,time,uname", "Comma-separated list of collectors to use.")
45 printCollectors = flag.Bool("collectors.print", false, "If true, print available collectors and exit.") 45 printCollectors = flag.Bool("collectors.print", false, "If true, print available collectors and exit.")
46 authUser = flag.String("auth.user", "", "Username for basic auth.")
47 authPass = flag.String("auth.pass", "", "Password for basic auth.")
48 46
49 collectorLabelNames = []string{"collector", "result"} 47 collectorLabelNames = []string{"collector", "result"}
50 48
@@ -83,23 +81,6 @@ func (n NodeCollector) Collect(ch chan<- prometheus.Metric) {
83 scrapeDurations.Collect(ch) 81 scrapeDurations.Collect(ch)
84} 82}
85 83
86type basicAuthHandler struct {
87 handler http.HandlerFunc
88 user string
89 password string
90}
91
92func (h *basicAuthHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
93 user, password, ok := r.BasicAuth()
94 if !ok || password != h.password || user != h.user {
95 w.Header().Set("WWW-Authenticate", "Basic realm=\"metrics\"")
96 http.Error(w, "Invalid username or password", http.StatusUnauthorized)
97 return
98 }
99 h.handler(w, r)
100 return
101}
102
103func execute(name string, c collector.Collector, ch chan<- prometheus.Metric) { 84func execute(name string, c collector.Collector, ch chan<- prometheus.Metric) {
104 begin := time.Now() 85 begin := time.Now()
105 err := c.Update(ch) 86 err := c.Update(ch)
@@ -164,16 +145,6 @@ func main() {
164 signal.Notify(sigUsr1, syscall.SIGUSR1) 145 signal.Notify(sigUsr1, syscall.SIGUSR1)
165 146
166 handler := prometheus.Handler() 147 handler := prometheus.Handler()
167 if *authUser != "" || *authPass != "" {
168 if *authUser == "" || *authPass == "" {
169 log.Fatal("You need to specify -auth.user and -auth.pass to enable basic auth")
170 }
171 handler = &basicAuthHandler{
172 handler: prometheus.Handler().ServeHTTP,
173 user: *authUser,
174 password: *authPass,
175 }
176 }
177 148
178 http.Handle(*metricsPath, handler) 149 http.Handle(*metricsPath, handler)
179 http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { 150 http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {