Options
All
  • Public
  • Public/Protected
  • All
Menu

Class LogCounters

Performance counters that periodically dumps counters measurements to logger.

Configuration parameters

  • options:
    • interval: interval in milliseconds to save current counters measurements (default: 5 mins)
    • reset_timeout: timeout in milliseconds to reset the counters. 0 disables the reset (default: 0)

References

  • *:logger:*:*:1.0 ILogger components to dump the captured counters
  • *:context-info:*:*:1.0 (optional) ContextInfo to detect the context id and specify counters source
see

Counter

see

CachedCounters

see

CompositeLogger

Example

let counters = new LogCounters();
counters.setReferences(References.fromTuples(
    new Descriptor("pip-services", "logger", "console", "default", "1.0"), new ConsoleLogger()
));

counters.increment("mycomponent.mymethod.calls");
let timing = counters.beginTiming("mycomponent.mymethod.exec_time");
try {
    ...
} finally {
    timing.endTiming();
}

counters.dump();

Hierarchy

Implements

Index

Constructors

constructor

Properties

Protected _cache

_cache: object

Type declaration

Protected _interval

_interval: number = 300000

Protected _lastDumpTime

_lastDumpTime: number = new Date().getTime()

Protected _lastResetTime

_lastResetTime: number = new Date().getTime()

Protected _resetTimeout

_resetTimeout: number = 0

Protected _updated

_updated: boolean

Methods

beginTiming

clear

  • clear(name: string): void
  • Clears (resets) a counter specified by its name.

    Parameters

    • name: string

      a counter name to clear.

    Returns void

clearAll

  • clearAll(): void
  • Clears (resets) all counters.

    Returns void

configure

  • configure(config: ConfigParams): void
  • Configures component by passing configuration parameters.

    Parameters

    • config: ConfigParams

      configuration parameters to be set.

    Returns void

dump

  • dump(): void
  • Dumps (saves) the current values of counters.

    see

    save

    Returns void

endTiming

  • endTiming(name: string, elapsed: number): void

get

  • Gets a counter specified by its name. It counter does not exist or its type doesn't match the specified type it creates a new one.

    Parameters

    • name: string

      a counter name to retrieve.

    • type: CounterType

      a counter type.

    Returns Counter

    an existing or newly created counter of the specified type.

getAll

  • Gets all captured counters.

    Returns Counter[]

    a list with counters.

getInterval

  • getInterval(): number
  • Gets the counters dump/save interval.

    Returns number

    the interval in milliseconds.

increment

  • increment(name: string, value: number): void
  • Increments counter by given value.

    Parameters

    • name: string

      a counter name of Increment type.

    • value: number

      a value to add to the counter.

    Returns void

incrementOne

  • incrementOne(name: string): void

last

  • last(name: string, value: number): void
  • Records the last calculated measurement value.

    Usually this method is used by metrics calculated externally.

    Parameters

    • name: string

      a counter name of Last type.

    • value: number

      a last value to record.

    Returns void

Protected save

  • Saves the current counters measurements.

    Parameters

    • counters: Counter[]

      current counters measurements to be saves.

    Returns void

setInterval

  • setInterval(value: number): void
  • Sets the counters dump/save interval.

    Parameters

    • value: number

      a new interval in milliseconds.

    Returns void

setReferences

  • setReferences(references: IReferences): void
  • Sets references to dependent components.

    Parameters

    • references: IReferences

      references to locate the component dependencies.

    Returns void

stats

  • stats(name: string, value: number): void
  • Calculates min/average/max statistics based on the current and previous values.

    Parameters

    • name: string

      a counter name of Statistics type

    • value: number

      a value to update statistics

    Returns void

timestamp

  • timestamp(name: string, value: Date): void
  • Records the given timestamp.

    Parameters

    • name: string

      a counter name of Timestamp type.

    • value: Date

      a timestamp to record.

    Returns void

timestampNow

  • timestampNow(name: string): void
  • Records the current time as a timestamp.

    Parameters

    • name: string

      a counter name of Timestamp type.

    Returns void

Protected update

  • update(): void
  • Makes counter measurements as updated and dumps them when timeout expires.

    see

    dump

    Returns void

Generated using TypeDoc