UNPKG

5.06 kBTypeScriptView Raw
1import { IReferenceable } from 'pip-services3-commons-node';
2import { IReferences } from 'pip-services3-commons-node';
3import { IOpenable } from 'pip-services3-commons-node';
4import { CachedCounters, Counter } from 'pip-services3-components-node';
5import { ConfigParams } from 'pip-services3-commons-node';
6/**
7 * Performance counters that periodically dumps counters to AWS Cloud Watch Metrics.
8 *
9 * ### Configuration parameters ###
10 *
11 * - connections:
12 * - discovery_key: (optional) a key to retrieve the connection from [[https://pip-services3-node.github.io/pip-services3-components-node/interfaces/connect.idiscovery.html IDiscovery]]
13 * - region: (optional) AWS region
14 * - credentials:
15 * - store_key: (optional) a key to retrieve the credentials from [[https://pip-services3-node.github.io/pip-services3-components-node/interfaces/auth.icredentialstore.html ICredentialStore]]
16 * - access_id: AWS access/client id
17 * - access_key: AWS access/client id
18 * - options:
19 * - interval: interval in milliseconds to save current counters measurements (default: 5 mins)
20 * - reset_timeout: timeout in milliseconds to reset the counters. 0 disables the reset (default: 0)
21 *
22 * ### References ###
23 *
24 * - <code>\*:context-info:\*:\*:1.0</code> (optional) [[https://pip-services3-node.github.io/pip-services3-components-node/classes/info.contextinfo.html ContextInfo]] to detect the context id and specify counters source
25 * - <code>\*:discovery:\*:\*:1.0</code> (optional) [[https://pip-services3-node.github.io/pip-services3-components-node/interfaces/connect.idiscovery.html IDiscovery]] services to resolve connections
26 * - <code>\*:credential-store:\*:\*:1.0</code> (optional) Credential stores to resolve credentials
27 *
28 * @see [[https://pip-services3-node.github.io/pip-services3-components-node/classes/count.counter.html Counter]] (in the Pip.Services components package)
29 * @see [[https://pip-services3-node.github.io/pip-services3-components-node/classes/count.cachedcounters.html CachedCounters]] (in the Pip.Services components package)
30 * @see [[https://pip-services3-node.github.io/pip-services3-components-node/classes/log.compositelogger.html CompositeLogger]] (in the Pip.Services components package)
31 *
32 * ### Example ###
33 *
34 * let counters = new CloudWatchCounters();
35 * counters.config(ConfigParams.fromTuples(
36 * "connection.region", "us-east-1",
37 * "connection.access_id", "XXXXXXXXXXX",
38 * "connection.access_key", "XXXXXXXXXXX"
39 * ));
40 * counters.setReferences(References.fromTuples(
41 * new Descriptor("pip-services", "logger", "console", "default", "1.0"),
42 * new ConsoleLogger()
43 * ));
44 *
45 * counters.open("123", (err) => {
46 * ...
47 * });
48 *
49 * counters.increment("mycomponent.mymethod.calls");
50 * let timing = counters.beginTiming("mycomponent.mymethod.exec_time");
51 * try {
52 * ...
53 * } finally {
54 * timing.endTiming();
55 * }
56 *
57 * counters.dump();
58 */
59export declare class CloudWatchCounters extends CachedCounters implements IReferenceable, IOpenable {
60 private _logger;
61 private _connectionResolver;
62 private _connection;
63 private _connectTimeout;
64 private _client;
65 private _source;
66 private _instance;
67 private _opened;
68 /**
69 * Creates a new instance of this counters.
70 */
71 constructor();
72 /**
73 * Configures component by passing configuration parameters.
74 *
75 * @param config configuration parameters to be set.
76 */
77 configure(config: ConfigParams): void;
78 /**
79 * Sets references to dependent components.
80 *
81 * @param references references to locate the component dependencies.
82 * @see [[https://pip-services3-node.github.io/pip-services3-commons-node/interfaces/refer.ireferences.html IReferences]] (in the Pip.Services commons package)
83 */
84 setReferences(references: IReferences): void;
85 /**
86 * Checks if the component is opened.
87 *
88 * @returns true if the component has been opened and false otherwise.
89 */
90 isOpen(): boolean;
91 /**
92 * Opens the component.
93 *
94 * @param correlationId (optional) transaction id to trace execution through call chain.
95 * @param callback callback function that receives error or null no errors occured.
96 */
97 open(correlationId: string, callback: (err: any) => void): void;
98 /**
99 * Closes component and frees used resources.
100 *
101 * @param correlationId (optional) transaction id to trace execution through call chain.
102 * @param callback callback function that receives error or null no errors occured.
103 */
104 close(correlationId: string, callback: (err: any) => void): void;
105 private getCounterData;
106 /**
107 * Saves the current counters measurements.
108 *
109 * @param counters current counters measurements to be saves.
110 */
111 protected save(counters: Counter[]): void;
112}