public void Execute(IJobExecutionContext context) { Random random = new Random(Guid.NewGuid().GetHashCode()); Thread.Sleep(random.Next(1, 3600) * 1000);//1小时内,暂停随机时间 DevOpsAPI.ReportVersion(); }
private void HealthCheck() { try { SystemStatusMonitor systemMonitor = new SystemStatusMonitor(); ProcessStatusMonitor processMonitor = new ProcessStatusMonitor(processName); LogStatusMonitor logMonitor = new LogStatusMonitor(processName); int warningInterval = 12;//12小时 while (isRunning) { Thread.Sleep(1000); try { if (processMonitor.ProcessExists()) { processMonitor.Refresh(); systemMonitor.Refresh(); var warning = processMonitor.HasWarning(); var systemWarning = systemMonitor.HasWarning(); var logWarning = logMonitor.HasWarning(); if (warning.WarningType == enumWarningType.None) { warning = systemWarning; } if (warning.WarningType != enumWarningType.None && DateTime.Now > nextWarningTime) { nextWarningTime = DateTime.Now.AddHours(warningInterval); //需要报警 DevOpsAPI.SendEvent(warning); } //中心日志报警 if (logWarning.WarningType != enumWarningType.None) { //中心日志检测时间间隔在HasWarning()方法里面,不与线程报警和系统报警共用间隔时间 //nextWarningTime = DateTime.Now.AddHours(warningInterval); DevOpsAPI.SendEvent(logWarning); } } } catch (Exception ex) { //try catch只是为了让它能继续执行下一次检测,不至于线程退出 Console.WriteLine(ex.ToString()); } } } catch (Exception ex) { //PerformanceCounter有些电脑会不可用,用不了就算了吧 Console.WriteLine(ex.ToString()); } }
private void UserControl_Loaded(object sender, RoutedEventArgs e) { try { DevOpsProduct product = DevOpsAPI.ReportVersion(); if (product != null) { viewModel.LastVersion = product.ProductVersion; if (CheckUpdateHelper.CompareVersion(EnvironmentInfo.CurrentVersion, product.ProductVersion) < 0) { viewModel.canExecute = true; } else { viewModel.BtnContent = "当前已是最新版本"; } } } catch (Exception ex) { Console.WriteLine(ex); } }
public void Execute(IJobExecutionContext context) { //获取SmartCenter所在的目录 try { var process = Process.GetProcessesByName("SmartCenter.Host").FirstOrDefault(); if (process != null) { string fileName = process.MainModule.FileName; string diskName = fileName.Substring(0, fileName.IndexOf(":") + 1); ulong space = Win32API.GetDiskFreeSpaceEx(diskName); if (space < 5 * 1024) { WarningMessage warningMessage = new WarningMessage(); warningMessage.Message = "磁盘空间不足"; warningMessage.WarningType = enumWarningType.Disk; DevOpsAPI.SendEvent(warningMessage); } } } catch (Exception ex) { } }
public void Execute(IJobExecutionContext context) { DevOpsAPI.ReportVersion(); }