Ejemplo n.º 1
0
        public IEnumerable <ApplicationContainer> Gears(bool skipStopped = true)
        {
            List <ApplicationContainer> gearSet = new List <ApplicationContainer>();

            if (this.Uuids != null)
            {
                foreach (string uuid in Uuids)
                {
                    ApplicationContainer gear = ApplicationContainer.GetFromUuid(uuid);
                    // TODO check gear stoplock
                    if (skipStopped && gear.StopLock)
                    {
                        throw new InvalidOperationException(string.Format("Gear is locked: {0}"));
                    }

                    gearSet.Add(gear);
                }
            }
            else
            {
                gearSet = ApplicationContainer.All(null, false).ToList();
            }

            foreach (ApplicationContainer gear in gearSet)
            {
                try
                {
                    // TODO check stop lock again
                    if (skipStopped && gear.StopLock)
                    {
                        continue;
                    }
                }
                catch (Exception ex)
                {
                    Logger.Error("Gear evaluation failed for: {0}", gear.Uuid);
                    Logger.Error("Exception: {0} - {1}", ex.Message, ex.StackTrace);
                }

                yield return(gear);
            }
        }
Ejemplo n.º 2
0
        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);
        }