CloudWatchCounters

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

Inherits: CachedCounters, IOpenable, IReferenceable

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 credential requests

Constructors

Creates a new instance of this class.

public CloudWatchCounters()

Instance methods

Close

Closes component and frees used resources.

public Task CloseAsync(string correlationId)

  • correlationId: string - (optional) transaction id used to trace execution through the call chain.

Configure

Configures a component by passing its configuration parameters.

public override void Configure(ConfigParams config)

  • config: ConfigParams - configuration parameters to be set.

IsOpen

Checks if the component is open.

public bool IsOpen()

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

OpenAsync

Opens the component.

public Task OpenAsync(string correlationId)

  • correlationId: string - (optional) transaction id used to trace execution through the call chain.

Save

Saves the current counters' measurements.

protected override void Save(IEnumerable<Counter> counters)

  • counters: IEnumerable<Counter> - current counters' measurements to be saved.

SetReferences

Sets references to dependent components.

public virtual void SetReferences(IReferences references)

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

Examples

var counters = new CloudWatchCounters();
counters.Configure(ConfigParams.FromTuples(
    "connection.region", "us-east-1",
    "connection.access_id", "XXXXXXXXXXX",
    "connection.access_key", "XXXXXXXXXXX"));

counters.SetReferences(References.fromTuples(
    new Descriptor("pip-services3", "logger", "console", "default", "1.0"), 
    new ConsoleLogger() ));
    counters.Open("123");

counters.Increment("mycomponent.mymethod.calls");
var timing = counters.BeginTiming("mycomponent.mymethod.exec_time");

try {
    ...
} finally {
    timing.EndTiming();
}

counters.Dump();

See also