Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions api/v1/controllers/onetimetokens.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import * as Const from '../../../lib/const.mjs'
import * as JV from '../../../lib/jsonvalidator.mjs'
import * as Items from '../../../model/item.mjs'
import * as KMS from '../../../lib/kms/kms.mjs'
import * as Metrics from '../../../lib/metrics.mjs'

import jsonwebtoken from 'jsonwebtoken'

Expand Down Expand Up @@ -111,6 +112,9 @@ export async function get (req, res, next) {
Events.add(req.user, Const.EV_ACTION_READ, Const.EV_ENTITY_ONETIMESHARE, ottoken.id)
Events.add(req.user, Const.EV_ACTION_READVIATOKEN, Const.EV_ENTITY_ITEM, ottoken.itemid)
}

// Update metrics
Metrics.counterInc(Const.METRICS_ONETIMETOKENS_READ)
res.send(R.ok(resp))
}

Expand Down Expand Up @@ -192,5 +196,8 @@ export async function create (req, res, next) {
Events.add(req.user, Const.EV_ACTION_CREATE, Const.EV_ENTITY_ONETIMESHARE, created.id)
Events.add(req.user, Const.EV_ACTION_ITEMSHARE, Const.EV_ENTITY_ITEM, req.body.itemid)
}

// Update metrics
Metrics.counterInc(Const.METRICS_ONETIMETOKENS_CREATED)
res.status(R.CREATED).send(R.ok({ token: newToken }))
}
2 changes: 2 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,9 @@ If enabled in configuration, PassWeaver API export various metrics (along defaul
- Users logins count (`login_users_total`)
- API keys logins count (`login_apikeys_total`)
- Item create, update, delete and read count (`items_created_total`, `items_updated_total`, `items_deleted_total`, `items_read_total`)
- One time tokens count (`onetimetokens_created_total`, `onetimetokens_read_total`)
- KMS encryptions and decryptions count (`kms_encryptions_total`, `kms_decryptions_total`)
- KMS encryptions and descriptions for each KMS

## Cache

Expand Down
2 changes: 2 additions & 0 deletions lib/const.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ export const METRICS_ITEMS_READ = 'items_read_total'
export const METRICS_ITEMS_CREATED = 'items_created_total'
export const METRICS_ITEMS_UPDATED = 'items_updated_total'
export const METRICS_ITEMS_DELETED = 'items_deleted_total'
export const METRICS_ONETIMETOKENS_CREATED = 'onetimetokens_created_total'
export const METRICS_ONETIMETOKENS_READ = 'onetimetokens_read_total'
export const METRICS_KMS_ENCRYPTIONS = 'kms_encryptions_total'
export const METRICS_KMS_DECRYPTIONS = 'kms_decryptions_total'
export const METRICS_KMS_ENCRYPTIONS_PER_KMS = 'kms_encryptions_per_kms_total'
Expand Down
2 changes: 2 additions & 0 deletions passweaver-api.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ if (cfg?.enable_metrics) {
Metrics.createCounter(Const.METRICS_ITEMS_DELETED, 'Deleted items')
Metrics.createCounter(Const.METRICS_ITEMS_UPDATED, 'Updated items')
Metrics.createCounter(Const.METRICS_ITEMS_READ, 'Read items')
Metrics.createCounter(Const.METRICS_ONETIMETOKENS_CREATED, 'One time tokens created')
Metrics.createCounter(Const.METRICS_ONETIMETOKENS_READ, 'One time tokens read')
Metrics.createCounter(Const.METRICS_KMS_ENCRYPTIONS, 'Encryptions')
Metrics.createCounter(Const.METRICS_KMS_DECRYPTIONS, 'Decryptions')
Metrics.createCounter(Const.METRICS_KMS_ENCRYPTIONS_PER_KMS, 'Encryptions per KMS', 'kms_description')
Expand Down
13 changes: 12 additions & 1 deletion test/metrics.spec.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,18 @@ describe('Metrics', function () {
.catch(v => v)

assert.strictEqual(res1.status, 200)
// Check that the new per-KMS metrics are included in the output

// Check that all metrics are present
assert.match(res1.text, /login_users_total/)
assert.match(res1.text, /login_apikeys_total/)
assert.match(res1.text, /items_read_total/)
assert.match(res1.text, /items_created_total/)
assert.match(res1.text, /items_updated_total/)
assert.match(res1.text, /items_deleted_total/)
assert.match(res1.text, /onetimetokens_created_total/)
assert.match(res1.text, /onetimetokens_read_total/)
assert.match(res1.text, /kms_encryptions_total/)
assert.match(res1.text, /kms_decryptions_total/)
assert.match(res1.text, /kms_encryptions_per_kms_total/)
assert.match(res1.text, /kms_decryptions_per_kms_total/)
})
Expand Down