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 a Prometheus controller.

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.

PrometheusCounters()

Instance methods

close

Closes the component and frees used resources.

@override

Future close(IContext? context)

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

configure

Configures the component by passing its configuration parameters.

@override

void configure(ConfigParams config)

  • config: ConfigParams - configuration parameters to be set.

isOpen

Checks if the component is opened.

@override

bool isOpen()

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

open

Opens the component.

@override

Future open(IContext? context)

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

save

Saves the current counters' measurements.

@override

Future save(List<Counter> counters)

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

setReferences

Sets references to dependent components.

@override

void setReferences(IReferences references)

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

Examples

var counters =  PrometheusCounters();
counters.configure(ConfigParams.fromTuples([
    'connection.protocol', 'http',
    'connection.host', 'localhost',
    'connection.port', 8080
]));

await counters.open('123')
    ...
counters.increment('mycomponent.mymethod.calls');
var counter_timing = counters.beginTiming('mycomponent.mymethod.exec_time');

try {
    ...
} finally {
    counter_timing.endTiming();
}

counters.dump();

See also