Inherits: CachedCounters, 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 PrometheusMetricsService. 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
CloseAsync
Closes the 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 the 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 opened.
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 PrometheusCounters();
counters.Configure(ConfigParams.FromTuples(
"connection.protocol", "http",
"connection.host", "localhost",
"connection.port", 8080 ));
counters.Open("123");
counters.Increment("mycomponent.mymethod.calls");
var timing = counters.BeginTiming("mycomponent.mymethod.exec_time");
try {
...
} finally {
timing.endTiming();
}
counters.dump();