statsd 0.2.0

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]
0
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
46
Learn more about scoring.

We analyzed this package on Jul 18, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: Flutter, other

Primary library: package:statsd/statsd.dart with components: io.

Maintenance suggestions

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.3+2
Dev dependencies
mockito ^3.0.0-beta
test ^1.0.0

Admin