{"id":13508146,"url":"https://github.com/jeffweiss/plug_statsd","last_synced_at":"2025-03-16T10:32:00.654Z","repository":{"id":30843241,"uuid":"34400707","full_name":"jeffweiss/plug_statsd","owner":"jeffweiss","description":"Send connection response time and count to statsd","archived":false,"fork":false,"pushed_at":"2019-02-19T18:41:04.000Z","size":49,"stargazers_count":49,"open_issues_count":2,"forks_count":15,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-27T07:47:12.114Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jeffweiss.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-22T16:06:28.000Z","updated_at":"2022-12-07T21:40:40.000Z","dependencies_parsed_at":"2022-09-26T18:21:53.475Z","dependency_job_id":null,"html_url":"https://github.com/jeffweiss/plug_statsd","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffweiss%2Fplug_statsd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffweiss%2Fplug_statsd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffweiss%2Fplug_statsd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffweiss%2Fplug_statsd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jeffweiss","download_url":"https://codeload.github.com/jeffweiss/plug_statsd/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243814898,"owners_count":20352037,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T02:00:48.871Z","updated_at":"2025-03-16T10:32:00.352Z","avatar_url":"https://github.com/jeffweiss.png","language":"Elixir","funding_links":[],"categories":["Framework Components"],"sub_categories":[],"readme":"PlugStatsd\n==========\n\n## Description\nA plug for automatically sending\ntiming and count metrics to [statsd](https://github.com/etsy/statsd).\n\nThis plug can currently can use any of these statsd backends:\n * [ex_statsd](https://github.com/CargoSense/ex_statsd)\n * [statsderl](https://github.com/lpgauth/statsderl)\n * [statix](https://github.com/lexmag/statix)\n\nIf you have additional statsd clients you'd like added, please open an [issue](https://github.com/jeffweiss/plug_statsd/issues/new)\nand let me know.\n\n## Usage\n\nAdd the plug and your chosen statsd backend as a dependencies for your application.\n\n```elixir\ndefp deps do\n  [\n    {:plug_statsd, \"~\u003e 0.3\"},\n    {:ex_statsd, \"~\u003e 0.5\"},\n  ]\nend\n```\n\nYou should also update your applications list to include the statsd plug and the backend:\n\n```elixir\ndef application do\n  [applications: [:plug_statsd, :ex_statsd]]\nend\n```\n\nAdd the plug to your endpoints, here's an example from a Phoenix chat application (`lib/chat/endpoint.ex`)\n\n```elixir\ndefmodule Chat.Endpoint do\n...\n\n  plug Plug.Logger\n\n  #send connection request timing and counts to statsd\n  plug Plug.Statsd\n\n...\nend\n```\n\nConfigure your statsd backend ([ex_statsd](https://github.com/CargoSense/ex_statsd) or [statderl](https://github.com/lpgauth/statsderl)) using `Mix.Config` as usual (probably in your\n`config/`):\n\n```elixir\nuse Mix.Config\n\nconfig :ex_statsd,\n  host: \"your.statsd.host.com\", # This is optional and will default to 127.0.0.1\n  port: 1234,                   # This is optional and will default to 8125\n  namespace: \"your-app\"         # This is optional and will default to nil\nconfig :plug_statsd,\n  metrics: [\n    # custom_text.4xx.more_custom_text\n    {:timer, [\"custom_text\", :generalized_http_status, \"more_custom_text\"]},\n    # request.GET.api-v1-users-jeff=weiss\n    {:counter, [\"request\", \u0026Plug.Statsd.http_method/2, :uri], sample_rate: 0.1},\n    # or this is equivalent as request.GET.api-v1-users-jeff=weiss\n    {:counter, [\"request\", {Plug.Statsd, :http_method}, :uri], sample_rate: 0.1},\n  ],\n  slash_replacement: \"-\", # defaults to \".\"\n  dot_replacement: \"=\"    # defaults to \"_\"\n```\n\nYou can also add custom dynamic segments to your metric name by creating a 2-arity function that takes a `Plug.Conn` and a `Keyword` list.\n\n## Seeing it in action\n\nIf you don't immediately have a statsd server available, you can run socat in a terminal.\n\n```shell\n$ socat UDP-RECV:8125 STDOUT\n```\n\nDepending on your sample rates, you should see a series of output that looks something like\n\n```\ncustom_text.2xx.more_custom_text:27|ms\nrequest.GET.[root]:1|c\ncustom_text.2xx.more_custom_text:18|ms\nrequest.GET.[root]:1|c\ncustom_text.2xx.more_custom_text:32|ms\nrequest.GET.[root]:1|c\ncustom_text.4xx.more_custom_text:1|ms\nrequest.GET.api-v1-users-jeff=weiss:1|c\ncustom_text.4xx.more_custom_text:0|ms\nrequest.GET.api-v1-users-jeff=weiss:1|c\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeffweiss%2Fplug_statsd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjeffweiss%2Fplug_statsd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeffweiss%2Fplug_statsd/lists"}