摘要: 性能問題也是BUG,也須要監控。javascript
Fundebug是專業的應用異常監控平臺,咱們Node.js插件fundebug-nodejs能夠提供全方位的異常監控,支持Express、Koa以及Hapi框架。html
從用戶的角度理解,性能問題某種程度上也是BUG,它多是數據庫的索引問題,多是代碼算法問題,也多是業務邏輯的設計有問題。爲了幫助你們快速定位性能BUG,fundebug-nodejs插件更新至0.2.0,支持監控Express慢請求。java
不過,Fundebug暫時無心於提供全面的性能監控服務,咱們將繼續專一於BUG監控。node
監控Express慢請求,須要配置閾值httpTimeout,而且添加ExpressTimeoutHandler中間件。git
fundebug.httpTimeout = 1000;
app.use(fundebug.ExpressTimeoutHandler());
複製代碼
注意,Fundebug的慢請求監控中間件ExpressTimeoutHandler必須放在其餘中間件以前。github
這樣,全部花費時間超過閾值1000ms的請求都會上報到Fundebug。算法
關於Express如何接入Fundebug異常監控服務,不妨查看咱們的Demo項目fundebug-express-demo。數據庫
const express = require("express");
const app = express();
const port = 5000;
const Promise = require("bluebird");
const fundebug = require("fundebug-nodejs");
fundebug.apikey = "APIKEY";
fundebug.httpTimeout = 1000;
app.use(fundebug.ExpressTimeoutHandler());
app.get("/error", () => {
throw new Error("test");
});
app.get("/timeout", async (req, res) => {
await Promise.delay(1500);
res.sendStatus(200);
});
app.use(function(err, req, res, next) {
res.status(500);
next(err);
});
app.use(fundebug.ExpressErrorHandler);
app.listen(port, () => console.log(`Example app listening on port ${port}!`));
複製代碼
其中,ExpressTimeoutHandler必須放在其餘中間件以前,而ExpressErrorHandler必須放在其餘中間件以後。express
Fundebug所捕獲的超時請求以下:npm
Fundebug專一於JavaScript、微信小程序、微信小遊戲、支付寶小程序、React Native、Node.js和Java線上應用實時BUG監控。 自從2016年雙十一正式上線,Fundebug累計處理了10億+錯誤事件,付費客戶有陽光保險、核桃編程、荔枝FM、掌門1對一、微脈、青團社等衆多知名企業。歡迎你們免費試用!
轉載時請註明做者Fundebug以及本文地址: blog.fundebug.com/2019/07/30/…