Options
All
  • Public
  • Public/Protected
  • All
Menu

Class PrometheusCounters

Performance counters that send their metrics to Prometheus service.

The component is normally used in passive mode conjunction with PrometheusMetricsService. Alternatively when connection parameters are set it can push metrics to Prometheus PushGateway.

Configuration parameters

  • connection(s):
    • discovery_key: (optional) a key to retrieve the connection from IDiscovery
    • protocol: connection protocol: http or https
    • host: host name or IP address
    • port: port number
    • uri: resource URI or connection string with all parameters in it
  • options:
    • retries: number of retries (default: 3)
    • connect_timeout: connection timeout in milliseconds (default: 10 sec)
    • timeout: invocation timeout in milliseconds (default: 10 sec)

References

  • *:logger:*:*:1.0 (optional) ILogger components to pass log messages
  • *:counters:*:*:1.0 (optional) ICounters components to pass collected measurements
  • *:discovery:*:*:1.0 (optional) IDiscovery services to resolve connection
see

RestService

see

CommandableHttpService

Example

let counters = new PrometheusCounters();
counters.configure(ConfigParams.fromTuples(
    "connection.protocol", "http",
    "connection.host", "localhost",
    "connection.port", 8080
));

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
    • PrometheusCounters

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.

    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