ProductPromotion
Logo

Elixir

made by https://0x3d.site

GitHub - jeffweiss/plug_statsd: Send connection response time and count to statsd
Send connection response time and count to statsd. Contribute to jeffweiss/plug_statsd development by creating an account on GitHub.
Visit Site

GitHub - jeffweiss/plug_statsd: Send connection response time and count to statsd

GitHub - jeffweiss/plug_statsd: Send connection response time and count to statsd

PlugStatsd

Description

A plug for automatically sending timing and count metrics to statsd.

This plug can currently can use any of these statsd backends:

If you have additional statsd clients you'd like added, please open an issue and let me know.

Usage

Add the plug and your chosen statsd backend as a dependencies for your application.

defp deps do
  [
    {:plug_statsd, "~> 0.3"},
    {:ex_statsd, "~> 0.5"},
  ]
end

You should also update your applications list to include the statsd plug and the backend:

def application do
  [applications: [:plug_statsd, :ex_statsd]]
end

Add the plug to your endpoints, here's an example from a Phoenix chat application (lib/chat/endpoint.ex)

defmodule Chat.Endpoint do
...

  plug Plug.Logger

  #send connection request timing and counts to statsd
  plug Plug.Statsd

...
end

Configure your statsd backend (ex_statsd or statderl) using Mix.Config as usual (probably in your config/):

use Mix.Config

config :ex_statsd,
  host: "your.statsd.host.com", # This is optional and will default to 127.0.0.1
  port: 1234,                   # This is optional and will default to 8125
  namespace: "your-app"         # This is optional and will default to nil
config :plug_statsd,
  metrics: [
    # custom_text.4xx.more_custom_text
    {:timer, ["custom_text", :generalized_http_status, "more_custom_text"]},
    # request.GET.api-v1-users-jeff=weiss
    {:counter, ["request", &Plug.Statsd.http_method/2, :uri], sample_rate: 0.1},
    # or this is equivalent as request.GET.api-v1-users-jeff=weiss
    {:counter, ["request", {Plug.Statsd, :http_method}, :uri], sample_rate: 0.1},
  ],
  slash_replacement: "-", # defaults to "."
  dot_replacement: "="    # defaults to "_"

You 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.

Seeing it in action

If you don't immediately have a statsd server available, you can run socat in a terminal.

$ socat UDP-RECV:8125 STDOUT

Depending on your sample rates, you should see a series of output that looks something like

custom_text.2xx.more_custom_text:27|ms
request.GET.[root]:1|c
custom_text.2xx.more_custom_text:18|ms
request.GET.[root]:1|c
custom_text.2xx.more_custom_text:32|ms
request.GET.[root]:1|c
custom_text.4xx.more_custom_text:1|ms
request.GET.api-v1-users-jeff=weiss:1|c
custom_text.4xx.more_custom_text:0|ms
request.GET.api-v1-users-jeff=weiss:1|c

Articles
to learn more about the elixir concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about Elixir.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory