All Projects → immobiliare → dats

immobiliare / dats

Licence: MIT license
📈 Minimalistic zero-dependencies statsd client for Node.js

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to dats

Socketify
Raw TCP and UDP Sockets API on Desktop Browsers
Stars: ✭ 67 (+6.35%)
Mutual labels:  tcp, udp
twjitm-core
采用Netty信息加载实现长连接实时通讯系统,客户端可以值任何场景,支持实时http通讯、webSocket通讯、tcp协议通讯、和udp协议通讯、广播协议等 通过http协议,rpc协议。 采用自定义网络数据包结构, 实现自定义网络栈。
Stars: ✭ 98 (+55.56%)
Mutual labels:  tcp, udp
ctsTraffic
ctsTraffic is a highly scalable client/server networking tool giving detailed performance and reliability analytics
Stars: ✭ 125 (+98.41%)
Mutual labels:  tcp, udp
SACK
System Abstraction Component Kit
Stars: ✭ 18 (-71.43%)
Mutual labels:  tcp, udp
ComputerNetworks-unipd2018
Tips and resources to easily pass the "Computer Networks" practical exam ("Reti di calcolatori") in Padua
Stars: ✭ 21 (-66.67%)
Mutual labels:  tcp, udp
server-framework
纯C的分布式服务器框架通用模板,跨平台,模块动态加载,tcp/可靠UDP,协程RPC,日志,集群建立
Stars: ✭ 24 (-61.9%)
Mutual labels:  tcp, udp
iit-kgp-network
Information repository and Solutions on IIT KGP Internet Problems.
Stars: ✭ 28 (-55.56%)
Mutual labels:  tcp, udp
Socket
The Hoa\Socket library.
Stars: ✭ 61 (-3.17%)
Mutual labels:  tcp, udp
udp2raw
A Tunnel which Turns UDP Traffic into Encrypted UDP/FakeTCP/ICMP Traffic by using Raw Socket,helps you Bypass UDP FireWalls(or Unstable UDP Environment)
Stars: ✭ 5,256 (+8242.86%)
Mutual labels:  tcp, udp
nc
Porting Netcat in Node.js. CLI util. 💻
Stars: ✭ 17 (-73.02%)
Mutual labels:  tcp, udp
network
exomia/network is a wrapper library around System.Socket for easy and fast TCP/UDP client & server communication.
Stars: ✭ 18 (-71.43%)
Mutual labels:  tcp, udp
DatagramTunneler
Simple C++ cross-platform client/server app forwarding UDP datagrams through a TCP connection.
Stars: ✭ 116 (+84.13%)
Mutual labels:  tcp, udp
net-protocol
golang模拟内核协议栈 实现链路层、网络层、传输层、应用层 用户态协议栈 ,基于虚拟网卡TUN/TAP
Stars: ✭ 129 (+104.76%)
Mutual labels:  tcp, udp
socket
Dazzle Async Socket
Stars: ✭ 19 (-69.84%)
Mutual labels:  tcp, udp
reverse-tunnel
Reverse tunnel TCP and UDP
Stars: ✭ 100 (+58.73%)
Mutual labels:  tcp, udp
voice
Implementation of the Discord Voice API for discord.js and other JS/TS libraries
Stars: ✭ 310 (+392.06%)
Mutual labels:  tcp, udp
KingNetwork
KingNetwork is an open source library to facilitate the creation and communication of clients and servers via TCP, UDP, WebSocket and RUDP sockets.
Stars: ✭ 78 (+23.81%)
Mutual labels:  tcp, udp
hev-socks5-tproxy
A simple, lightweight socks5 transparent proxy for Linux. (IPv4/IPv6/TCP/UDP over TCP)
Stars: ✭ 209 (+231.75%)
Mutual labels:  tcp, udp
Rmessage
Reactive Programming Multi-protocol push service
Stars: ✭ 23 (-63.49%)
Mutual labels:  tcp, udp
asyncio-socks-server
A SOCKS proxy server implemented with the powerful python cooperative concurrency framework asyncio.
Stars: ✭ 154 (+144.44%)
Mutual labels:  tcp, udp

logo

dats

release workflow code style: prettier semantic-release npm (scoped) license

Minimalistic zero-dependencies UDP/TCP statsd client for Node.js

There are times when you have to gather metrics and you want something simple without writing too much boilerplate, dats to your aid!

This client aims to have a simple statsd compliant API with some optional flavour for advanced usage, like: buffered metrics and either UDP/TCP transports!

Supports Node.js >=14.0.0, if you are a Node.js v12 user refer to [email protected].

Table of Content

Installation

The package is available at npm.

You can install it with npm

# lastest stable version
$ npm i -S @immobiliarelabs/dats
# latest development version
$ npm i -S @immobiliarelabs/dats@next

or yarn

# lastest stable version
$ yarn add @immobiliarelabs/dats
# latest development version
$ yarn @immobiliarelabs/dats@next

Usage

Generic

import Client from '@immobiliarelabs/dats';

const stats = new Client({
    host: 'udp://someip:someport',
    namespace: 'myGrafanaNamespace',
    // Optionally register a global handler to track errors.
    onError: (error) => {
        processError(error);
    },
});

// Send counter (myGrafanaNamespace.some.toCount)
stats.counter('some.toCount', 3);
stats.counter('some.toCount'); // defaults to 1
stats.counter('some.toCount', 1, 10); // set sampling to 10
// Send timing (myGrafanaNamespace.some.toTime)
stats.timing('some.toTime', 10);
stats.timing('some.toTime', 10, 0.1); // set sampling to 0.1

