statsd 0.2.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 54

StatsD client for Dart #

Build Status Pub package License

A StatsD client library implemented in Dart.

Installation #

Use git dependency in your pubspec.yaml:

dependencies:
  statsd: "^0.2.0"

And then import it as usual:

import 'package:statsd/statsd.dart';

Usage #

Basic example:

import 'dart:io';
import 'dart:async';
import 'package:statsd/statsd.dart';

Future main() async {
  var connection = await StatsdConnection.connect(
    Uri.parse('udp://127.0.0.1:5678'));
  var client = new StatsdClient(connection, prefix: 'myapp');
  // Sending counters:
  await client.count('metric1'); // increment `myapp.metric1` by 1
  await client.count('metric1', -1); // decrement `myapp.metric1` by 1
  await client.count('metric1', 5, 0.1); // increment `myapp.metric1` by 5 with 0.1 sample rate

  // Sending timings:
  var stopwatch = new Stopwatch();
  stopwatch.start();
  // client will use value of stopwatch.elapsedMilliseconds
  await client.time('response-time', stopwatch);

  // Sending gauges:
  await client.gauge('metric2', 428); // sets gauge value to 428
  await client.gaugeDelta('metric2', 3); // increments value by 3
  await client.gaugeDelta('metric2', -10); // decrements value by 10

  // Sending sets:
  await client.set('uniques', 345);

  // Sending multiple metrics at once:
  var batch = client.batch();
  batch
    ..time('response-time', stopwatch)
    ..count('total-requests', 3)
    ..set('metric1', 56);
  await batch.send();

  // Make sure to close the connection when done:
  connection.close();
}

Current limitations:

  • Only UDP connections are supported at this moment.

License #

BSD-2

[0.2.0] #

  • updated for Dart 2

[0.1.1] #

  • added logger (name 'statsd') as well as some logging for UDP connection.
  • added possibility to set prefix for metric names in StatsdClient.
  • fixed bug in UDP connection when it was binding to the same port as Statsd server.

[0.1.0] #

  • initial version

example/main.dart

import 'dart:async';
import 'package:statsd/statsd.dart';

Future main() async {
  var connection =
      await StatsdConnection.connect(Uri.parse('udp://127.0.0.1:5678'));
  var client = new StatsdClient(connection, prefix: 'myapp');
  // Sending counters:
  await client.count('metric1'); // increment `myapp.metric1` by 1
  await client.count('metric1', -1); // decrement `myapp.metric1` by 1
  await client.count(
      'metric1', 5, 0.1); // increment `myapp.metric1` by 5 with 0.1 sample rate

  // Sending timings:
  var stopwatch = new Stopwatch();
  stopwatch.start();
  // client will use value of stopwatch.elapsedMilliseconds
  await client.time('response-time', stopwatch);

  // Sending gauges:
  await client.gauge('metric2', 428); // sets gauge value to 428
  await client.gaugeDelta('metric2', 3); // increments value by 3
  await client.gaugeDelta('metric2', -10); // decrements value by 10

  // Sending sets:
  await client.set('uniques', 345);

  // Sending multiple metrics at once:
  var batch = client.batch();
  batch
    ..time('response-time', stopwatch)
    ..count('total-requests', 3)
    ..set('metric1', 56);
  await batch.send();

  // Make sure to close the connection when done:
  connection.close();
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  statsd: ^0.2.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:statsd/statsd.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
47
Health:
Code health derived from static analysis. [more]
94
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
11
Overall:
Weighted score of the above. [more]
54
Learn more about scoring.

We analyzed this package on Apr 4, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6

Health suggestions

Fix lib/src/connection.dart. (-3.45 points)

Analysis of lib/src/connection.dart reported 7 hints, including:

line 14 col 13: Unnecessary new keyword.

line 31 col 21: Unnecessary new keyword.

line 38 col 28: Unnecessary new keyword.

line 41 col 28: Unnecessary new keyword.

line 46 col 26: Unnecessary new keyword.

Fix lib/src/client.dart. (-1.99 points)

Analysis of lib/src/client.dart reported 4 hints:

line 53 col 12: Unnecessary new keyword.

line 102 col 26: Unnecessary new keyword.

line 118 col 27: Unnecessary new keyword.

line 173 col 14: Unnecessary new keyword.

Fix lib/statsd.dart. (-0.50 points)

Analysis of lib/statsd.dart reported 1 hint:

line 12 col 18: Unnecessary new keyword.

Maintenance suggestions

Package is getting outdated. (-69.04 points)

The package was last published 88 weeks ago.

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev <3.0.0
logging ^0.11.2 0.11.4
Dev dependencies
mockito ^3.0.0-beta
test ^1.0.0