Ejemplo n.º 1
0
        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");
        }
Ejemplo n.º 2
0
        /// <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);
        }
Ejemplo n.º 3
0
        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);
            }
        }