danielrataj / sails-hook-prometheus Goto Github PK
View Code? Open in Web Editor NEWProvides Prometheus /metrics endpoint with stats.
License: MIT License
Provides Prometheus /metrics endpoint with stats.
License: MIT License
This is my Counter metrics. As you can see i have multiple in one file.
`
/* global sails */
const LoginAttemptCounter = sails.hooks.prometheus.counter.setup({
name: 'app_login_attempt',
help: 'Track the status of login attempts (success or failed).',
labelNames: ['status', 'code'],
})
const InitiateOnboardingCounter = sails.hooks.prometheus.counter.setup({
name: 'initiate_onboarding',
help: 'Track the status of onboarding initiation.',
labelNames: ['status', 'code', 'step'],
})
const ImageUploadCounter = sails.hooks.prometheus.counter.setup({
name: 'image_upload',
help: 'Track the status of image upload.',
labelNames: ['status', 'code'],
})
const ImageDownloadCounter = sails.hooks.prometheus.counter.setup({
name: 'image_download',
help: 'Track the status of image download.',
labelNames: ['status', 'code'],
})
const FaceVerificationCounter = sails.hooks.prometheus.counter.setup({
name: 'face_verification',
help: 'Track the status of facial verification.',
labelNames: ['status', 'code'],
})
const CompleteOnboardingCounter = sails.hooks.prometheus.counter.setup({
name: 'complete_onboarding',
help: 'Track the status of the complete onboarding step.',
labelNames: ['status', 'code'],
})
module.exports = {
/**
* Track login attempts metrics.
*/
loginAttempts: {
success: (code = 200) =>
LoginAttemptCounter.inc({ amount: 1, labels: { status: 'success', code } }),
failed: (code = 400) =>
LoginAttemptCounter.inc({ amount: 1, labels: { status: 'failed', code } }),
},
/**
* Track initiate-onboarding metrics.
*/
initiateOnboarding: {
success: (code = 200) =>
InitiateOnboardingCounter.inc({ amount: 1, labels: { status: 'success', code } }),
failed: (code = 400, step) =>
InitiateOnboardingCounter.inc({ amount: 1, labels: { status: 'failed', code, step } }),
},
/**
* Track image upload metrics.
*/
imageUpload: {
success: (code = 200) =>
ImageUploadCounter.inc({ amount: 1, labels: { status: 'success', code } }),
failed: (code = 400) =>
ImageUploadCounter.inc({ amount: 1, labels: { status: 'failed', code } }),
},
/**
* Track image download metrics.
*/
imageDownload: {
success: (code = 200) =>
ImageDownloadCounter.inc({ amount: 1, labels: { status: 'success', code } }),
failed: (code = 400) =>
ImageDownloadCounter.inc({ amount: 1, labels: { status: 'failed', code } }),
},
/**
* Track image face verification.
*/
faceVerification: {
success: (code = 200) =>
FaceVerificationCounter.inc({ amount: 1, labels: { status: 'success', code } }),
failed: (code = 400) =>
FaceVerificationCounter.inc({ amount: 1, labels: { status: 'failed', code } }),
},
/**
* Track image download metrics.
*/
completeOnboarding: {
success: (code = 200) =>
CompleteOnboardingCounter.inc({ amount: 1, labels: { status: 'success', code } }),
failed: (code = 400) =>
CompleteOnboardingCounter.inc({ amount: 1, labels: { status: 'failed', code } }),
},
};
`
However, when i run the application only the first counter in this file seems to get registered.
I'd like to collect he response size byte. Could any one guide me configure the right way?
Would be possible to introduce a config parameter to personalize the /metrics
endpoint (i.e. /api/v1/metrics
)?
We would like to use this, but are stuck on this.
TYIA
The HTTP metrics is only showing the request where the status code is 200. Whenever a request failed, the counter for that failed request increases (http_request_duration_seconds_count works fine) but http_request_duration_seconds_sum doesn't show the failed request i.e. status code 4xx
verbose: verbo: Interpreting socket.io message as VR (virtual request) to "put /api/v1/login"...
silly: : Handling virtual request :: Running virtual querystring parser...
silly: : Handling virtual request :: Running virtual body parser...
silly: : Handling virtual request :: Running final "error" handler...
error: error: Sending 500 ("Server Error") response:
TypeError: Cannot read property 'statusCode' of undefined
at all /* (/certifirm/SailsBE_dev/node_modules/sails-hook-prometheus/src/index.js:43:36)
at routeTargetFnWrapper (/certifirm/SailsBE_dev/node_modules/sails/lib/router/bind.js:392:9)
at Layer.handle [as handle_request] (/certifirm/SailsBE_dev/node_modules/router/lib/layer.js:93:5)
at next (/certifirm/SailsBE_dev/node_modules/router/lib/route.js:144:13)
at Route.dispatch (/certifirm/SailsBE_dev/node_modules/router/lib/route.js:109:3)
at handle (/certifirm/SailsBE_dev/node_modules/router/index.js:520:11)
at Layer.handle [as handle_request] (/certifirm/SailsBE_dev/node_modules/router/lib/layer.js:93:5)
at /certifirm/SailsBE_dev/node_modules/router/index.js:296:22
at param (/certifirm/SailsBE_dev/node_modules/router/index.js:373:14)
at param (/certifirm/SailsBE_dev/node_modules/router/index.js:384:14)
at Function.process_params (/certifirm/SailsBE_dev/node_modules/router/index.js:429:3)
at next (/certifirm/SailsBE_dev/node_modules/router/index.js:290:10)
at next (/certifirm/SailsBE_dev/node_modules/router/lib/route.js:124:14)
at logRequest (/certifirm/SailsBE_dev/node_modules/sails-hook-apianalytics/lib/private/log-request.middleware.js:109:10)
at routeTargetFnWrapper (/certifirm/SailsBE_dev/node_modules/sails/lib/router/bind.js:392:9)
at Layer.handle [as handle_request] (/certifirm/SailsBE_dev/node_modules/router/lib/layer.js:93:5)
at next (/certifirm/SailsBE_dev/node_modules/router/lib/route.js:144:13)
at Route.dispatch (/certifirm/SailsBE_dev/node_modules/router/lib/route.js:109:3)
at handle (/certifirm/SailsBE_dev/node_modules/router/index.js:520:11)
at Layer.handle [as handle_request] (/certifirm/SailsBE_dev/node_modules/router/lib/layer.js:93:5)
at /certifirm/SailsBE_dev/node_modules/router/index.js:296:22
at param (/certifirm/SailsBE_dev/node_modules/router/index.js:373:14)
at param (/certifirm/SailsBE_dev/node_modules/router/index.js:384:14)
at Function.process_params (/certifirm/SailsBE_dev/node_modules/router/index.js:429:3)
at next (/certifirm/SailsBE_dev/node_modules/router/index.js:290:10)
at next (/certifirm/SailsBE_dev/node_modules/router/lib/route.js:124:14)
at fn (/certifirm/SailsBE_dev/api/hooks/custom/index.js:173:47)
at routeTargetFnWrapper (/certifirm/SailsBE_dev/node_modules/sails/lib/router/bind.js:375:23)
at /certifirm/SailsBE_dev/node_modules/sails/lib/router/bind.js:455:14
at Layer.handle [as handle_request] (/certifirm/SailsBE_dev/node_modules/router/lib/layer.js:93:5)
at next (/certifirm/SailsBE_dev/node_modules/router/lib/route.js:144:13)
at Route.dispatch (/certifirm/SailsBE_dev/node_modules/router/lib/route.js:109:3)
at handle (/certifirm/SailsBE_dev/node_modules/router/index.js:520:11)
at Layer.handle [as handle_request] (/certifirm/SailsBE_dev/node_modules/router/lib/layer.js:93:5)
When we use method "inc()" without arguments, we got an error:
TypeError: Cannot read property 'amount' of undefined at Object.inc (/Users/drataj/workspace/test-project/node_modules/sails-hook-prometheus/src/index.js:100:14)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.