Beispiel #1
0
        public IList <SystemPerformance> GetSystemCpuPerformanceData(string cpuFrom, string to, bool?raw = null)
        {
            try
            {
                DateTime fromDate = DateTime.ParseExact(cpuFrom, Constants.DateFormat, CultureInfo.InvariantCulture);
                DateTime toDate   = DateTime.ParseExact(to, Constants.DateFormat, CultureInfo.InvariantCulture);

                using (var dao = _daoFactory.Create <ISystemDao>())
                {
                    var data = dao.GetCpuPerformanceData(fromDate, toDate);

                    if (raw != true)
                    {
                        SystemPerformance.CompactData(data, SecondsInterval);
                        SystemPerformance.LowerResolution(
                            data,
                            ApplicationSettings.Current.PerformanceGraphMaxPoints,
                            ApplicationSettings.Current.PerformanceGraphThreshold);
                    }

                    return(data);
                }
            }
            catch (Exception e)
            {
                log.Error("REST API Error", e);
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Handles the Started event of the ServiceAppProcess object.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void ServiceAppProcess_Started(object sender, EventArgs e)
        {
            // TODO: this is so bad! but there's a bug here that disappeared as soon as I added this :(
            try
            {
                string            errorMessage = string.Empty;
                ServiceAppProcess process      = sender as ServiceAppProcess;

                if (process != null)
                {
                    if (process.IsProcessRunning)
                    {
                        using (var dao = _daoFactory.Create <IServiceAppDao>())
                        {
                            dao.RecordServiceAppStart(process.ServiceApp.Name);
                        }

                        if (process.ServiceApp.StartupTypeEnum == StartupType.Automatic)
                        {
                            errorMessage = _schedulingService.ScheduleServiceApp(process);
                        }
                    }
                    else
                    {
                        errorMessage = string.Format("Failed to initialize ServiceApp '{0}'", process.ServiceApp.Name);
                    }
                }

                if (!string.IsNullOrWhiteSpace(errorMessage))
                {
                    this._log.Warn(errorMessage);
                }
            }
            catch (Exception ex)
            {
                _log.Error("ServiceAppProcess_Started event failed", ex);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Records the performance of the SAC system
        /// </summary>
        public void RecordPerformance()
        {
            TimeSpan monitorDifference = new TimeSpan(0);

            if (loggingStartTime == null)
            {
                loggingStartTime = DateTime.Now;
            }

            monitorDifference = DateTime.Now - loggingStartTime.Value;

            decimal cpuValue = Math.Floor((decimal)cpuCounter.NextValue() / (decimal)Environment.ProcessorCount);
            decimal ramValue = ((decimal)ramCounter.NextValue() / 1024m) / 1024m;

            // Add on each service app
            foreach (var process in _appManager.ServiceAppProcesses)
            {
                cpuValue += process.GetCurrentCpuValue() / (decimal)Environment.ProcessorCount;
                ramValue += (process.GetCurrentRamValue() / 1024m) / 1024m;
            }

            string message = "Monitor reports as running";

            log.Debug(
                string.Format(
                    "{0:F} {1}: CPU - {2}%, RAM - {3}MB Remaining, Up-Time: {4}",
                    DateTime.Now,
                    message,
                    cpuValue,
                    ramValue,
                    monitorDifference));

            using (ISystemDao dao = _daoFactory.Create <ISystemDao>())
            {
                dao.LogSystemPerformances(message, cpuValue, ramValue);
            }
        }