Skip to content

Commit

Permalink
added statsd support
Browse files Browse the repository at this point in the history
  • Loading branch information
martensson committed Jun 22, 2015
1 parent 974ce36 commit 948c8e6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Features:
* Reverse proxy and load balancer for your microservices running inside Mesos and Marathon
* Single binary with no other dependencies for easy deployment
* Supports TLS termination
* Statistics of req/s per application via statsd
* Event callback listener to automatically be up-to-date with Marathon
* Local file backups of Marathon states, so moxy will keep serving your apps even if Marathon goes down
* + more on the works...
Expand All @@ -23,7 +24,8 @@ Edit moxy.toml:
``` toml
port = "7000"
marathon = "http://localhost:8080"
tls = false
statsd = "example.com:8125" # optional if you want to graph req/s per app
tls = false # optional if you want moxy to terminate tls
cert = "cert.pem"
key = "key.pem"
```
Expand Down
11 changes: 11 additions & 0 deletions moxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/BurntSushi/toml"
"github.com/mailgun/oxy/forward"
"github.com/mailgun/oxy/roundrobin"
"github.com/peterbourgon/g2s"
"github.com/thoas/stats"
)

Expand All @@ -34,19 +35,26 @@ var apps Apps
type Config struct {
Port string
Marathon string
Statsd string
TLS bool
Cert string
Key string
}

var config Config
var statsd g2s.Statter

func moxy_proxy(w http.ResponseWriter, r *http.Request) {
// let us forward this request to a running container
app := strings.Split(r.Host, ".")[0]
apps.RLock()
defer apps.RUnlock()
if s, ok := apps.Apps[app]; ok {
go func(app string) {
if config.Statsd != "" {
statsd.Counter(1.0, "moxy."+app, 1)
}
}(app)
s.Lb.ServeHTTP(w, r)
return
}
Expand Down Expand Up @@ -87,6 +95,9 @@ func main() {
if err != nil {
log.Fatal("Problem parsing config: ", err)
}
if config.Statsd != "" {
statsd, _ = g2s.Dial("udp", config.Statsd)
}
moxystats := stats.New()
mux := http.NewServeMux()
mux.HandleFunc("/moxy_callback", moxy_callback)
Expand Down
1 change: 1 addition & 0 deletions moxy.toml.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
port = "7000"
marathon = "http://localhost:8080"
statsd = "example.com:8125" # optional if you want to graph req/s per app
tls = false # optional if you want moxy to terminate tls
cert = "cert.pem"
key = "key.pem"

0 comments on commit 948c8e6

Please sign in to comment.