You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by be...@apache.org on 2017/06/19 17:27:02 UTC

[incubator-openwhisk-package-alarms] branch master updated: Add system stats and basic auth to the health endpoint (#68)

This is an automated email from the ASF dual-hosted git repository.

berstler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-package-alarms.git


The following commit(s) were added to refs/heads/master by this push:
     new d24b95d  Add system stats and basic auth to the health endpoint (#68)
d24b95d is described below

commit d24b95dd594f3b415963ea1d150228517028e0fc
Author: Jason Peterson <ja...@us.ibm.com>
AuthorDate: Mon Jun 19 13:27:00 2017 -0400

    Add system stats and basic auth to the health endpoint (#68)
    
    * Add system stats and basic auth to the health endpoint
    * get all system stats in parallel
---
 package.json              |  5 ++---
 provider/app.js           |  4 ++--
 provider/lib/constants.js |  7 ++++++-
 provider/lib/health.js    | 37 ++++++++++++++++++++++++++++++-------
 provider/lib/utils.js     |  5 ++---
 5 files changed, 42 insertions(+), 16 deletions(-)

diff --git a/package.json b/package.json
index 03c4cdc..90a13a7 100755
--- a/package.json
+++ b/package.json
@@ -6,10 +6,8 @@
   "license": "ISC",
   "dependencies": {
     "body-parser": "^1.15.0",
-    "agentkeepalive": "^2.2.0",
     "cron": "^1.1.0",
     "express": "^4.13.4",
-    "http-status": "^0.2.0",
     "lodash": "^4.5.0",
     "nano": "^6.2.0",
     "request": "^2.69.0",
@@ -19,6 +17,7 @@
     "http-status-codes": "^1.0.5",
     "request-promise": "^1.0.2",
     "redis":"^2.7.1",
-    "bluebird": "^3.5.0"
+    "bluebird": "^3.5.0",
+    "systeminformation": "^3.19.0"
   }
 }
\ No newline at end of file
diff --git a/provider/app.js b/provider/app.js
index 094370e..ecfe146 100755
--- a/provider/app.js
+++ b/provider/app.js
@@ -34,7 +34,7 @@ var dbProtocol = process.env.DB_PROTOCOL;
 var dbPrefix = process.env.DB_PREFIX;
 var databaseName = dbPrefix + constants.TRIGGER_DB_SUFFIX;
 var redisUrl = process.env.REDIS_URL;
-var ddname = '_design/triggers';
+var ddname = '_design/' + constants.DESIGN_DOC_NAME;
 
 // Create the Provider Server
 var server = http.createServer(app);
@@ -148,7 +148,7 @@ function init(server) {
         app.get(providerRAS.endPoint, providerRAS.ras);
 
         // Health Endpoint
-        app.get(providerHealth.endPoint, providerHealth.health);
+        app.get(providerHealth.endPoint, providerUtils.authorize, providerHealth.health);
 
         // Activation Endpoint
         app.get(providerActivation.endPoint, providerUtils.authorize, providerActivation.active);
diff --git a/provider/lib/constants.js b/provider/lib/constants.js
index 4fca5dd..e45e204 100644
--- a/provider/lib/constants.js
+++ b/provider/lib/constants.js
@@ -3,11 +3,16 @@ const DEFAULT_MAX_TRIGGERS = -1;
 const RETRY_ATTEMPTS = 10;
 const RETRY_DELAY = 1000; //in milliseconds
 const REDIS_KEY = 'active';
+const DESIGN_DOC_NAME = 'triggers';
+const FILTER_FUNCTION = 'only_triggers_by_worker';
+
 
 module.exports = {
     TRIGGER_DB_SUFFIX: TRIGGER_DB_SUFFIX,
     DEFAULT_MAX_TRIGGERS: DEFAULT_MAX_TRIGGERS,
     RETRY_ATTEMPTS: RETRY_ATTEMPTS,
     RETRY_DELAY: RETRY_DELAY,
-    REDIS_KEY: REDIS_KEY
+    REDIS_KEY: REDIS_KEY,
+    DESIGN_DOC_NAME: DESIGN_DOC_NAME,
+    FILTER_FUNCTION: FILTER_FUNCTION
 };
diff --git a/provider/lib/health.js b/provider/lib/health.js
index 808295d..2c56e2b 100644
--- a/provider/lib/health.js
+++ b/provider/lib/health.js
@@ -1,11 +1,34 @@
-module.exports = function(providerUtils) {
+var si = require('systeminformation');
 
-  // Health Endpoint
-  this.endPoint = '/health';
+module.exports = function(utils) {
 
-  // Health Logic
-  this.health = function (req, res) {
-      res.send({triggerCount: Object.keys(providerUtils.triggers).length});
-  };
+    // Health Endpoint
+    this.endPoint = '/health';
+    var stats = {triggerCount: Object.keys(utils.triggers).length};
+
+    // Health Logic
+    this.health = function (req, res) {
+
+        // get all system stats in parallel
+        Promise.all([
+            si.mem(),
+            si.currentLoad(),
+            si.fsSize(),
+            si.networkStats(),
+            si.inetLatency(utils.routerHost)
+        ])
+        .then(results => {
+            stats.memory = results[0];
+            stats.cpu = results[1];
+            stats.disk = results[2];
+            stats.network = results[3];
+            stats.apiHostLatency = results[4];
+            res.send(stats);
+        })
+        .catch(error => {
+            stats.error = error;
+            res.send(stats);
+        });
+    };
 
 };
diff --git a/provider/lib/utils.js b/provider/lib/utils.js
index 5ae875c..9b366e4 100644
--- a/provider/lib/utils.js
+++ b/provider/lib/utils.js
@@ -22,9 +22,8 @@ module.exports = function(
 
     var retryDelay = constants.RETRY_DELAY;
     var retryAttempts = constants.RETRY_ATTEMPTS;
-
-    var ddname = 'triggers';
-    var filter = 'only_triggers_by_worker';
+    var ddname = constants.DESIGN_DOC_NAME;
+    var filter = constants.FILTER_FUNCTION;
 
     var utils = this;
 

-- 
To stop receiving notification emails like this one, please contact
['"commits@openwhisk.apache.org" <co...@openwhisk.apache.org>'].