コード例 #1
0
ファイル: AutoTx.cs プロジェクト: imcf/auto-tx
        /// <summary>
        /// Check system parameters for valid ranges and update the global service state accordingly.
        /// </summary>
        private void UpdateServiceState()
        {
            var suspendReasons = new List <string>();

            // check all system parameters for valid ranges and remember the reason in a string
            // if one of them is failing (to report in the log why we're suspended)
            if (_phyDisk.HighLoad)
            {
                suspendReasons.Add("Disk I/O");
            }

            if (_cpu.HighLoad)
            {
                suspendReasons.Add("CPU");
            }

            if (SystemChecks.GetFreeMemory() < _config.MinAvailableMemory)
            {
                suspendReasons.Add("RAM");
            }

            var blacklistedProcess = SystemChecks.CheckForBlacklistedProcesses(
                _config.BlacklistedProcesses);

            if (!string.IsNullOrWhiteSpace(blacklistedProcess))
            {
                suspendReasons.Add("process '" + blacklistedProcess + "'");
            }

            // all parameters within valid ranges, so set the state to "Running":
            if (suspendReasons.Count == 0)
            {
                _status.SetSuspended(false, "all parameters in valid ranges");
                return;
            }

            // set state to "Running" if no-one is logged on:
            if (SystemChecks.NoUserIsLoggedOn())
            {
                _status.SetSuspended(false, "no user is currently logged on");
                return;
            }

            // by reaching this point we know the service should be suspended:
            _status.SetSuspended(true, string.Join(", ", suspendReasons));
        }
コード例 #2
0
ファイル: AutoTx.cs プロジェクト: imcf/auto-tx
        /// <summary>
        /// Write a summary of loaded config + status to the log.
        /// </summary>
        private void StartupSummary()
        {
            var msg = "Startup Summary:\n\n";

            var thisAssembly    = Assembly.GetExecutingAssembly();
            var thisVersionInfo = FileVersionInfo.GetVersionInfo(thisAssembly.Location);

            msg += "------ Assembly Information ------\n" +
                   $" > version: {thisAssembly.GetName().Version}\n" +
                   $" > file version: {thisVersionInfo.FileVersion}\n" +
                   $" > description: {thisVersionInfo.Comments}\n" +
                   $" > version information: {thisVersionInfo.ProductVersion}\n";

            var roboAssembly    = Assembly.GetAssembly(typeof(RoboCommand));
            var roboVersionInfo = FileVersionInfo.GetVersionInfo(roboAssembly.Location);

            msg += "\n------ RoboSharp ------\n" +
                   $" > location: [{roboAssembly.Location}]\n" +
                   $" > version: {roboAssembly.GetName().Version}\n" +
                   $" > file version: {roboVersionInfo.FileVersion}\n" +
                   $" > description: {roboVersionInfo.Comments}\n" +
                   $" > version information: {roboVersionInfo.ProductVersion}\n";

            _versionSummary = $"AutoTx {Properties.Resources.BuildCommit.Trim()} " +
                              $"{Properties.Resources.BuildDate.Trim()} | " +
                              $"RoboSharp {roboAssembly.GetName().Version} " +
                              $"{roboVersionInfo.ProductVersion}";


            msg += "\n------ Loaded status flags ------\n" + _status.Summary() +
                   "\n------ Loaded configuration settings ------\n" + _config.Summary();


            msg += "\n------ Current system parameters ------\n" +
                   "Hostname: " + Environment.MachineName + "\n" +
                   "Free system memory: " + SystemChecks.GetFreeMemory() + " MB" + "\n";
            foreach (var driveToCheck in _config.SpaceMonitoring)
            {
                msg += "Free space on drive '" + driveToCheck.DriveName + "': " +
                       Conv.BytesToString(SystemChecks.GetFreeDriveSpace(driveToCheck.DriveName)) + "\n";
            }


            msg += "\n------ Grace location status, threshold: " + _config.GracePeriod + " days " +
                   "(" + TimeUtils.DaysToHuman(_config.GracePeriod) + ") ------\n";
            try {
                var tmp = SendGraceLocationSummary(_config.GracePeriod);
                if (string.IsNullOrEmpty(tmp))
                {
                    msg += " -- NO EXPIRED folders in grace location! --\n";
                }
                else
                {
                    msg += tmp;
                }
            }
            catch (Exception ex) {
                Log.Error("GraceLocationSummary() failed: {0}", ex.Message);
            }

            Log.Debug(msg);

            // finally check if the validation gave warnings and send them to the admin:
            var warnings = ServiceConfig.ValidatorWarnings;

            if (string.IsNullOrWhiteSpace(warnings))
            {
                return;
            }
            SendAdminEmail(warnings);
        }