-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
46 lines (38 loc) · 1.04 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"fmt"
"net/http"
"flag"
"mime"
)
// Very small and simple implementation of StatsD compatible statistics collector with very simple WebUI
func main() {
httpAddr := flag.String("web", "localhost:8888", "Web interface address to use")
statsdAddr := flag.String("listen", "localhost:8125", "Listend for statsd compatible stats on address")
static := flag.String("static", "", "Use this directory for serving static pages instead of statically compiled ones")
flag.Parse()
stat := NewSimpleStats()
http.Handle("/metrics", stat.Handler())
http.Handle("/stats", stat)
if *static == "" {
handleStaticPages()
} else {
mime.AddExtensionType(".mjs", "text/javascript")
http.Handle("/", http.FileServer(http.Dir(*static)))
}
go func () {
http.ListenAndServe(*httpAddr, nil)
}()
ch := make(chan *Message, 1000)
go func() {
for msg := range(ch) {
// Debug print:
// fmt.Printf("Message: %#v\n", msg)
stat.Add(msg)
}
}()
err := StatsDaemon(*statsdAddr, ch)
if err != nil {
fmt.Printf("Error: %v\n", err)
}
}