CloudWatchCounters

Performance counters that periodically dump counters to AWS Cloud Watch Metrics.

Implements: IConfigurable, IReferenceable

Extends: CachedCounters

Description

The CloudWatchCounters class allows you to create performance counters that periodically dump counters to AWS Cloud Watch Metrics.

Configuration parameters

  • connections:
    • discovery_key: (optional) key to retrieve the connection from IDiscovery
    • region: (optional) AWS region
  • credentials:
    • store_key: (optional) key to retrieve the credentials from ICredentialStore
    • access_id: AWS access/client id
    • access_key: AWS access/client key
  • options:
    • interval: interval in milliseconds to save current counters measurements (default: 5 mins)
    • reset_timeout: timeout in milliseconds to reset the counters. 0 disables the reset (default: 0)

References

  • *:context-info:*:*:1.0 - (optional) ContextInfo to detect the context id and specify the counters' source
  • *:discovery:*:*:1.0 - (optional) IDiscovery services to resolve connections
  • *:credential-store:*:*:1.0 - (optional) credential stores to resolve credentials requests

Constructors

Creates a new instance of this counters.

public constructor()

Instance methods

close

Closes component and frees used resources.

public close(context: IContext): Promise<void>

  • context: IContext - (optional) a context to trace execution through a call chain.

configure

Configures a component by passing its configuration parameters.

public configure(config: ConfigParams): void

  • config: ConfigParams - configuration parameters to be set.

isOpen

Checks if the component is open.

public isOpen(): boolean

  • returns: boolean - true if the component is open and false otherwise.

open

Opens the component.

public open(context: IContext): Promise<void>

  • context: IContext - (optional) a context to trace execution through a call chain.

save

Saves the current counters' measurements.

protected save(counters: Counter[]): Promise<void>

  • counters: Counter[] - current counters' measurements to be saved.

setReferences

Sets references to dependent components.

public setReferences(references: IReferences): void

  • references: IReferences - references to locate the component’s dependencies.

Examples

let counters = new CloudWatchCounters();
counters.config(ConfigParams.fromTuples(
    "connection.region", "us-east-1",
    "connection.access_id", "XXXXXXXXXXX",
    "connection.access_key", "XXXXXXXXXXX"
));
counters.setReferences(References.fromTuples(
    new Descriptor("pip-services", "logger", "console", "default", "1.0"), 
    new ConsoleLogger()
));
  
await counters.open("123");
   
counters.increment("mycomponent.mymethod.calls");
let timing = counters.beginTiming("mycomponent.mymethod.exec_time");
try {
    ...
} finally {
    timing.endTiming();
}
    
counters.dump();

See also