Counter
public class Counter
extension Counter: CustomStringConvertible
A counter is a cumulative metric that represents a single monotonically increasing counter whose value can only increase or be reset to zero. For example, you can use a counter to represent the number of requests served, tasks completed, or errors.
This is the user-facing Counter API.
Its behavior depends on the CounterHandler
implementation.
-
Undocumented
Declaration
Swift
public let label: String
-
Undocumented
Declaration
Swift
public let dimensions: [(String, String)]
-
Alternative way to create a new
Counter
, while providing an explicitCounterHandler
.Warning
This initializer provides an escape hatch for situations where one must use a custom factory instead of the global one. We do not expect this API to be used in normal circumstances, so if you find yourself using it make sure it’s for a good reason.
See also
Use
init(label:dimensions:)
to createCounter
instances using the configured metrics backend.Declaration
Swift
public init(label: String, dimensions: [(String, String)], handler: CounterHandler)
Parameters
label
The label for the
Counter
.dimensions
The dimensions for the
Counter
.handler
The custom backend.
-
Increment the counter.
Declaration
Swift
@inlinable public func increment<DataType>(by amount: DataType) where DataType : BinaryInteger
Parameters
by
Amount to increment by.
-
Increment the counter by one.
Declaration
Swift
@inlinable public func increment()
-
Reset the counter back to zero.
Declaration
Swift
@inlinable public func reset()
-
Create a new
Counter
.Declaration
Swift
public convenience init(label: String, dimensions: [(String, String)] = [])
Parameters
label
The label for the
Counter
.dimensions
The dimensions for the
Counter
. -
Signal the underlying metrics library that this counter will never be updated again. In response the library MAY decide to eagerly release any resources held by this
Counter
.Declaration
Swift
@inlinable public func destroy()
-
Declaration
Swift
public var description: String { get }