diff --git a/cloudron.js b/cloudron.js index def31d0..63f102c 100644 --- a/cloudron.js +++ b/cloudron.js @@ -306,16 +306,11 @@ Cloudron.prototype.checkA = function (callback) { }); }; -Cloudron.prototype.checkGraphs = function (appId) { - var timePeriod = 2 * 60; // in minutes - var timeBucketSize = 30; // in minutes - - var target = 'summarize(collectd.localhost.table-' + appId + '-memory.gauge-rss, "' + timeBucketSize + 'min", "avg")'; - +Cloudron.prototype._checkGraphs = function (targets, from) { var params = { - target: [ target ], + target: targets, format: 'json', - from: '-' + timePeriod + 'min', + from: from, access_token: this._credentials.accessToken }; @@ -323,19 +318,40 @@ Cloudron.prototype.checkGraphs = function (appId) { for (var i = 0; i < 40; i++) { sleep(10); res = request.get(this._origin + '/api/v1/cloudron/graphs').query(params).end(); - if (res.statusCode === 200) { - if (util.isArray(res.body) && res.body.length !== 0 && res.body[0].target && res.body[0].datapoints && res.body[0].datapoints.length !== 0) { - console.log(); - console.log(res.body); - break; - } - } process.stdout.write('.'); + if (res.statusCode !== 200) continue; + if (!util.isArray(res.body) && res.body.length !== targets.length) continue; + + for (var j = 0; j < res.body.length; j++) { + if (res.body[j].datapoints.length === 0) break; // no data + console.log(); + console.log(res.body); + return; // success + } } assert(false, 'Graphs are not populated'); }; +Cloudron.prototype.checkAppGraphs = function (appId) { + var timePeriod = 2 * 60; // in minutes + var timeBucketSize = 30; // in minutes + + var target = 'summarize(collectd.localhost.table-' + appId + '-memory.gauge-rss, "' + timeBucketSize + 'min", "avg")'; + + this._checkGraphs([target], '-' + timePeriod + 'min'); +}; + +Cloudron.prototype.checkDiskGraphs = function () { + var targets = [ + 'averageSeries(collectd.localhost.df-loop*.df_complex-free)', + 'averageSeries(collectd.localhost.df-loop*.df_complex-reserved)', + 'averageSeries(collectd.localhost.df-loop*.df_complex-used)' + ]; + + this._checkGraphs(targets, '-1min'); +}; + Cloudron.prototype.checkSPF = function (callback) { var that = this; dns.resolveTxt(this._box.domain, function (error, records) { diff --git a/test/app-flow-test.js b/test/app-flow-test.js index a35cbb1..c5e90ec 100644 --- a/test/app-flow-test.js +++ b/test/app-flow-test.js @@ -76,7 +76,7 @@ describe('Application flow test', function () { }); it('displays app graphs', function () { - cloudron.checkGraps(appId); + cloudron.checkAppGraphs(appId); }); it('can configure app', function () {