Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

response-dashboard

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

response-dashboard - npm Package Compare versions

Comparing version 1.0.14 to 1.0.15

.jsdocrc

62

dashboard.js

@@ -0,1 +1,5 @@

/**
* main script to build the UI
* @module dashboard
*/
/* jslint browser: true, devel: true, node: true */

@@ -15,2 +19,5 @@ /* global $, Gauge, d3 */

/**
* setup - self-invoking function
*/
$(function setup() {

@@ -24,3 +31,3 @@ $.get({

setupDash(measurements)
requestInterval(checkmeasurements, interval, measurements)
requestInterval(checkMeasurements, interval, measurements)
}

@@ -31,2 +38,7 @@ }

/**
* setupDash
*
* @param {object} measurements - metric for adding to the dashboard
*/
const setupDash = (measurements) => {

@@ -68,4 +80,17 @@ measurements.forEach((i, v) => {

/**
* get the measurements for each service
*
* @param {object} measurements - details of the service to measure
*/
const checkMeasurements = (measurements) => {
measurements.forEach((currentServer) => pingServer(currentServer))
}
/**
* measure the server response
*
* @param {object} server - details for measurement
*/
const pingServer = (server) => {
// let timer = 0
const { chartType, location, data, url, value, name } = server

@@ -77,3 +102,2 @@ let { unit, threshold } = server

url: url,
// cache: false,
start_time: new Date().getTime(),

@@ -89,11 +113,7 @@ complete: function(returnData) {

if (result > threshold) {
// $('#' + location).addClass('panel-background-alert')
let alert = { type: 'alert', measure: name, value: result + unit, threshold: threshold + unit }
if (!alertsCurrent[name]) {
alertsCurrent[name] = { startTime: new Date() }
}
if (!alertsCurrent[name]) alertsCurrent[name] = { startTime: new Date() }
alerts.unshift(alert)
$('#alertsRecent').prepend(`<div class="threshold threshold-recent">${new Date().toLocaleString()}: ${name} - ${result + unit} (>${threshold + unit})</div>`)
} else {
// $('#' + location).removeClass('panel-background-alert')
if (alertsCurrent[name]) delete alertsCurrent[name]

@@ -117,6 +137,9 @@ }

const checkmeasurements = (measurements) => {
measurements.forEach((currentServer) => pingServer(currentServer))
}
/**
* display a spark line moving through the dashboard panel
*
* @param {object} server - service being measured
* @param {number} x - x-axis value of the data
* @param {number} line - y-axis value
*/
const displaySpark = (server, x, line) => {

@@ -135,2 +158,10 @@ graph[server.location].selectAll('path')

/**
* repeat calculation of values
*
* @param {function} fn - callback function
* @param {integer} delay - pause duration
* @param {object} measurements - services being measured
* @returns {object} handle
*/
const requestInterval = (fn, delay, measurements) => {

@@ -144,3 +175,2 @@ const requestAnimFrame = (() => {

let handle = {}
const loop = () => {

@@ -158,2 +188,8 @@ handle.value = requestAnimFrame(loop)

/**
* apply a background colour (green to red) depending on results
*
* @param {number} percent - percent of threshold
* @returns {string} - colour to apply to background in HSL space
*/
const shadeBackground = (percent) => {

@@ -160,0 +196,0 @@ if (percent > 1) percent = 1

@@ -0,5 +1,14 @@

/**
* get the system cpu load averages
* @module cpu
*/
const process = require('process')
const os = require('os')
/**
* return os CPU usage
*
* @returns {object} result - {os1: cpuUsage load average over 1 minute, os5: cpuUsage load average over 5 minutes, os15: cpuUsage load average over 15 minutes}
*/
module.exports = () => {
// console.log(process.cpuUsage())
const result = process.cpuUsage()

@@ -6,0 +15,0 @@ result.os1 = os.loadavg()[0]

@@ -0,5 +1,14 @@

/**
* get the system memory consumption
* @module mem
*/
const process = require('process')
const os = require('os')
/**
* get memory stats from the system
*
* @returns {object} result - {osUsed: % of total memory consumed, freemem: free memory (string), totalmem: total memory (string)}
*/
module.exports = () => {
// console.log(process.cpuUsage())
const mem = process.memoryUsage()

@@ -6,0 +15,0 @@ let result = {used: Math.floor(100 * mem.heapUsed / mem.heapTotal)}

@@ -0,2 +1,7 @@

/**
* get random number via API to external service
* @module random_number
*/
const got = require('got')
/*

@@ -13,4 +18,12 @@ Example configuration:

}
*/
module.exports = async(url, callback = () => {}) => {
*/
/**
* async function to get random number
*
* @param {string} url - target url
* @param {function} [callback=() => {}]
* @returns {object} result - {url: passed url, random: random number}
*/
module.exports = async (url, callback = () => { }) => {
try {

@@ -23,10 +36,9 @@ if (url && url.match(/url=/gi)) {

})
// console.log(response.body)
callback()
// change to get the JSON response you want to measure
return {url: url, random: response.body[0].random}
return { url: url, random: response.body[0].random }
} catch (error) {
callback()
return {url: url, response: error}
return { url: url, response: error }
}
}

@@ -0,2 +1,13 @@

/**
* url proxy service
* @module url
*/
const got = require('got')
/**
* proxy to external url avoiding CORS issues
* @param {string} url - target url
* @param {function} [callback = () => {}]
* @returns {object} result - {url: passed url, response: response time}
*/
module.exports = async(url, callback = () => {}) => {

@@ -3,0 +14,0 @@ try {

@@ -0,7 +1,17 @@

/**
* proxy to async function call
* @module serveAPI
*/
const path = require('path')
const url = require('url')
/**
* async function to call local API service
*
* @param {object} req - HTTP request
* @param {object} res - HTTP response
* @param {*} [callback=() => { }]
*/
module.exports = async(req, res, callback = () => { }) => {
const requestURL = url.parse(req.url)
// console.log(`loading ${path.join(__dirname, requestURL.pathname + '.js')}`)
// const apiCall = require(__dirname+req.url+'.js')
try {

@@ -11,3 +21,2 @@ (async() => {

const apiCall = await require(path.join(__dirname, requestURL.pathname + '.js'))(requestURL.query)
// console.log(apiCall)
res.setHeader('Content-type', 'text/json')

@@ -14,0 +23,0 @@ res.end(JSON.stringify(apiCall))

@@ -0,5 +1,15 @@

/**
* serve file from local web server
* @module serveFile
*/
const url = require('url')
const fs = require('fs')
const path = require('path')
/**
* simple function to serve file
*
* @param {object} req - HTTP request
* @param {object} res - HTTP response
* @returns null
*/
module.exports = (req, res) => {

@@ -6,0 +16,0 @@ if (!req) return null

{
"name": "response-dashboard",
"version": "1.0.14",
"version": "1.0.15",
"description": "Performance measurement dashboard with configurable metrics and end-point monitoring. Ideally suited to API microservices.",

@@ -17,3 +17,4 @@ "main": "index.js",

"start": "node index.js",
"test": "jest --maxWorkers=1 --testTimeout=30000"
"test": "jest --maxWorkers=1 --testTimeout=30000",
"doc": "jsdoc -c .jsdocrc"
},

@@ -27,2 +28,3 @@ "author": "marctimperley@yahoo.co.uk",

"devDependencies": {
"boxy-jsdoc-template": "^2.0.2",
"eslint": "^5.4.0",

@@ -35,4 +37,5 @@ "eslint-config-standard": "^11.0.0",

"eslint-plugin-standard": "^3.1.0",
"jest": "^24.9.0"
"jest": "^24.9.0",
"jsdoc": "^3.6.4"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc