-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: export SwingSet metrics to Prometheus via local HTTP port
Run: `AG_CHAIN_COSMOS_PROMETHEUS=9464 ag-chain-cosmos start` to export via http://localhost:9464/metrics
- Loading branch information
1 parent
94e0078
commit 78160fe
Showing
5 changed files
with
264 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
// All the kernel metrics we are prepared for. | ||
const KERNEL_STATS_SUM_METRICS = [ | ||
{ | ||
key: 'syscalls', | ||
name: 'syscall_total', | ||
description: 'Total number of SwingSet kernel calls', | ||
}, | ||
{ | ||
key: 'syscallSend', | ||
name: 'syscall_send_total', | ||
description: 'Total number of SwingSet message send kernel calls', | ||
}, | ||
{ | ||
key: 'syscallCallNow', | ||
name: 'syscall_call_now_total', | ||
description: 'Total number of SwingSet synchronous device kernel calls', | ||
}, | ||
{ | ||
key: 'syscallSubscribe', | ||
name: 'syscall_subscribe_total', | ||
description: 'Total number of SwingSet promise subscription kernel calls', | ||
}, | ||
{ | ||
key: 'syscallResolve', | ||
name: 'syscall_resolve_total', | ||
description: 'Total number of SwingSet promise resolution kernel calls', | ||
}, | ||
{ | ||
key: 'dispatches', | ||
name: 'dispatch_total', | ||
description: 'Total number of SwingSet vat calls', | ||
}, | ||
{ | ||
key: 'dispatchDeliver', | ||
name: 'dispatch_deliver_total', | ||
description: 'Total number of SwingSet vat message deliveries', | ||
}, | ||
{ | ||
key: 'dispatchNotify', | ||
name: 'dispatch_notify_total', | ||
description: 'Total number of SwingSet vat promise notifications', | ||
}, | ||
]; | ||
|
||
const KERNEL_STATS_UPDOWN_METRICS = [ | ||
{ | ||
key: 'kernelObjects', | ||
name: 'swingset_kernel_objects', | ||
description: 'Active kernel objects', | ||
}, | ||
{ | ||
key: 'kernelDevices', | ||
name: 'swingset_kernel_devices', | ||
description: 'Active kernel devices', | ||
}, | ||
{ | ||
key: 'kernelPromises', | ||
name: 'swingset_kernel_promises', | ||
description: 'Active kernel promises', | ||
}, | ||
{ | ||
key: 'kpUnresolved', | ||
name: 'swingset_unresolved_kernel_promises', | ||
description: 'Unresolved kernel promises', | ||
}, | ||
{ | ||
key: 'kpFulfilledToPresence', | ||
name: 'swingset_presence_kernel_promises', | ||
description: 'Kernel promises fulfilled to presences', | ||
}, | ||
{ | ||
key: 'kpFulfilledToData', | ||
name: 'swingset_data_kernel_promises', | ||
description: 'Kernel promises fulfilled to data', | ||
}, | ||
{ | ||
key: 'kpRejected', | ||
name: 'swingset_rejected_kernel_promises', | ||
description: 'Rejected kernel promises', | ||
}, | ||
{ | ||
key: 'runQueueLength', | ||
name: 'swingset_run_queue_length', | ||
description: 'Length of the kernel run queue', | ||
}, | ||
{ | ||
key: 'clistEntries', | ||
name: 'clist_entries', | ||
description: 'Number of entries in the kernel c-list', | ||
}, | ||
]; | ||
|
||
/** | ||
* @param {Object} param0 | ||
* @param {any} param0.controller | ||
* @param {import('@opentelemetry/metrics').Meter} param0.metricMeter | ||
* @param {Console} param0.log | ||
*/ | ||
export function exportKernelStats({ controller, metricMeter, log = console }) { | ||
const kernelStatsMetrics = new Map(); | ||
const expectedKernelStats = new Set(); | ||
|
||
KERNEL_STATS_SUM_METRICS.forEach(({ key, name, ...options }) => { | ||
expectedKernelStats.add(key); | ||
kernelStatsMetrics.set(key, metricMeter.createSumObserver(name, options)); | ||
}); | ||
|
||
KERNEL_STATS_UPDOWN_METRICS.forEach(({ key, name, ...options }) => { | ||
expectedKernelStats.add(key); | ||
expectedKernelStats.add(`${key}Up`); | ||
expectedKernelStats.add(`${key}Down`); | ||
expectedKernelStats.add(`${key}Max`); | ||
kernelStatsMetrics.set( | ||
key, | ||
metricMeter.createUpDownSumObserver(name, options), | ||
); | ||
}); | ||
|
||
function warnUnexpectedKernelStat(key) { | ||
if (!expectedKernelStats.has(key)) { | ||
log.warn(`Unexpected SwingSet kernel statistic`, key); | ||
expectedKernelStats.add(key); | ||
} | ||
} | ||
|
||
function checkKernelStats(stats) { | ||
const notYetFoundKernelStats = new Set(kernelStatsMetrics.keys()); | ||
Object.keys(stats).forEach(key => { | ||
notYetFoundKernelStats.delete(key); | ||
warnUnexpectedKernelStat(key); | ||
}); | ||
notYetFoundKernelStats.forEach(key => { | ||
log.warn(`Expected SwingSet kernel statistic`, key, `not found`); | ||
}); | ||
} | ||
|
||
// We check everything on initialization. Other checks happen when scraping. | ||
checkKernelStats(controller.getStats()); | ||
metricMeter.createBatchObserver(batchObserverResult => { | ||
const observations = []; | ||
Object.entries(controller.getStats()).forEach(([key, value]) => { | ||
warnUnexpectedKernelStat(key); | ||
if (kernelStatsMetrics.has(key)) { | ||
const metric = kernelStatsMetrics.get(key); | ||
observations.push(metric.observation(value)); | ||
} | ||
}); | ||
batchObserverResult.observe({ app: 'ag-chain-cosmos' }, observations); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters