public static RubyHash NodeUtilization() { RubyHash result = new RubyHash(); Common.Config resource = Node.ResourceLimits; if (resource == null) { return(result); } result["node_profile"] = resource.Get("node_profile", Node.DEFAULT_NODE_PROFILE); result["quota_blocks"] = resource.Get("quota_blocks", Node.DEFAULT_QUOTA_BLOCKS); result["quota_files"] = resource.Get("quota_files", Node.DEFAULT_QUOTA_FILES); result["no_overcommit_active"] = Boolean.Parse(resource.Get("no_overcommit_active", Node.DEFAULT_NO_OVERCOMMIT_ACTIVE)); result["max_active_gears"] = Convert.ToInt32(resource.Get("max_active_gears", Node.DEFAULT_MAX_ACTIVE_GEARS)); // // Count number of git repos and gear status counts // result["git_repos_count"] = 0; result["gears_total_count"] = 0; result["gears_idled_count"] = 0; result["gears_stopped_count"] = 0; result["gears_started_count"] = 0; result["gears_deploying_count"] = 0; result["gears_unknown_count"] = 0; foreach (ApplicationContainer app in ApplicationContainer.All(null, false)) { result["gears_total_count"] += 1; switch (app.State.Value()) { case "building": case "deploying": case "new": result["gears_deploying_count"] += 1; break; case "started": result["gears_started_count"] += 1; break; case "idle": result["gears_idled_count"] += 1; break; case "stopped": result["gears_stopped_count"] += 1; break; case "unknown": result["gears_unknown_count"] += 1; break; } } // consider a gear active unless explicitly not result["gears_active_count"] = result["gears_total_count"] - result["gears_idled_count"] - result["gears_stopped_count"]; result["gears_usage_pct"] = result["max_active_gears"] == 0 ? 0.0f : (result["gears_total_count"] * 100.0f) / result["max_active_gears"]; result["gears_active_usage_pct"] = result["max_active_gears"] == 0 ? 0.0f : (result["gears_active_count"] * 100.0f) / result["max_active_gears"]; result["capacity"] = result["gears_usage_pct"].ToString(); result["active_capacity"] = result["gears_active_usage_pct"].ToString(); return(result); }