diff --git a/data/statsd/.gitignore b/data/statsd/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/data/statsd/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/docker-compose.base.yml b/docker-compose.base.yml index d8df429..1ffb478 100644 --- a/docker-compose.base.yml +++ b/docker-compose.base.yml @@ -11,3 +11,8 @@ services: RABBITMQ_DEFAULT_USER: "ely-skinsystem-app" RABBITMQ_DEFAULT_PASS: "ely-skinsystem-app-password" RABBITMQ_DEFAULT_VHOST: "/ely" + + statsd: + image: hopsoft/graphite-statsd + volumes: + - ./data/statsd:/opt/graphite/storage diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index db6d8c0..c5e919d 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -11,6 +11,7 @@ services: links: - redis - rabbitmq + - statsd redis: extends: @@ -21,3 +22,10 @@ services: extends: file: docker-compose.base.yml service: rabbitmq + + statsd: + extends: + file: docker-compose.base.yml + service: statsd + ports: + - "8123:80" diff --git a/lib/routes/Textures.go b/lib/routes/Textures.go index b1cd1ae..e0c10fc 100644 --- a/lib/routes/Textures.go +++ b/lib/routes/Textures.go @@ -13,6 +13,7 @@ import ( ) func Textures(w http.ResponseWriter, r *http.Request) { + services.Stats.Incr("textures-requests", 1) username := tools.ParseUsername(mux.Vars(r)["username"]) log.Println("request textures for username " + username) diff --git a/lib/services/services.go b/lib/services/services.go index e4ce93d..c1906d6 100644 --- a/lib/services/services.go +++ b/lib/services/services.go @@ -4,6 +4,7 @@ import ( "github.com/mediocregopher/radix.v2/pool" "github.com/streadway/amqp" "github.com/gorilla/mux" + "github.com/quipo/statsd" ) var Router *mux.Router @@ -13,3 +14,5 @@ var RedisPool *pool.Pool var RabbitMQChannel *amqp.Channel var RootFolder string + +var Stats *statsd.StatsdBuffer diff --git a/minecraft-skinsystem.go b/minecraft-skinsystem.go index 9f90837..a125015 100644 --- a/minecraft-skinsystem.go +++ b/minecraft-skinsystem.go @@ -11,6 +11,8 @@ import ( "github.com/gorilla/mux" "github.com/streadway/amqp" "github.com/mediocregopher/radix.v2/pool" + "github.com/quipo/statsd" + //"github.com/mediocregopher/radix.v2/redis" "elyby/minecraft-skinsystem/lib/routes" "elyby/minecraft-skinsystem/lib/services" @@ -56,6 +58,17 @@ func main() { } log.Println("Connected to rabbitmq channel") + // init + statsClient := statsd.NewStatsdClient(statsString, "skinsystem.") + statsErr := statsClient.CreateSocket() + if statsErr != nil { + log.Fatal(statsErr) + } + + interval := 2 * time.Second // aggregate stats and flush every 2 seconds + stats := statsd.NewStatsdBuffer(interval, statsClient) + defer stats.Close() + router := mux.NewRouter().StrictSlash(true) router.HandleFunc("/skins/{username}", routes.Skin).Methods("GET").Name("skins") router.HandleFunc("/cloaks/{username}", routes.Cape).Methods("GET").Name("cloaks") @@ -75,6 +88,7 @@ func main() { services.Router = router services.RedisPool = redisPool services.RabbitMQChannel = rabbitChannel + services.Stats = stats _, file, _, _ := runtime.Caller(0) services.RootFolder = filepath.Dir(file)