UNPKG

6.88 kBTypeScriptView Raw
1import dgram = require("dgram");
2
3declare module "hot-shots" {
4 export type Tags = { [key: string]: string } | string[];
5 export interface ClientOptions {
6 bufferFlushInterval?: number;
7 bufferHolder?: { buffer: string };
8 cacheDns?: boolean;
9 cacheDnsTtl?: number;
10 errorHandler?: (err: Error) => void;
11 globalTags?: Tags;
12 globalize?: boolean;
13 host?: string;
14 isChild?: boolean;
15 maxBufferSize?: number;
16 mock?: boolean;
17 path?: string;
18 port?: number;
19 prefix?: string;
20 protocol?: 'tcp' | 'udp' | 'uds';
21 sampleRate?: number;
22 socket?: dgram.Socket;
23 suffix?: string;
24 telegraf?: boolean;
25 useDefaultRoute?: boolean;
26 tagPrefix?: string;
27 tagSeparator?: string;
28 udsGracefulErrorHandling?: boolean;
29 udsGracefulRestartRateLimit?: number;
30 }
31
32 export interface ChildClientOptions {
33 globalTags?: Tags;
34 prefix?: string;
35 suffix?: string;
36 }
37
38 export interface CheckOptions {
39 date_happened?: Date;
40 hostname?: string;
41 message?: string;
42 }
43
44 export interface DatadogChecks {
45 OK: 0;
46 WARNING: 1;
47 CRITICAL: 2;
48 UNKNOWN: 3;
49 }
50
51 type unionFromInterfaceValues4<
52 T,
53 K1 extends keyof T,
54 K2 extends keyof T,
55 K3 extends keyof T,
56 K4 extends keyof T,
57 > = T[K1] | T[K2] | T[K3] | T[K4];
58
59 export type DatadogChecksValues = unionFromInterfaceValues4<DatadogChecks, "OK", "WARNING", "CRITICAL", "UNKNOWN">;
60
61 export interface EventOptions {
62 aggregation_key?: string;
63 alert_type?: "info" | "warning" | "success" | "error";
64 date_happened?: Date;
65 hostname?: string;
66 priority?: "low" | "normal";
67 source_type_name?: string;
68 }
69
70 export type StatsCb = (error: Error | undefined, bytes: any) => void;
71
72 export class StatsD {
73 constructor(options?: ClientOptions);
74 childClient(options?: ChildClientOptions): StatsD;
75
76 increment(stat: string, tags?: Tags): void;
77 increment(stat: string | string[], value: number, sampleRate?: number, tags?: Tags, callback?: StatsCb): void;
78 increment(stat: string | string[], value: number, tags?: Tags, callback?: StatsCb): void;
79 increment(stat: string | string[], value: number, callback?: StatsCb): void;
80 increment(stat: string | string[], value: number, sampleRate?: number, callback?: StatsCb): void;
81
82 decrement(stat: string): void;
83 decrement(stat: string | string[], value: number, sampleRate?: number, tags?: Tags, callback?: StatsCb): void;
84 decrement(stat: string | string[], value: number, tags?: Tags, callback?: StatsCb): void;
85 decrement(stat: string | string[], value: number, callback?: StatsCb): void;
86 decrement(stat: string | string[], value: number, sampleRate?: number, callback?: StatsCb): void;
87
88 timing(stat: string | string[], value: number, sampleRate?: number, tags?: Tags, callback?: StatsCb): void;
89 timing(stat: string | string[], value: number, tags?: Tags, callback?: StatsCb): void;
90 timing(stat: string | string[], value: number, callback?: StatsCb): void;
91 timing(stat: string | string[], value: number, sampleRate?: number, callback?: StatsCb): void;
92
93 timer<P extends any[], R>(func: (...args: P) => R, stat: string | string[], sampleRate?: number, tags?: Tags, callback?: StatsCb): (...args: P) => R;
94 timer<P extends any[], R>(func: (...args: P) => R, stat: string | string[], tags?: Tags, callback?: StatsCb): (...args: P) => R;
95 timer<P extends any[], R>(func: (...args: P) => R, stat: string | string[], callback?: StatsCb): (...args: P) => R;
96 timer<P extends any[], R>(func: (...args: P) => R, stat: string | string[], sampleRate?: number, callback?: StatsCb): (...args: P) => R;
97
98 asyncTimer<P extends any[], R>(func: (...args: P) => Promise<R>, stat: string | string[], sampleRate?: number, tags?: Tags, callback?: StatsCb): (...args: P) => Promise<R>;
99 asyncTimer<P extends any[], R>(func: (...args: P) => Promise<R>, stat: string | string[], tags?: Tags, callback?: StatsCb): (...args: P) => Promise<R>;
100 asyncTimer<P extends any[], R>(func: (...args: P) => Promise<R>, stat: string | string[], callback?: StatsCb): (...args: P) => Promise<R>;
101 asyncTimer<P extends any[], R>(func: (...args: P) => Promise<R>, stat: string | string[], sampleRate?: number, callback?: StatsCb): (...args: P) => Promise<R>;
102
103 histogram(stat: string | string[], value: number, sampleRate?: number, tags?: Tags, callback?: StatsCb): void;
104 histogram(stat: string | string[], value: number, tags?: Tags, callback?: StatsCb): void;
105 histogram(stat: string | string[], value: number, callback?: StatsCb): void;
106 histogram(stat: string | string[], value: number, sampleRate?: number, callback?: StatsCb): void;
107
108 distribution(stat: string | string[], value: number, sampleRate?: number, tags?: Tags, callback?: StatsCb): void;
109 distribution(stat: string | string[], value: number, tags?: Tags, callback?: StatsCb): void;
110 distribution(stat: string | string[], value: number, callback?: StatsCb): void;
111 distribution(stat: string | string[], value: number, sampleRate?: number, callback?: StatsCb): void;
112
113 gauge(stat: string | string[], value: number, sampleRate?: number, tags?: Tags, callback?: StatsCb): void;
114 gauge(stat: string | string[], value: number, tags?: Tags, callback?: StatsCb): void;
115 gauge(stat: string | string[], value: number, callback?: StatsCb): void;
116 gauge(stat: string | string[], value: number, sampleRate?: number, callback?: StatsCb): void;
117
118 set(stat: string | string[], value: number | string, sampleRate?: number, tags?: Tags, callback?: StatsCb): void;
119 set(stat: string | string[], value: number | string, tags?: Tags, callback?: StatsCb): void;
120 set(stat: string | string[], value: number | string, callback?: StatsCb): void;
121 set(stat: string | string[], value: number | string, sampleRate?: number, callback?: StatsCb): void;
122
123 unique(stat: string | string[], value: number | string, sampleRate?: number, tags?: Tags, callback?: StatsCb): void;
124 unique(stat: string | string[], value: number | string, tags?: Tags, callback?: StatsCb): void;
125 unique(stat: string | string[], value: number | string, callback?: StatsCb): void;
126 unique(stat: string | string[], value: number | string, sampleRate?: number, callback?: StatsCb): void;
127
128 close(callback: (error?: Error) => void): void;
129
130 event(title: string, text?: string, options?: EventOptions, tags?: Tags, callback?: StatsCb): void;
131 event(title: string, text?: string, options?: EventOptions, callback?: StatsCb): void;
132 check(name: string, status: DatadogChecksValues, options?: CheckOptions, tags?: Tags, callback?: StatsCb): void;
133
134 public CHECKS: DatadogChecks;
135 public mockBuffer?: string[];
136 public socket: dgram.Socket;
137 }
138}
139
140declare const StatsDClient: new (options?: ClientOptions) => StatsD;
141export default StatsDClient;