Log reqs based on package as well

This commit is contained in:
Michael Jackson 2016-04-12 05:20:22 -07:00
parent 5435b3c788
commit dd04ece3d0
1 changed files with 9 additions and 2 deletions

View File

@ -17,8 +17,15 @@ const requestLogging = (redisURL) => {
onFinished(res, () => {
const path = req.path
if (res.statusCode === 200 && path.charAt(path.length - 1) !== '/')
redisClient.zincrby([ 'requests', 1, req.path ])
if (res.statusCode === 200 && path.charAt(path.length - 1) !== '/') {
redisClient.zincrby([ 'requests', 1, path ])
const packageSpec = path.split('/')[1]
const atIndex = packageSpec.lastIndexOf('@')
const packageName = packageSpec.substring(0, atIndex)
redisClient.zincrby([ 'package-requests', 1, packageName ])
}
})
next()