diff --git a/src/driver/freenas/http/index.js b/src/driver/freenas/http/index.js index 4d2009c..bb2a1b8 100644 --- a/src/driver/freenas/http/index.js +++ b/src/driver/freenas/http/index.js @@ -131,15 +131,18 @@ class Client { delete options.httpAgent; 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 STATUS: " + _.get(response, "statusCode", "") + "FREENAS HTTP RESPONSE STATUS CODE: " + _.get(response, "statusCode", "") ); 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) { diff --git a/src/utils/general.js b/src/utils/general.js index ea79423..fc0987f 100644 --- a/src/utils/general.js +++ b/src/utils/general.js @@ -2,7 +2,32 @@ const _ = require("lodash"); const axios = require("axios"); const crypto = require("crypto"); 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) { return new Promise((resolve) => {