예제 #1
0
        private Alert GenerateAlert(AlertPolicy alertPolicy, AlertTrigger trigger, ServerStatistic statistic, string serverId, string message)
        {
            var alert = new Alert()
            {
                AlertPolicyId = alertPolicy.Id,
                ServerId = serverId,
                Metric = trigger.Metric,
                Message = message,
                GeneratedOn = statistic.Timestamp
            };

            return alert;
        }
예제 #2
0
 void SetInternalAlertPolicyProperties(AlertPolicy policy)
 {
     policy.ServerService = serverService;
 }
예제 #3
0
        /// <summary>
        /// Determines if a server has violated a certain alert policy and returns an alert if true;
        /// </summary>
        private Alert GetServerAlert(AlertPolicy alertPolicy, AlertTrigger trigger, ServerStatistic statistic, string serverId)
        {
            if (string.Equals(trigger.Metric, Constants.Metrics.Cpu, StringComparison.CurrentCultureIgnoreCase))
            {
                if (statistic.CpuPercent > ((float)trigger.Threshold))
                {
                    return GenerateAlert(alertPolicy, trigger, statistic, serverId, Constants.AlertMessages.CpuAlert);
                }
            }

            if (string.Equals(trigger.Metric, Constants.Metrics.Memory, StringComparison.CurrentCultureIgnoreCase))
            {
                if (statistic.MemoryPercent > ((float)trigger.Threshold))
                {
                    return GenerateAlert(alertPolicy, trigger, statistic, serverId, Constants.AlertMessages.MemoryAlert);
                }
            }

            if (string.Equals(trigger.Metric, Constants.Metrics.Disk, StringComparison.CurrentCultureIgnoreCase))
            {
                float totalDiskUsage = 0;

                foreach (var guestDiskUsage in statistic.GuestDiskUsage)
                {
                    float usage = (guestDiskUsage.ConsumedMB / guestDiskUsage.CapacityMB);
                    totalDiskUsage += usage;
                }

                if (totalDiskUsage > (trigger.Threshold / 100f))
                {
                    return GenerateAlert(alertPolicy, trigger, statistic, serverId, Constants.AlertMessages.DiskUsageAlert);
                }
            }

            return null;
        }