@keyvhq/stats
v2.1.5
Published
Collects metrics for a Keyv instance over time.
Downloads
19
Readme
@keyvhq/stats
Collects metrics for a Keyv instance over time.
Install
npm install --save @keyvhq/stats
Usage
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()
API
stats([options])
options
initialData
Type: object
Default: { hit: 0, miss: 0}
The data to set for first time or when .stats.reset()
is called.
interval
Type: number
Default: 1500
key
Type: string
Default: '__keyv_stats__'
The key used for storing the stats inside the store.
.stats.info()
Returns the collected stats for the store in the shape:
{
hit: {
value: number
percent: string
},
miss: {
value: number
percent: string
}
total: number
}
.stats.reset()
Resets the stats counters.
.stats.save()
Peforms a save of the current buffered stats into the store.
License
@keyvhq/stats © Jytesh, released under the MIT License. Maintained by Microlink with help from contributors.
microlink.io · GitHub microlinkhq · X @microlinkhq