All Projects → TryStatsN → StatsN

TryStatsN / StatsN

Licence: MIT License
A modern c# statsd client for .net core and .net 4.0+

Programming Languages

C#
18002 projects
powershell
5483 projects

Projects that are alternatives of or similar to StatsN

Magician
Magician is a small HTTP service package based on Netty that makes it very easy to start an http service, and also supports WebSocket, using annotated configuration Handler, If you want to develop an http service with netty but find it cumbersome, then Magician may help you.
Stars: ✭ 97 (+410.53%)
Mutual labels:  udp
ccxx
This is a cross-platform library software library about c, c ++, unix4, posix. Include gtest, benchmark, cmake, process lock, daemon, libuv, lua, cpython, re2, json, yaml, mysql, redis, opencv, qt, lz4, oci ... https://hub.docker.com/u/oudream
Stars: ✭ 31 (+63.16%)
Mutual labels:  udp
prometheus-httpd
Expose Prometheus metrics using inets httpd.
Stars: ✭ 21 (+10.53%)
Mutual labels:  metrics
dats
📈 Minimalistic zero-dependencies statsd client for Node.js
Stars: ✭ 63 (+231.58%)
Mutual labels:  udp
otrchat
😈 An end-to-end encrypted chat system based on the OTR protocol
Stars: ✭ 18 (-5.26%)
Mutual labels:  udp
packetdrill
packetdrill with UDPLite and SCTP support and bug fixes for FreeBSD
Stars: ✭ 37 (+94.74%)
Mutual labels:  udp
twjitm-core
采用Netty信息加载实现长连接实时通讯系统,客户端可以值任何场景,支持实时http通讯、webSocket通讯、tcp协议通讯、和udp协议通讯、广播协议等 通过http协议,rpc协议。 采用自定义网络数据包结构, 实现自定义网络栈。
Stars: ✭ 98 (+415.79%)
Mutual labels:  udp
fluentd-elastic-kibana
Working inital configuration for fluentd elastic and kibana
Stars: ✭ 40 (+110.53%)
Mutual labels:  metrics
web-udp
Establish client/server and P2P UDP-like channels in the browser
Stars: ✭ 43 (+126.32%)
Mutual labels:  udp
icingaweb2-module-pnp
Integrate PNP graphs into Icinga Web 2
Stars: ✭ 32 (+68.42%)
Mutual labels:  metrics
netty-raknet
A reliable and high performance RakNet library designed with strict Netty patterns.
Stars: ✭ 24 (+26.32%)
Mutual labels:  udp
dpdk
A comprehensive rust binding for DPDK allowing high speed userspace networking across 256 cores and 32 NICs
Stars: ✭ 30 (+57.89%)
Mutual labels:  udp
mocket
Reliable UDP server client for flaky networks
Stars: ✭ 21 (+10.53%)
Mutual labels:  udp
DatagramTunneler
Simple C++ cross-platform client/server app forwarding UDP datagrams through a TCP connection.
Stars: ✭ 116 (+510.53%)
Mutual labels:  udp
gin-metrics
gin-gonic/gin metrics for prometheus.
Stars: ✭ 87 (+357.89%)
Mutual labels:  metrics
Socketify
Raw TCP and UDP Sockets API on Desktop Browsers
Stars: ✭ 67 (+252.63%)
Mutual labels:  udp
influxdb-php-sdk
InfluxDB PHP SDK - UDP/IP or HTTP adapters for read and write data
Stars: ✭ 88 (+363.16%)
Mutual labels:  udp
kcp-dotnet
KCP dotNet Core implementation
Stars: ✭ 26 (+36.84%)
Mutual labels:  udp
torch-metrics
Metrics for model evaluation in pytorch
Stars: ✭ 99 (+421.05%)
Mutual labels:  metrics
libmcu
A toolkit for firmware development
Stars: ✭ 33 (+73.68%)
Mutual labels:  metrics

StatsN

Build status Coverage Status

