Collects metrics for a Keyv instance over time.
npm install --save @keyvhq/stats
Wrap your keyv instance with @keyvhq/stats
:
const KeyvStats = require('@keyvhq/stats')
const KeyvRedis = require('@keyvhq/redis')
const Keyv = require('@keyvhq/core')
const keyv = KeyvStats(new Keyv({ store: new KeyvRedis() }))
That adds some methods for getting stats over your keyv instance:
await keyv.get('foo')
keyv.stats.info()
// => {
// hit: { value: 0, percent: '0%' },
// miss: { value: 1, percent: '100%' },
// total: 1
// }
await keyv.set('foo', 'bar')
await keyv.get('foo')
await keyv.get('foo')
keyv.stats.info()
// => {
// hit: { value: 2, percent: '67%' },
// miss: { value: 1, percent: '33%' },
// total: 3
// }
keyv.stats.reset()
Type: object
Default: { hit: 0, miss: 0}
The data to set for first time or when .stats.reset()
is called.
Type: number
Default: 1500
Type: string
Default: '__keyv_stats__'
The key used for storing the stats inside the store.
Returns the collected stats for the store in the shape:
{
hit: {
value: number
percent: string
},
miss: {
value: number
percent: string
}
total: number
}
Resets the stats counters.
Peforms a save of the current buffered stats into the store.
@keyvhq/stats © Jytesh, released under the MIT License.
Maintained by Microlink with help from contributors.
microlink.io · GitHub microlinkhq · X @microlinkhq