My node.js application uses prom-client. Once a minute, I save the current metrics to the database as a string. How to install them in the registry back from the string?
async function saveMetricsToDatabase(dbSuite, register) {
try {
const metrics = register.metrics();
const { metricsMapper } = dbSuite;
await metricsMapper.create({ data: metrics }); // save into database
} catch (err) {
console.error( Failed to save metrics to database: , err);
}
}
async function loadMetricsFromDatabase(dbSuite, register) {
try {
const { metricsMapper } = dbSuite;
const result = await metricsMapper.findOne({
order: [[ createdAt , DESC ]],
});
if (result) {
const metrics = result.data;
register.clear();
register.xxx(metrics); // In the metrics variable, the past state of the metrics.
// How to install them in the current registry?
}
} catch (err) {
console.error( Failed to load metrics from database: , err);
}
}
Didn t find the preferred method in the technical documentation. Writing to the database is correct. https://github.com/siimon/prom-client