log truenas request duration
Signed-off-by: Travis Glenn Hansen <travisghansen@yahoo.com>
This commit is contained in:
parent
f27a359f7c
commit
339e952d1c
|
|
@ -131,15 +131,18 @@ class Client {
|
||||||
delete options.httpAgent;
|
delete options.httpAgent;
|
||||||
delete options.httpsAgent;
|
delete options.httpsAgent;
|
||||||
|
|
||||||
this.logger.debug("FREENAS HTTP REQUEST: " + stringify(options));
|
let duration = parseFloat((Math.round((_.get(response, 'duration', 0) + Number.EPSILON) * 100) / 100) / 1000).toFixed(2);
|
||||||
|
|
||||||
|
this.logger.debug("FREENAS HTTP REQUEST DETAILS: " + stringify(options));
|
||||||
|
this.logger.debug("FREENAS HTTP REQUEST DURATION: " + duration + "s");
|
||||||
this.logger.debug("FREENAS HTTP ERROR: " + error);
|
this.logger.debug("FREENAS HTTP ERROR: " + error);
|
||||||
this.logger.debug(
|
this.logger.debug(
|
||||||
"FREENAS HTTP STATUS: " + _.get(response, "statusCode", "")
|
"FREENAS HTTP RESPONSE STATUS CODE: " + _.get(response, "statusCode", "")
|
||||||
);
|
);
|
||||||
this.logger.debug(
|
this.logger.debug(
|
||||||
"FREENAS HTTP HEADERS: " + stringify(_.get(response, "headers", ""))
|
"FREENAS HTTP RESPONSE HEADERS: " + stringify(_.get(response, "headers", ""))
|
||||||
);
|
);
|
||||||
this.logger.debug("FREENAS HTTP BODY: " + stringify(body));
|
this.logger.debug("FREENAS HTTP RESPONSE BODY: " + stringify(body));
|
||||||
}
|
}
|
||||||
|
|
||||||
async get(endpoint, data) {
|
async get(endpoint, data) {
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,32 @@ const _ = require("lodash");
|
||||||
const axios = require("axios");
|
const axios = require("axios");
|
||||||
const crypto = require("crypto");
|
const crypto = require("crypto");
|
||||||
const dns = require("dns");
|
const dns = require("dns");
|
||||||
const crc = require('crc');
|
const crc = require("crc");
|
||||||
|
|
||||||
|
axios.interceptors.request.use(
|
||||||
|
function (config) {
|
||||||
|
config.metadata = { startTime: new Date() };
|
||||||
|
return config;
|
||||||
|
},
|
||||||
|
function (error) {
|
||||||
|
return Promise.reject(error);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
axios.interceptors.response.use(
|
||||||
|
function (response) {
|
||||||
|
response.config.metadata.endTime = new Date();
|
||||||
|
response.duration =
|
||||||
|
response.config.metadata.endTime - response.config.metadata.startTime;
|
||||||
|
return response;
|
||||||
|
},
|
||||||
|
function (error) {
|
||||||
|
error.config.metadata.endTime = new Date();
|
||||||
|
error.duration =
|
||||||
|
error.config.metadata.endTime - error.config.metadata.startTime;
|
||||||
|
return Promise.reject(error);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
function sleep(ms) {
|
function sleep(ms) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue