Collecting performance and health data from various places throughout the email platform.
-
STETHOSCOPE_MONGO_URIString[required]Used to set up the connection to the MongoDB instance. See Documentation for examples of this.
-
STETHOSCOPE_EVENT_TTLInteger[optional]The number of seconds the events should be kept for. Default is
86400seconds (24hours).
npm install financial-times/email-stethoscope --save
const stethoscope = require('@financial-times/email-stethoscope');
[...] see below for logger and metric usageNOTE : No functions are rejected, so you can safely avoid having to add a catch block for any functions used. However, as a minimum, we still recommend that you implement unhandledRejection or an empty catch, eg:
await metrics.age.orderedEvents().catch()
Loggers are used to log events into the database, to be retrieved later using the metrics
Events age allows for tagging events when they are started and ended:
loggers.age.startEvent({event!: Any, identifier!: Any, expire?: Integer})description:
- logs the given event as started
args:
event: [required] name of eventidentifier: [required] event identifierexpire: [optional] specifies the TTL of event
returns:
undefined
await stethoscope.loggers.age.startEvent({ event: 'PROCESSING_LIST', identifier: '7da32a14-a9f1-4582-81eb-e4216e0d9a51' });loggers.age.endEvent({event!: Any, identifier!: Any})description:
- logs the given event as ended
args:
event: [required] name of eventidentifier: [required] event identifier
returns:
undefined
await stethoscope.loggers.age.endEvent({ event: 'PROCESSING_LIST', identifier: '7da32a14-a9f1-4582-81eb-e4216e0d9a51' });Metrics are used to interrogate previously logged events from the database for analysis
Events age allows for interrogating the age of previously logged events
metrics.age.eventAge({event!: Any, identifier!: Any})description:
- Get the age of the specific event
args:
event: [required] name of eventidentifier: [required] event identifier
returns:
-
undefinedif event is not foundor
-
Number: the age of the given event in milliseconds
await stethoscope.metrics.age.eventAge({ event: 'PROCESSING_LIST', identifier: '7da32a14-a9f1-4582-81eb-e4216e0d9a51' });metrics.age.eventsAge({event!: Any, operation!: ['average', 'max', 'min']})description:
- Get the average, max and min age of given events (by event category) - useful to identify slow running events
args:
event: [required] name of eventoperation: [required] metric operation. Allowed values areaverage,max,min
returns:
-
undefinedif event is not foundor
-
Number: theaverage,maxorminage of the given event in milliseconds
await stethoscope.metrics.age.eventAge({ event: 'PROCESSING_LIST', operation: 'max' });metrics.age.orderedEvents({limit?: Integer})description:
- Returns age ordered events
args:
limit: [optional] set number of events. All Age Events are returned whenlimitis not supplied
returns:
-
undefinedif no events existor
-
The list of events with age in milliseconds
await stethoscope.metrics.age.orderedEvents({ limit: 1 });- Add more types of events, for example
std- events that were never ended
Made with ❤️ and 🔥 by the email-platform-engineers