StatsN is a modern performance first Stastd client for dotnet core. StatsN supports both TCP and UDP, although UDP is recommended. Largely inspired by the statsd-csharp-client and the statsd.net client. Both projects In my mind are awesome 👊, just not exactly what I was looking for.

I wrote this client, because I found unit testing statics less than fun, and tired of waiting for features to be published. Or support for features that statsd does not actually supprt.

This client attempts to help testability by using interfaces, observability by allowing you to register functions to listen for exceptions and logging that occurs inside the client, and scalability by really making the code perform well.

Getting started

Install-Package StatsN

In short the api is easy. You can get a new IStatsd with a few different ways, and then you can log metrics with an IStatsd implementation. Here are some examples.

Note, You will want to store your IStatsd as a singleton (most likely inside a DI container). This type persists a tcp or udp connection. The client's functions are thread safe.

IStatsd statsd = Statsd.New<Udp>(a=>a.HostOrIp = "10.22.2.1", Port = 8125, Prefix = "MyMicroserviceName");
IStatsd statsd = Statsd.New<Tcp>(a=>a.HostOrIp = "10.22.2.1"); //use tcp
IStatsd statsd = Statsd.New<NullChannel>(a=>a.HostOrIp = "10.22.2.1", Port = 8125); //pipes your metrics to nowhere...which can scale infinately btw
IStatsd statsd = Statsd.New(a=>a.HostOrIp = "10.22.2.1"); //defaults to udp
IStatsd statsd = Statsd.New(new StatsdOptions(){ HostOrIp = "127.0.0.1"}); //defaults to udp
IStatsd statsd = new Stastd(new StatsdOptions(){ HostOrIp = "127.0.0.1"});  //defaults to udp
IStatsd statsd = new Stastd(new StatsdOptions(){ HostOrIp = "127.0.0.1"}, new Tcp()); //pass a new udp client. You could in theory make your own transport if you inherit from BaseCommunicationProvider


statsd.CountAsync("myapp.counterstat"); //default to 1 aka increment
statsd.CountAsync("myapp.counterstat", 6);
statsd.CountAsync("myapp.counterstat", -6);
statsd.TimerAsync("myapp.timeMyFunction", ()=>{
 //code to instrument
});
statsd.TimerAsync("myapp.timeData", 400); //400ms
statsd.GaugeAsync("autotest.gaugeyo", 422);
statsd.GaugeDeltaAsync("autotest.gaugeyo", -10);
statsd.SetAsync("autotest.setyo", 888);

Logging

Like most statsd clients, this client avoids throwing exceptions at all costs. Any errors/exceptions created will be logged as a Systems.Diagnostics.Trace messages.

You can pass lambda into the StatsdOptions class to be passed exceptions and log messages, instead of getting them through the Trace system.

            var opt = new StatsdOptions
            {
                OnExceptionGenerated = (exception) => { /* handle exception */ },
				OnLogEventGenerated = (log) => { /* handle log msg */ }
            };
			var stats = Statsd.New(opt);

or

var stats = Statsd.New(a=>a.OnExceptionGenerated = (exception) => { /* handle exception */ });

Buffering metrics

By setting the BufferMetrics property in the options object to true, the metrics will be buffered thus sending less packets. The Buffer size defaults to 512, which is documented by statsd. You may change its size using the BufferSize property of StastdOptions. This uses a Concurrent Queue to Queue up the metrics and a BackgroundWorker to peal metrics off the Queue and send them along aggregated.

var opt = new StatsdOptions(){

    BufferMetrics = true,
    BufferSize = 512
};

Awaiting metrics

By default the various logging metric functions return Tasks. You do not need to await on these If you await on these and you have buffered metrics off , you will return after the bytes have been added to the network stream. If you await, and buffered metrics are on then your await will return when your metric has been added to the Queue of metrics to be sent.

dotnet 4.0

While this project does target dotnet 4.0, the unit tests do not run in 4.0. The support is limited (new features may not come to dotnet 4.S), but bugs will be addressed.

Dev setup

If you plan on playing around with the code, be sure to download and install .NET core sdk.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].