簡體   English   中英

使用Prometheus監視Node.js axios請求

[英]Monitoring node.js axios requests with prometheus

我有node.js微服務,帶有對外部api的axios請求,我需要使用prometheus監視它們。 如我所見,普羅米修斯被用來監視明確的請求:

app.use((req, res, next) => {
  const responseTimeInMs = Date.now() - res.locals.startEpoch;

  httpRequestDurationMs
      .labels(req.method, req.route.path, res.statusCode)
      .observe(responseTimeInMs);

  next();
});

但是我發現無法與axios一起使用它(例如):

function getData() {
  return axios.get(url)
    .then (res) => {
      [should put metrics somewhere here]
    }
}

希望有人可以幫助您。

舞會客戶端文檔-您可以啟動計時器並在完成時調用return方法:

const end = gauge.startTimer();
xhrRequest(function(err, res) {
  end(); // Sets value to xhrRequests duration in seconds
});

與量規,直方圖,摘要或任何其他對象一起使用...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM