Class: Counter

This represents the metric type - counter, that can be only increased by an integer number.

Constructor

This instantiates the Counter object. Name field is mandatory, and description and tags fields are optional and have its own default values when no params are passed.

init (string name, string? desc, map<string>? tags)
  • name string
  • Name of the Counter instance

  • desc string? ""
  • Description of the Counter instance. If no description is provided, the the default empty string will be used

  • tags map<string>? ()
  • The key/value pair of Tags. If no tags are provided, the default nil value will be used

Methods

register

Register the counter metric instance with the Metric Registry.

unregister

Unregister the counter metric instance with the Metric Registry.

increment

Increment the counter's value by an amount.

reset

Resets the counter's value to zero.

getValue

Retrieves the counter's current value.

Fields

  • name string
  • Name of the counter metric

  • description string
  • Description of the counter metric

  • metricTags map<string>
  • Tags associated with the counter metric

register

function register() returns error?

Register the counter metric instance with the Metric Registry.

Return Type

(error?)

Returns error if there is any metric registered already with the same name but different parameters or in a different kind

unregister

function unregister()

Unregister the counter metric instance with the Metric Registry.

increment

function increment(int amount)

Increment the counter's value by an amount.

Parameters

  • amount int (default 1)
  • The amount by which the value needs to be increased. The amount is defaulted as 1 and will be used if there is no amount passed in

reset

function reset()

Resets the counter's value to zero.

getValue

function getValue() returns int

Retrieves the counter's current value.

Return Type

(int)

The current value of the counter