コード例 #1
0
ファイル: AutoTx.cs プロジェクト: imcf/auto-tx
        /// <summary>
        /// Do the main tasks of the service, check system state, trigger transfers, ...
        /// </summary>
        private void RunMainTasks()
        {
            // Log.Error("test the email rate limiting for error messages...");
            // throw new Exception("just a test exception from RunMainTasks");

            // mandatory tasks, run on every call:
            SendLowSpaceMail(SystemChecks.CheckFreeDiskSpace(_config.SpaceMonitoring));
            UpdateServiceState();
            _status.SerializeHeartbeat();

            if (TimeUtils.SecondsSince(_lastUserDirCheck) >= 120)
            {
                _lastUserDirCheck = FsUtils.CreateIncomingDirectories(
                    _config.DestinationDirectory, _config.TmpTransferDir, _config.IncomingPath);
            }

            // tasks depending on the service state:
            if (_status.ServiceSuspended)
            {
                // make sure to pause any running transfer:
                PauseTransfer();
            }
            else
            {
                // always check the incoming dirs, independently of running transfers:
                CheckIncomingDirectories();
                // now trigger potential transfer tasks:
                RunTransferTasks();
            }
        }
コード例 #2
0
ファイル: ATxDiagnostics.cs プロジェクト: mathse/auto-tx
        static void Main(string[] args)
        {
            var loglevel = LogLevel.Debug;

            if (args.Length > 0 && args[0] == "trace")
            {
                loglevel = LogLevel.Trace;
            }
            var logConfig        = new LoggingConfiguration();
            var logTargetConsole = new ConsoleTarget {
                Name   = "console",
                Header = "AutoTx Diagnostics",
                Layout = @"${time} [${level}] ${message}",
            };

            logConfig.AddTarget(logTargetConsole);
            var logRuleConsole = new LoggingRule("*", loglevel, logTargetConsole);

            logConfig.LoggingRules.Add(logRuleConsole);
            LogManager.Configuration = logConfig;

            var commonAssembly    = Assembly.GetAssembly(typeof(ATxCommon.Monitoring.Cpu));
            var commonVersionInfo = FileVersionInfo.GetVersionInfo(commonAssembly.Location);

            Log.Info("ATxCommon library version: {0}", commonVersionInfo.ProductVersion);

            Log.Debug("Free space on drive [C:]: " + Conv.BytesToString(SystemChecks.GetFreeDriveSpace("C:")));

            Log.Info("Checking CPU load using ATxCommon.Monitoring...");
            var cpu = new Cpu {
                Interval  = 250,
                Limit     = 25,
                Probation = 4,  // 4 * 250 ms = 1 second
                Enabled   = true
            };

            System.Threading.Thread.Sleep(10000);
            cpu.Enabled = false;
            Log.Info("Finished checking CPU load using ATxCommon.Monitoring.\n");

            Log.Info("Checking CPU load using WMI...");
            for (int i = 0; i < 10; i++)
            {
                WmiQueryCpuLoad();
                System.Threading.Thread.Sleep(1000);
            }
            Log.Info("Finished checking CPU load using WMI.\n");
        }
コード例 #3
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));
        }
コード例 #4
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);
        }
コード例 #5
0
ファイル: ATxDiagnostics.cs プロジェクト: imcf/auto-tx
        private static void Main(string[] args)
        {
            var loglevel = LogLevel.Debug;

            if (args.Length > 0 && args[0] == "trace")
            {
                loglevel = LogLevel.Trace;
            }
            var logConfig        = new LoggingConfiguration();
            var logTargetConsole = new ConsoleTarget {
                Name   = "console",
                Header = "AutoTx Diagnostics",
                Layout = @"${time} [${level}] ${message}",
            };

            logConfig.AddTarget(logTargetConsole);
            var logRuleConsole = new LoggingRule("*", loglevel, logTargetConsole);

            logConfig.LoggingRules.Add(logRuleConsole);
            LogManager.Configuration = logConfig;

            // set the default performance monitors:
            var perfMonitors = new[] { "CPU", "PhysicalDisk" };

            // if requested explicitly as a command line parameter, override them:
            if (args.Length > 1)
            {
                perfMonitors = args[1].Split(',');
            }

            var commonAssembly    = Assembly.GetAssembly(typeof(Cpu));
            var commonVersionInfo = FileVersionInfo.GetVersionInfo(commonAssembly.Location);

            Log.Info("ATxCommon library version: {0}", commonVersionInfo.ProductVersion);

            Log.Debug("Free space on drive [C:]: " + Conv.BytesToString(SystemChecks.GetFreeDriveSpace("C:")));

            if (perfMonitors.Contains("CPU"))
            {
                Log.Info("Watching CPU load using ATxCommon.Monitoring...");
                var cpu = new Cpu {
                    Interval  = 250,
                    Limit     = 50,
                    Probation = 4, // 4 * 250 ms = 1 second
                    LogPerformanceReadings = LogLevel.Info,
                    Enabled = true
                };
            }

            if (perfMonitors.Contains("PhysicalDisk"))
            {
                Log.Info("Watching I/O load using ATxCommon.Monitoring...");
                var disk = new PhysicalDisk {
                    Interval  = 250,
                    Limit     = 0.25F,
                    Probation = 4, // 4 * 250 ms = 1 second
                    LogPerformanceReadings = LogLevel.Info,
                    Enabled = true
                };
            }

            while (true)
            {
                System.Threading.Thread.Sleep(10000);
            }
        }