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

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

CachedCounters

  • CachedCounters(): void

LogCounters

  • LogCounters(): void

beginTiming

  • beginTiming(name: string): Timing

clear

  • clear(name: string): void

clearAll

  • clearAll(): void

configure

  • configure(config: ConfigParams): void

dump

  • dump(): 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

getInterval

  • getInterval(): number

increment

  • increment(name: string, value: number): 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

setInterval

  • setInterval(value: number): 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

timestampNow

  • timestampNow(name: string): void

Protected update

  • update(): void

Generated using TypeDoc