From f103abe02a769cbd83388076bd0bf96aa671c523 Mon Sep 17 00:00:00 2001 From: Chris Bobo Date: Tue, 30 Aug 2016 07:23:38 -0700 Subject: [PATCH] Add node-dogstatsd definitions and tests (#10795) * Add node-dogstatsd definitions and tests * Correct project url --- node-dogstatsd/node-dogstatsd-tests.ts | 48 ++++++++++++++++++++++++++ node-dogstatsd/node-dogstatsd.d.ts | 29 ++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 node-dogstatsd/node-dogstatsd-tests.ts create mode 100644 node-dogstatsd/node-dogstatsd.d.ts diff --git a/node-dogstatsd/node-dogstatsd-tests.ts b/node-dogstatsd/node-dogstatsd-tests.ts new file mode 100644 index 0000000000..9a32229bd6 --- /dev/null +++ b/node-dogstatsd/node-dogstatsd-tests.ts @@ -0,0 +1,48 @@ +/// + +import * as datadog from 'node-dogstatsd'; + +function test_statsd_client() { + // can create client with defaults + let client = new datadog.StatsD('localhost'); + let options: datadog.StatsDOptions = { global_tags: ['environment:definitely_typed']}; + + // can create client with all params + client = new datadog.StatsD('localhost', 8125, null, options); + + let key: string = 'key'; + let timeValue: number = 99; + let sampleRate: number = 0.85; + let incrementBy: number = 7; + let decrementBy: number = 5; + let gaugeValue: number = 199; + let tags: string[] = ['tag1', 'tag2']; + + client.timing(key, timeValue); + client.timing(key, timeValue, sampleRate); + client.timing(key, timeValue, sampleRate, tags); + + client.increment(key); + client.increment(key, sampleRate); + client.increment(key, sampleRate, tags); + + client.incrementBy(key, incrementBy); + client.incrementBy(key, incrementBy, tags); + + client.decrement(key); + client.decrement(key, sampleRate); + client.decrement(key, sampleRate, tags); + + client.decrementBy(key, decrementBy); + client.decrementBy(key, decrementBy, tags); + + client.gauge(key, gaugeValue); + client.gauge(key, gaugeValue, sampleRate); + client.gauge(key, gaugeValue, sampleRate, tags); + + client.histogram(key, timeValue); + client.histogram(key, timeValue, sampleRate); + client.histogram(key, timeValue, sampleRate, tags); + + client.close(); +} diff --git a/node-dogstatsd/node-dogstatsd.d.ts b/node-dogstatsd/node-dogstatsd.d.ts new file mode 100644 index 0000000000..36f8145202 --- /dev/null +++ b/node-dogstatsd/node-dogstatsd.d.ts @@ -0,0 +1,29 @@ +// Type definitions for Datadog's nodejs metrics client node-dogstatsd +// Project: https://github.com/joybro/node-dogstatsd +// Definitions by: Chris Bobo +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare module "node-dogstatsd" { + + export interface StatsDOptions { + global_tags?: string[]; + } + + export class StatsD { + constructor(host: string, port?: number, socket?: string, options?: StatsDOptions); + + timing(stat: string, time: number, sample_rate?: number, tags?: string[]): void; + + increment(stat: string, sample_rate?: number, tags?: string[]): void; + incrementBy(stat: string, value: number, tags?: string[]): void; + + decrement(stat: string, sample_rate?: number, tags?: string[]): void; + decrementBy(stat: string, value: number, tags?: string[]): void; + + gauge(stat: string, value: number, sample_rate?: number, tags?: string[]): void; + + histogram(stat: string, time: number, sample_rate?: number, tags?: string[]): void; + + close(): void; + } +}