Added metric-shipping to monitor boot-time

no issue
Boot-time metrics are really valuable for understanding how releases affect the performance of Ghost. The new @tryghost/metrics package lets us ship these metrics to different sources using the same configuration framework as @tryghost/logging introduced.
This commit is contained in:
Sam Lord 2021-10-12 14:29:10 +01:00
parent af7fe99127
commit a535cfdf16
4 changed files with 35 additions and 2 deletions

View File

@ -16,14 +16,19 @@ const debug = require('@tryghost/debug')('boot');
* Helper class to create consistent log messages
*/
class BootLogger {
constructor(logging, startTime) {
constructor(logging, metrics, startTime) {
this.logging = logging;
this.metrics = metrics;
this.startTime = startTime;
}
log(message) {
let {logging, startTime} = this;
logging.info(`Ghost ${message} in ${(Date.now() - startTime) / 1000}s`);
}
metric(name) {
let {metrics, startTime} = this;
metrics.metric(name, Date.now() - startTime);
}
}
/**
@ -289,6 +294,7 @@ async function bootGhost() {
let config;
let ghostServer;
let logging;
let metrics;
// These require their own try-catch block and error format, because we can't log an error if logging isn't working
try {
@ -301,7 +307,8 @@ async function bootGhost() {
// Logging is used absolutely everywhere
debug('Begin: Load logging');
logging = require('@tryghost/logging');
bootLogger = new BootLogger(logging, startTime);
metrics = require('@tryghost/metrics');
bootLogger = new BootLogger(logging, metrics, startTime);
debug('End: Load logging');
// At this point logging is required, so we can handle errors better
@ -362,6 +369,7 @@ async function bootGhost() {
// Step 6 - We are technically done here - let everyone know!
bootLogger.log('booted');
bootLogger.metric('boot-time');
notifyServerReady();
// Step 7 - Init our background services, we don't wait for this to finish

View File

@ -8,6 +8,14 @@ module.exports = {
mode: config.get('logging:mode'),
level: config.get('logging:level'),
transports: config.get('logging:transports'),
metrics: {
transports: config.get('logging:metrics:transports'),
metadata: {
// Undefined if unavailable
siteId: config.get('hostSettings:siteId'),
domain: config.get('url')
}
},
gelf: config.get('logging:gelf'),
loggly: config.get('logging:loggly'),
elasticsearch: config.get('logging:elasticsearch'),

View File

@ -84,6 +84,7 @@
"@tryghost/members-importer": "0.3.3",
"@tryghost/members-offers": "0.4.2",
"@tryghost/members-ssr": "1.0.14",
"@tryghost/metrics": "0.2.0",
"@tryghost/mw-session-from-token": "0.1.25",
"@tryghost/nodemailer": "0.3.3",
"@tryghost/package-json": "1.0.5",

View File

@ -1563,6 +1563,13 @@
leaky-bucket "^2.2.0"
stripe "^8.174.0"
"@tryghost/metrics@0.2.0":
version "0.2.0"
resolved "https://registry.yarnpkg.com/@tryghost/metrics/-/metrics-0.2.0.tgz#e44ddea0ffc6b4092a7dd83f12911f4e3d00812c"
integrity sha512-pym7A2BDjVCNj6LPlxPg5qPXbrZNSamXWqTF5PxeUSUhF6kZpYkxSVU1L3ADkQlG1UqYsJQuO4FrEf0DBuntJg==
dependencies:
"@tryghost/pretty-stream" "^0.1.1"
"@tryghost/mobiledoc-kit@^0.12.4-ghost.1":
version "0.12.4-ghost.1"
resolved "https://registry.yarnpkg.com/@tryghost/mobiledoc-kit/-/mobiledoc-kit-0.12.4-ghost.1.tgz#32060242b4c7e787a9605ba856454c6a26141925"
@ -1606,6 +1613,15 @@
chalk "^4.1.0"
sywac "^1.3.0"
"@tryghost/pretty-stream@^0.1.1":
version "0.1.1"
resolved "https://registry.yarnpkg.com/@tryghost/pretty-stream/-/pretty-stream-0.1.1.tgz#8be18694f3081424c0efb832fa32469d5891356b"
integrity sha512-+FYAVozEmYctaVI+4xEhRnpep0xSnGL7FiT91dffxTLx2QVQxI1qADD9Dfb9EzIYIDRttUKoZJ4xzrVpnzD0WQ==
dependencies:
lodash "^4.17.21"
moment "^2.29.1"
prettyjson "^1.2.1"
"@tryghost/promise@0.1.12":
version "0.1.12"
resolved "https://registry.yarnpkg.com/@tryghost/promise/-/promise-0.1.12.tgz#05fc3acba1c74a02255c11fcee5383e291d6f25f"