Options
All
  • Public
  • Public/Protected
  • All
Menu

Class CloudWatchCounters

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

Configuration parameters

  • connections:
    • discovery_key: (optional) a key to retrieve the connection from IDiscovery
    • region: (optional) AWS region
  • credentials:
    • store_key: (optional) a key to retrieve the credentials from ICredentialStore
    • access_id: AWS access/client id
    • access_key: AWS access/client id
  • 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 counters source
  • *:discovery:*:*:1.0 (optional) IDiscovery services to resolve connections
  • *:credential-store:*:*:1.0 (optional) Credential stores to resolve credentials
see

Counter (in the Pip.Services components package)

see

CachedCounters (in the Pip.Services components package)

see

CompositeLogger (in the Pip.Services components package)

Example

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()
));

counters.open("123", (err) => {
    ...
});

counters.increment("mycomponent.mymethod.calls");
let timing = counters.beginTiming("mycomponent.mymethod.exec_time");
try {
    ...
} finally {
    timing.endTiming();
}

counters.dump();

Hierarchy

  • CachedCounters
    • CloudWatchCounters

Implements

  • ICounters
  • IReconfigurable
  • ITimingCallback
  • IReferenceable
  • IOpenable

Index

Constructors

constructor

Properties

Protected _cache

_cache: object

Type declaration

  • [id: string]: Counter

Protected _interval

_interval: number

Protected _lastDumpTime

_lastDumpTime: number

Protected _lastResetTime

_lastResetTime: number

Protected _resetTimeout

_resetTimeout: number

Protected _updated

_updated: boolean

Methods

CachedCounters

  • CachedCounters(): void
  • Creates a new CachedCounters object.

    Returns void

beginTiming

  • beginTiming(name: string): Timing
  • Creates and starts a new [[Timing]], which will call this object's endTiming method once timing stops.

    see

    [[Timing]]

    Parameters

    • name: string

      the name of the counter to include in the callback.

    Returns Timing

clear

  • clear(name: string): void
  • Removes the [[Counter]] with the given name from this object's cache.

    Parameters

    • name: string

      the name of the counter to remove.

    Returns void

clearAll

  • clearAll(): void
  • Removes all [[Counter Counters]] from this object's cache.

    Returns void

close

  • close(correlationId: string, callback: function): void
  • Closes component and frees used resources.

    Parameters

    • correlationId: string

      (optional) transaction id to trace execution through call chain.

    • callback: function

      callback function that receives error or null no errors occured.

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

configure

  • configure(config: ConfigParams): void
  • Configures component by passing configuration parameters.

    Parameters

    • config: ConfigParams

      configuration parameters to be set.

    Returns void

dump

  • dump(): void
  • Dumps the [[Counter Counters]] that are stored in this object's cache to memory.

    see

    save

    Returns void

endTiming

  • endTiming(name: string, elapsed: number): void
  • Method that is called by a [[Timing Timing]] once timing has ended.

    see

    beginTiming

    Parameters

    • name: string

      the name of the counter that was being timed.

    • elapsed: number

      the time elapsed since timing began.

    Returns void

get

  • get(name: string, type: CounterType): Counter
  • Looks for a [[Counter]] with the given name and type within this object's cache. If none are found, then a new [[Counter]] of the given [[CounterType type]] is created, added to the cache, and returned.

    If the need for cache resetting is detected, calling this method will trigger the reset.

    throws

    an Error if name is null

    Parameters

    • name: string

      the name of the counter to retrieve.

    • type: CounterType

      the counter's type.

    Returns Counter

    the counter found in the cache or the one created (if none were found).

getAll

  • getAll(): Counter[]
  • Retrieves the [[Counter Counters]] that are stored in this object's cache.

    If the need for cache resetting is detected, calling this method will trigger the reset.

    Returns Counter[]

    an array, containing all cached Counters.

getInterval

  • getInterval(): number
  • Returns number

    this CachedCounters' update interval. Used to dump the cache to memory at regular intervals.

increment

  • increment(name: string, value: number): void
  • Increments the named [[CounterType.Increment Incremental Counter]] by the given value.

    see

    [[CounterType]]

    see

    get

    Parameters

    • name: string

      the name of the counter to increment.

    • value: number

      the value to increment the counter by.

    Returns void

incrementOne

  • incrementOne(name: string): void
  • Incrementes the named [[CounterType.Increment Incremental Counter]] by 1.

    see

    [[CounterType]]

    see

    increment

    Parameters

    • name: string

      the name of the counter to increment.

    Returns void

isOpen

  • isOpen(): boolean

last

  • last(name: string, value: number): void
  • Updates the named [[CounterType.LastValue Last Counter]] by setting its last value to the value given.

    see

    [[CounterType]]

    see

    get

    Parameters

    • name: string

      the name of the counter to update.

    • value: number

      the value to update the counter with.

    Returns void

open

  • open(correlationId: string, callback: function): void
  • Opens the component.

    Parameters

    • correlationId: string

      (optional) transaction id to trace execution through call chain.

    • callback: function

      callback function that receives error or null no errors occured.

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

Protected save

  • save(counters: Counter[]): void
  • Saves the current counters measurements.

    Parameters

    • counters: Counter[]

      current counters measurements to be saves.

    Returns void

setInterval

  • setInterval(value: number): void
  • Sets this CachedCounters' update interval, which is used to dump the cache to memory at regular intervals.

    Parameters

    • value: number

      the value to set this CachedCounters' update interval to.

    Returns void

setReferences

  • setReferences(references: IReferences): void
  • Sets references to dependent components.

    see

    IReferences (in the Pip.Services commons package)

    Parameters

    • references: IReferences

      references to locate the component dependencies.

    Returns void

stats

  • stats(name: string, value: number): void
  • Adds the given value to the named [[CounterType.Statistics Statistics Counter]] and recalculates its statistics, taking into account the new value. Statistics include last, count, min, max, and average.

    see

    [[CounterType]]

    see

    get

    Parameters

    • name: string

      the name of the counter to update.

    • value: number

      the value to update the counter with.

    Returns void

timestamp

  • timestamp(name: string, value: Date): void
  • Updates the named [[CounterType.Timestamp Timestamp Counter's]] time to the time given.

    see

    [[CounterType]]

    see

    get

    Parameters

    • name: string

      the name of the counter to update.

    • value: Date

      the timestamp to update the counter to.

    Returns void

timestampNow

  • timestampNow(name: string): void
  • Updates the named [[CounterType.Timestamp Timestamp Counter's]] time to the current time.

    see

    [[CounterType]]

    see

    timestamp

    Parameters

    • name: string

      the name of the counter to update.

    Returns void

Protected update

  • update(): void
  • Checks whether or not the update interval has passed (since the last dump was performed) and, if it has, performs a dump.

    see

    dump

    Returns void

Generated using TypeDoc