@actyx/sdk
Version:
Actyx SDK
124 lines (123 loc) • 4.06 kB
TypeScript
import * as t from 'io-ts';
import { Observable } from '../../node_modules/rxjs';
declare type Duration = number;
declare type Integer = number;
declare type Timestamp = number;
declare const Timestamp: {
now: () => number;
};
export declare const CounterMap: t.ReadonlyC<t.RecordC<t.StringC, t.TupleC<[t.NumberC, t.NumberC]>>>;
export declare type CounterMap = t.TypeOf<typeof CounterMap>;
export declare const DurationMap: t.ReadonlyC<t.RecordC<t.StringC, t.UnionC<[t.ReadonlyC<t.TypeC<{
count: t.NumberC;
min: t.NumberC;
max: t.NumberC;
median: t.NumberC;
_90: t.NumberC;
_95: t.NumberC;
_99: t.NumberC;
pending: t.NumberC;
discarded: t.NumberC;
}>>, t.ReadonlyC<t.TypeC<{
pending: t.NumberC;
discarded: t.NumberC;
}>>]>>>;
export declare type DurationMap = t.TypeOf<typeof DurationMap>;
export declare const GaugeMap: t.ReadonlyC<t.RecordC<t.StringC, t.TypeC<{
last: t.NumberC;
max: t.NumberC;
}>>>;
export declare type GaugeMap = t.TypeOf<typeof GaugeMap>;
/**
* Methods to work with simple and rather cheap invocation counters
*/
export declare type Counters = {
/**
* Increment a named counter value. Default increment is one.
*/
add: (name: string, count?: Integer) => void;
/**
* Get all current counter values. Returns an immutable copy.
*/
current: () => CounterMap;
};
/**
* Methods to work with duration statistics
*/
export declare type Durations = {
/**
* Start a long-running operation for a metric name. The operation will be
* ongoing until `end()` is called!
*/
start: (name: string, at: Timestamp) => void;
/**
* End a long-running operation for a metric name. This call only makes sense
* in conjunction with a preceding start.
*
* The from parameter must be the timestamp at which the operation was started,
* to allow the operation to be properly ended.
*
* See profileSync and profileObservable for a more convenient way to use these methods
*/
end: (name: string, from: Timestamp, to: Timestamp) => void;
/**
* Add a duration to a named duration statistic.
* The duration should be positive, but this is not enforced
*/
add: (name: string, duration: Duration) => void;
/**
* Get all current duration statistics. Returns an immutable copy.
*/
getAndClear: () => DurationMap;
};
/**
* Convenience methods for profiling synchronous and asynchronous operations
*/
export declare type ProfileMethods = {
/**
* Profile a synchronous block of code. Will add the duration it took to execute
* the block to the statistics, regardless of whether the block terminates normally
* or with an exception.
*/
profileSync: <T>(name: string) => (block: () => T) => T;
/**
* Profile an observable. Will measure the time between the materialisation of the
* observable and the first element, and then the time between elements, up to a
* configurable number of elements.
*
* The default is to track until the first element arrives or the observable completes
* with a completion or an error. To track indefinitely, pass Number.MAX_SAFE_INTEGER.
*
* This is meant to be used with the rxjs pipe operator.
*/
profileObservable: <T>(name: string, n?: Integer) => (inner: Observable<T>) => Observable<T>;
};
/**
* Methods to work with simple gauges
*/
export declare type Gauges = {
/**
* Set a gauge value.
*/
set: (name: string, value: Integer) => void;
/**
* Get all current gauge values. Returns an immutable copy.
*/
current: () => GaugeMap;
};
export interface RunStats {
readonly counters: Counters;
readonly durations: Durations;
readonly profile: ProfileMethods;
readonly gauges: Gauges;
}
export declare const RunStats: {
create: () => RunStats;
};
/**
* Global statistics singleton.
*
* In the same file to avoid circular dependency issues.
*/
export declare const runStats: RunStats;
export {};