4 cloudcms.utils.addCommas = function(nStr)
9 x2 = x.length > 1 ? '.' + x[1] : '';
10 var rgx = /(\d+)(\d{3})/;
11 while (rgx.test(x1)) {
12 x1 = x1.replace(rgx, '$1' + ',' + '$2');
17 function ServiceStats(opts, wrapper) {
19 this.wrapper = wrapper;
23 ServiceStats.prototype.updateStats = function(data) {
25 function filldata(value, key) {
26 self.wrapper.find("li."+key).find('span').text(cloudcms.utils.addCommas(value));
28 _.each(data,filldata);
32 ServiceStats.prototype.addArray = function(data) {
33 return _.reduce(data, function(memo, num){ return memo + num; }, 0);
37 ServiceStats.prototype.getActive = function(data) {
38 var active = _.omit(data,'DELETED');
39 var active_count = _.pluck(active, 'count');
40 return this.addArray(active_count);
43 ServiceStats.prototype.getAll = function(data) {
44 return this.addArray(_.pluck(data, 'count'));
47 ServiceStats.prototype.loadStats = function() {
49 if (this.options.compute_url) {
51 url: this.options.compute_url,
53 success: function(data) {
55 'running_vms': data.servers.ACTIVE.count,
56 'active_vms': self.getActive(data.servers),
57 'spawned_vms': self.getAll(data.servers),
58 'running_networks': data.networks.ACTIVE.count,
59 'active_networks': self.getActive(data.networks),
60 'spawned_networks': self.getAll(data.networks),
66 if (this.options.storage_url) {
68 url: this.options.storage,
69 success: function(data) {
70 self.storage.find("span").text(data.storage);
76 ServiceStats.prototype.startUpdate = function(interval) {
79 window.setTimeout(function(){
80 self.startUpdate(interval);