English 中文(简体)
如何在方便客户登记处强制确定以前节省的衡量标准?
原标题:How to forcefully set the previously saved state of metrics in the prom-client registry?

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

问题回答

暂无回答




相关问题
Prometheus Java client manually exposing prometheus end point

I have a spring boot application where for certain legacy reasons I cannot use spring actuator. I was able to expose a prometheus end point and see a lot of default metrics. But I am not able to see ...

Grafana interval variable: minimum threshold function?

I m adding an interval variable to a dashboard to allow averaging some prometheus time series over an interval to get cleaner looking graphs. But I want to leave in the base sample rate (15s) so the ...

How to specify time range in {aggregate}_over_time?

I have a Grafana chart that makes use of the sum_over_time(data_source[$__interval]) and count_over_time(data_source[$__interval]) command in Prometheus. Normally, it is working fine. But, the ...

how to regex path in prometheus relabel_configs

i have a metric and label like this: namedprocess_namegroup_num_procs{groupname:"/data/home/user01/app.service.1/service"}, i want to get the last field: service, and the number in last but ...

Omit labels from series results PromQL

Suppose I write a basic PromQL query like this Query: kube_deployment_spec_replicas{} Result: kube_deployment_spec_replicas{deployment="mydeployment",endpoint="myendpoint",instance="myinstance",...

Last known timestamp of a metric sample?

How do I get the timestamp of the last known sample of a metric? I want to display a table that lists when was the last time a specific service was running before it disappeared (died or whatever). ...

热门标签