PrometheusCounters

Performance counters that send their metrics to Prometheus service.

Extends: CachedCounters

Implements: IReferenceable, IOpenable

Description

The PrometheusCounters class allows you to create performance counters that send their metrics to Pormetheus service.

Important points

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

Configuration parameters

connection(s):

  • discovery_key: (optional) 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
  • *:discovery:*:*:1.0 - (optional) IDiscovery services
  • *:counters:*:*:1.0 - (optional) ICounters components to pass collected measurements

Constructors

Creates a new instance of the performance counters.

public constructor()

Instance methods

close

Closes the component and frees used resources.

public close(context: IContext)

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

configure

Configures the component by passing its configuration parameters.

public configure(config: ConfigParams): void

  • config: ConfigParams - configuration parameters to be set.

isOpen

Checks if the component is opened.

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[]): 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 dependencies.

Examples

let counters = new PrometheusCounters();
counters.configure(ConfigParams.fromTuples(
    "connection.protocol", "http",
    "connection.host", "localhost",
    "connection.port", 8080
));
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