Giter Club home page Giter Club logo

statsderl's Introduction

statsderl

High Performance Erlang StatsD Client

Build Status

Requirements

  • Erlang 16.0 +

Features

  • Performance optimized
  • Parse transform

API

Function Index

Environment variables:

Name Type Default Description
base_key base_key() undefined key prefix
hostname inet:ip_address() | inet:hostname() | binary() {127,0,0,1} server hostname
port inet:port_number() 8125 server port
pool_size pos_integer() 4 pool size

base_key options:

Name Source Description Example
hostname inet:gethostname/0 use the hostname "h033"
name erl -name use the long node name "nonode@nohost"
sname erl -sname use the short node name "nonode"

Parse Transform

statsderl_transform is used to pre-compute (at compile time) the scaled sample rate and StatsD packet.

-compile({parse_transform, statsderl_transform}).

Examples

1> statsderl_app:start().
ok.

2> statsderl:counter(["test", $., "counter"], 1, 0.23).
ok.

3> statsderl:decrement("test.decrement", 1, 0.5).
ok.

4> statsderl:gauge([<<"test">>, $., "gauge"], 333, 1.0).
ok.

5> statsderl:gauge_decrement([<<"test.gauge_decrement">>], 15, 0.001).
ok.

6> statsderl:gauge_increment(<<"test.gauge_increment">>, 32, 1).
ok.

7> statsderl:increment(<<"test.increment">>, 1, 1).
ok.

8> statsderl:timing("test.timing", 5, 0.5).
ok.

9> statsderl:timing_fun(<<"test.timing_fun">>, fun() -> timer:sleep(100) end, 0.5).
ok.

10> Timestamp = os:timestamp().
{1448,591778,258983}

11> statsderl:timing_now("test.timing_now", Timestamp, 0.15).
ok.

12> statsderl_app:stop().
ok.

Tests

make test

License

The MIT License (MIT)

Copyright (c) 2011-2020 Louis-Philippe Gauthier

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

statsderl's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

statsderl's Issues

Statsderl application crashing when being called with high frequency

I am experiencing errors on production system under high load (which means statsderl is called very frequently). Those errors are crashing statsderl application, which in turn causes to whole erlang interpreter termination.

I get in logs:

16:43:50.808 [error] CRASH REPORT Process statsderl_1 with 0 neighbours crashed with reason: no function clause matching statsderl_server:handle_msg({inet_reply,#Port<0.170403>,{error,eperm}}, {state,<<31,189,149,202,194,181,112,114,111,100,117,99,116,105,111,110,46,100,100,98,45,109,101,...>>,...}) line 46
16:43:50.808 [error] Supervisor statsderl_sup had child undefined started with statsderl_server:start_link(statsderl_1) at <0.4125.5> exit with reason function_clause in context child_terminated
16:43:50.991 [error] CRASH REPORT Process statsderl_1 with 0 neighbours crashed with reason: no function clause matching statsderl_server:handle_msg({inet_reply,#Port<0.177218>,{error,eperm}}, {state,<<31,189,149,202,194,181,112,114,111,100,117,99,116,105,111,110,46,100,100,98,45,109,101,...>>,...}) line 46
16:43:50.992 [error] Supervisor statsderl_sup had child undefined started with statsderl_server:start_link(statsderl_1) at <0.10894.5> exit with reason function_clause in context child_terminated
16:43:50.992 [error] Supervisor statsderl_sup had child undefined started with statsderl_server:start_link(statsderl_1) at <0.10894.5> exit with reason reached_max_restart_intensity in context shutdown
16:43:50.992 [info] Application statsderl exited with reason: shutdown
16:43:50.992 [error] gen_server <0.193.0> terminated with reason: unexpected_delivery_and_no_default_consumer
16:43:50.993 [error] gen_server <0.207.0> terminated with reason: unexpected_delivery_and_no_default_consumer
16:43:50.993 [error] CRASH REPORT Process <0.207.0> with 0 neighbours exited with reason: unexpected_delivery_and_no_default_consumer in gen_server2:terminate/3 line 1145
16:43:50.993 [error] CRASH REPORT Process <0.193.0> with 0 neighbours exited with reason: unexpected_delivery_and_no_default_consumer in gen_server2:terminate/3 line 1145
{"Kernel pid terminated",application_controller,"{application_terminated,statsderl,shutdown}"}

It happens only when system is under high load. Under smaller load everything works just fine. Als changing rate parameter in statsderl calls does not seem to make any difference.

I am running most resent statsderl v0.4.3.

eafnosupport on OTP 20

Erlang/OTP 20 was released today, however it seems like statsderl breaks with this new release.

Erlang/OTP 20 [erts-9.0] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:0] [hipe] [kernel-poll:false]

Eshell V9.0  (abort with ^G)
1> statsderl_app:start().
{ok,[granderl,statsderl]}
2> statsderl:counter("a", 1, 1).
ok
3>
=ERROR REPORT==== 21-Jun-2017::16:24:52 ===
[statsderl] inet_reply error: eafnosupport

Support multiple hosts

TODO:

  • Add new environment var called hosts
  • Modify server code to accept hostname/port arguments

Suggestion: Allow start params

For cases where no Environments variables are set, or usage of other config tools like confetti. Would be nice to have possibility to start the application passing parameters, instead of having them being read hardcoded in ENV vars.

If this turns to be a case, I'd be glad to add the possibility without breaking backward compatibility

Tag 0.3.6

Hey! Would you be okay to create a tag for version 0.3.6?

Allow mixing parts in base_key

from #12

I find it useful to be able to mix tokens within base_key. With my proposed change one can have composite base key, for example:

{base_key, ["development", hostname, "my-app"]}

How to set statsd server address

Hi

How to set the statsd server address.
How do i modify the defaults

-define(DEFAULT_BASEKEY, undefined).
-define(DEFAULT_HOSTNAME, {127, 0, 0, 1}).

I see that it could be set using

{env, [{Key, Val}]} in statsderl.app.

But I wish to add the statsderl as a dependency to rebar or erlang.mk. Not to modify the existing dependency.

Please advise. Did I understand any thing wrong

How to connect with graphite

Few things:

  1. I want to start it as a background process, rather than from erl.
  2. Right now it is sending stats (when used along with vmstats) on UDP ports on localhost (lo interface), I want the messages on eth0 and on the ip.
  3. How should I send my messages(datapoints) to graphite.

I am new to the erlang world, sorry if I ask something stupid.

Implement meters and historgrams

According to the StatsD spec (the only one available...) histograms and meters are part of the protocol, but statsderl currently does not support these metrics:

https://github.com/b/statsd_spec
https://github.com/etsy/statsd/wiki/Protocol

Other clients that do support these metrics:

Codahale StatsD reporter: https://github.com/organicveggie/metrics-statsd/blob/master/src/main/java/com/bealetech/metrics/reporting/StatsdReporter.java#L129
Go: https://github.com/alexcesaro/statsd/blob/master/statsd.go

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.