diff --git a/graphite-udp/graphite-udp-tests.ts b/graphite-udp/graphite-udp-tests.ts new file mode 100644 index 0000000000..c61ad172cd --- /dev/null +++ b/graphite-udp/graphite-udp-tests.ts @@ -0,0 +1,43 @@ +import graphite = require('graphite-udp'); + +// Test creation of client directly. +let client = new graphite.Client(); +client.put('test', 1); +client.add('test', 1); +client.close(); + +// Create client with helper +let client2 = graphite.createClient(); +client2.put('test2', 1); +client2.add('test2', 1); +client2.close(); + +// Test creation with options. +graphite.createClient({ + host: '127.0.0.1', + port: 2003, + type: 'udp4', + maxPacketSize: 4096, + prefix: 'prefix', + suffix: 'suffix', + interval: 60 * 1000, + verbose: true, + callback: (error: Error, metrics: any): void => { + + } +}); + +// Test creation options with class directly. +new graphite.Client({ + host: '127.0.0.1', + port: 2003, + type: 'udp4', + maxPacketSize: 4096, + prefix: 'prefix', + suffix: 'suffix', + interval: 60 * 1000, + verbose: true, + callback: (error: Error, metrics: any): void => { + + } +}); diff --git a/graphite-udp/index.d.ts b/graphite-udp/index.d.ts new file mode 100644 index 0000000000..218888b39a --- /dev/null +++ b/graphite-udp/index.d.ts @@ -0,0 +1,97 @@ +// Type definitions for graphite-udp 1.2 +// Project: https://github.com/fermads/graphite-udp +// Definitions by: Eric Byers +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + + +interface ClientOptions { + /** + * graphite server host or ip + * Defaults to 127.0.0.1 + */ + host?: string; + + /** + * graphite server udp port + * Defaults to 2003 + */ + port?: number; + + /** + * udp type (udp4 or udp6) + * Defaults to udp4 + */ + type?: 'udp4' | 'udp6'; + + /** + * split into smaller UDP packets + * Defaults to 4096 + */ + maxPacketSize?: number; + + /** + * Prefix for each metric name + * Defaults to '' + */ + prefix?: string; + + /** + * Suffix for each metrtic name + * Defaults to '' + */ + suffix?: string; + + /** + * Interval to group metrics by in milliseconds + * Defaults to 5000 (5s) + */ + interval?: number; + + /** + * log messages to console + * Defaults to false + */ + verbose?: boolean; + + /** + * called when metrics are sent + * Defaults to null + * + * @param {error} Error + * @param {metrics} + * @return void + */ + callback?: (error: Error, metrics: any) => void; +} + +export class Client { + + constructor(clientOptions?: ClientOptions); + + /** + * During the interval time option, if 2 or more metrics with the same name are sent, metrics will be added (summed) + * + * @param {name} + * @param {value} number + * @return void + */ + add(name: string, value: number): void; + + /** + * During the interval time option, if 2 or more metrics with the same name are sent, the last one will be used + * + * @param {name} metric name (my.test.metric) + * @param {value} number + * @return void + */ + put(name: string, value: number): void; + + /** + * Close the underlying UDP client socket + * + * @return void + */ + close(): void; +} + +export function createClient(clientOptions?: ClientOptions): Client; diff --git a/graphite-udp/tsconfig.json b/graphite-udp/tsconfig.json new file mode 100644 index 0000000000..50f3e17459 --- /dev/null +++ b/graphite-udp/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "graphite-udp-tests.ts" + ] +} diff --git a/graphite-udp/tslint.json b/graphite-udp/tslint.json new file mode 100644 index 0000000000..377cc837d4 --- /dev/null +++ b/graphite-udp/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" }