// Send gauge (myGrafanaNamespace.some.toGauge)
stats.gauge('some.toGauge', 23);

// Send set (myGrafanaNamespace.some.set)
stats.set('some.set', 765);

Namespacing with Hostname/PID

// Scope your stats per hostname and/or pid
import Client from '@immobiliarelabs/dats';

const stats = new Client({
    host: 'udp://someip:someport',
    namespace: 'myGrafanaNamespace.${hostname}.${pid}',
});

// Send counter (myGrafanaNamespace.myMachine.123.some.toCount)
stats.counter('some.toCount', 3);

If the hostname contains any ., the client will replace them with _.

TCP Client

import Client from '@immobiliarelabs/dats';

// TCP usage
const stats = new Client({
    host: 'tcp://someip:someport',
    namespace: 'myGrafanaNamespace.${hostname}.${pid}',
});

// Calling connect is required in TCP environment
await stats.connect();

// Send counter (myGrafanaNamespace.myMachine.123.some.toCount)
stats.counter('some.toCount', 3);

API

This module exports:

Client

The statsd client

new Client(options)

  • options: configuration object.
    • host: statsd host (udp://{ip}:{port} or tcp://{ip}:{port}), you can use also ipv6. If you want to force udp6 usage use: udp6://{host}:{port}, when using TCP, you have to call the Client.connect method.
    • namespace: Optional. Prefix to use for the metrics. The metric will be sent as namespace. + the metric string. Optionally you can use ${hostname} and ${pid} placeholders in the namespace and have them substituted with the machine hostname and the process id.
    • bufferSize: Optional. Default is 0. Setting this value to a number greather than zero will activate buffered mode, which instead of sending metrics on each call, it will buffer them and send them when one of this conditions occurs: the buffer is full, or the bufferFlushTimeout has expired. Using this approach is more performant, but you must be careful to use a value compatible to the MTU available on your network, otherwise your packets might get dropped silently. See multi-metric-packets.
    • bufferFlushTimeout: Optional. Default is 100. Timeout in milliseconds to wait before flushing the metrics buffer.
    • debug: Optional. Default debuglog('dats'). The logger function.
    • udpDnsCache: Optional. Default true. Activate the cache DNS lookup for udp.
    • udpDnsCacheTTL: Optional. Default 120. Dns cache Time to live in seconds.
    • onError: Optional. Default (err) => void. Called when there is an error. Allows you to check also send errors.
    • customSocket: Optional. Default null. Custom socket used by the client, this is a feature for mocking we do not recommend using it in production.

Client.close([cb])

close the client socket

  • cb: optional. A callback function to call when the socket is closed. If no cb is provided a Promise is returned.

Returns: a Promise if no cb is passed.

Client.connect()

connect the TCP socket. Calling this function is required only on TCP.

Returns: a Promise.

Client.counter(string[, value, sampling])

send a metric of type counter

  • string: The metric string
  • value: Optional. The metric value (Number). Defaults to 1.
  • sampling: Optional. The metric sampling.

All sending errors are handled by the onError callback.

Client.timing(string, value[, sampling])

send a metric of type timing

  • string: The metric string
  • value: The metric value (Number).
  • sampling: Optional. The metric sampling.

All sending errors are handled by the onError callback.

Client.gauge(string, value)

send a metric of type gauge

  • string: The metric string
  • value: The metric value (Number).

All sending errors are handled by the onError callback.

Client.set(string, value)

send a metric of type set

  • string: The metric string
  • value: The metric value (Number).

All sending errors are handled by the onError callback.

Dats Mock

Dats exports his mock, you can use it as follow:

import ClientMock from '@immobiliarelabs/dats/dist/mock';

const host = new URL(`udp://127.0.0.1:8232`);
const namespace = 'ns1';
const client = new ClientMock({ host, namespace });

client.gauge('some.metric', 100);
client.set('some.metric', 100);
// metrics is an array with all metrics sent
console.log(client.metrics);
/* stdout:
    [
        'ns1.some.metric:100|g',
        'ns1.some.metric:100|s',
    ]
*/
// Check if a metric is in the metrics array
client.hasSent('ns1.some.metric:100|s'); // -> true
client.hasSent('ns1.some.metric:10|s'); // -> false
client.hasSent(/ns1\.some\.metric:\d+\|s/); // -> true
client.hasSent(/ns1\.some\.test:\d+\|s/); // -> false

// Clean the metrics array with
client.cleanMetrics();
console.log(client.metrics);
/* stdout:
    []
*/

Benchmarks

The automatic benchmarking for every commit can be found at the following links: next and main.

The tests were done using autocannon pointing to an HTTP node.js Server that sends at each request a count metric. With this kind of test, we evaluate how much the library influences the application performance.

Below are reported the benchmarks with the most famous node.js statsd clients:

LIBRARY Req/Sec (97.5th) Req/Sec (avg)
dats 45503 43174.4
hot-shots 46975 43319.47
node-statsd 14935 11632.34
statsd-client 42463 35790.67
Base 50271 43312.54

Base is the HTTP server without metrics.

Powered Apps

dats was created by the amazing Node.js team at ImmobiliareLabs, the Tech dept of Immobiliare.it, the #1 real estate company in Italy.

We are currently using dats in our products as well as our internal toolings.

If you are using dats in production drop us a message.

Support & Contribute

Made with ❤️ by ImmobiliareLabs & Contributors

We'd love for you to contribute to dats! If you have any questions on how to use dats, bugs and enhancement please feel free to reach out by opening a GitHub Issue.

License

dats is licensed under the MIT license.
See the LICENSE file for more information.

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