public void start() { string sql3 = "update Status_Histroy set sign = '1'"; string sql4 = "update Status_Now set flag = 'N',details = '正常' where para_name = 'disk_size'"; string value = "正常"; string sql5 = "update Status_Now set para_value='正常',details ='" + value + "',create_date = '" + DateTime.Now + "',flag = 'N' where para_name = 'instrument_connection'"; string sql111 = "update Status_Now set para_value='正常',details ='" + value + "',create_date = '" + DateTime.Now + "',flag = 'N' where para_name = 'cpu_running'"; string sql222 = "update Status_Now set para_value='正常',details ='" + value + "',create_date = '" + DateTime.Now + "',flag = 'N' where para_name = 'memory_running'"; Tool_Class.IO_tool tool = new Tool_Class.IO_tool(); string l61 = tool.readconfig("jb", "netwarn"); string disk_c = tool.readconfig("jb", "Cwarn"); string disk_d = tool.readconfig("jb", "Dwarn"); string disk_e = tool.readconfig("jb", "Ewarn"); string disk_f = tool.readconfig("jb", "Fwarn"); string cpu = tool.readconfig("jb", "cpuwarnvalue"); string memery = tool.readconfig("jb", "memwarnvalue"); //label61.Text = "连通不通次数少于" + l61 + "次"; diskrecomond = "C>" + disk_c + "G;" + "D>" + disk_d + "G;" + "\n\r" + "E>" + disk_e + "G;" + "F>" + disk_f + "G;"; cpurecomond = "CPU使用率低于" + cpu + "%,内存使用率低于" + memery + "%"; tool.AccessDbclass(sql3); tool.AccessDbclass(sql4); tool.AccessDbclass(sql5); tool.AccessDbclass(sql111); tool.AccessDbclass(sql222); //threadlog(true, 0); }
public void start() { string sql3 = "update Status_Histroy set sign = '1'"; string sql4 = "update Status_Now set flag = 'N',details = '正常' where para_name = 'disk_size'"; string value = "正常"; string sql5 = "update Status_Now set para_value='正常',details ='" + value + "',create_date = '" + DateTime.Now + "',flag = 'N' where para_name = 'instrument_connection'"; string sql111 = "update Status_Now set para_value='正常',details ='" + value + "',create_date = '" + DateTime.Now + "',flag = 'N' where para_name = 'cpu_running'"; string sql222 = "update Status_Now set para_value='正常',details ='" + value + "',create_date = '" + DateTime.Now + "',flag = 'N' where para_name = 'memory_running'"; Tool_Class.IO_tool tool = new Tool_Class.IO_tool(); tool.AccessDbclass(sql3); tool.AccessDbclass(sql4); tool.AccessDbclass(sql5); tool.AccessDbclass(sql111); tool.AccessDbclass(sql222); }
private void timer2_Tick(object sender, EventArgs e) { this.timer2.Interval = (1000 * 3600); //1秒1次 string time = DateTime.Now.Hour.ToString(); if (time == "12") { string sql3 = "update Status_Histroy set sign = '1'"; Tool_Class.IO_tool tool = new Tool_Class.IO_tool(); tool.AccessDbclass(sql3); } }
//内存监控 public void threadMem(bool is_first, int exec) { string memvalue = "内存正常;\n\r"; string memsign = "N"; string cpuvalue = "CPU正常;\n\r"; string cpusign = "N"; string db_dir = System.Windows.Forms.Application.StartupPath + "\\db.accdb"; bool begin = tool.execute_or_not("memory_running", db_dir, cpumem, is_first, exec); if (begin == true) { monitor mem = new monitor(); uint memValue = mem.getRamUsePercent(); int perOfRam = int.Parse(memValue.ToString().Split('.').ElementAt(0)); int memerrorvalue = int.Parse(tool.readconfig("bj", "memerrorvalue")); int memerrortime = int.Parse(tool.readconfig("bj", "memerrortime")); int memwarnvalue = int.Parse(tool.readconfig("jb", "memwarnvalue")); int memwarntime = int.Parse(tool.readconfig("jb", "memwarntime")); if (perOfRam >= memwarnvalue) { RamCpuInfo ramCpuInfo = new RamCpuInfo(); ramCpuInfo.WarningDateTime = DateTime.Now; ramCpuInfo.WarningValue = perOfRam; WarningListOfMem.Add(ramCpuInfo); string str5 = System.Windows.Forms.Application.StartupPath; string a = str5 + "\\db.accdb"; Tool_Class.AccessDbClass1 db = new Tool_Class.AccessDbClass1(); db.AccessDbClass2(a); string sql11 = "insert into Status_Histroy (para_name,details,create_date) values ('memory_running','" + perOfRam + "','" + DateTime.Now + "')"; bool ee = db.ExecuteSQLNonquery(sql11); } ////textBox3.Text = ee.ToString(); string sql5 = "select details from Status_Histroy where para_name = 'memory_running' and sign is null"; DataTable memerrorcount = tool.DbToDatatable(sql5); int num = 0; int errornum = 0; for (int i = 0; i < memerrorcount.Rows.Count; i++) { int numm = int.Parse(memerrorcount.Rows[i][0].ToString()); if (numm > memwarnvalue) { num++; //达到警告值的次数 } if (numm > memerrorvalue) { errornum++; //达到错误值的次数 } } if (num < memwarntime) { memvalue = "内存正常;\n\r"; memsign = "N"; } if (num > memwarntime) { memvalue = "内存>" + memwarnvalue + "% 共:" + num + "次;\n\r"; memsign = "W"; } if (errornum > memerrortime) { memvalue = "内存>" + memerrorvalue + "% 共:" + errornum + "次;\n\r"; memsign = "E"; } string sql6 = "select details from Status_Histroy where para_name = 'cpu_running' and sign is null"; DataTable cpuerrorcount = tool.DbToDatatable(sql6); int numcpu = 0; int errornumcpu = 0; int cpuerrorvalue = int.Parse(tool.readconfig("bj", "cpuerrorvalue")); int cpuerrortime = int.Parse(tool.readconfig("bj", "cpuerrortime")); int cpuwarnvalue = int.Parse(tool.readconfig("jb", "cpuwarnvalue")); int cpuwarntime = int.Parse(tool.readconfig("jb", "cpuwarntime")); for (int i = 0; i < cpuerrorcount.Rows.Count; i++) { int numm = int.Parse(cpuerrorcount.Rows[i][0].ToString()); if (numm > cpuwarnvalue) { numcpu++; //达到警告值的次数 } if (numm > cpuerrorvalue) { errornumcpu++; //达到错误值的次数 } } if (numcpu < cpuwarntime) { cpuvalue = "正常;\n\r"; cpusign = "N"; } if (numcpu > cpuwarntime) { cpuvalue = "CPU>" + cpuwarnvalue + "% 共:" + numcpu + "次;\n\r"; cpusign = "W"; } if (errornumcpu > cpuerrortime) { cpuvalue = "CPU>" + cpuerrorvalue + "% 共:" + errornumcpu + "次;\n\r"; cpusign = "E"; } if (cpusign == "N" && memsign == "N") { string sql10 = "update Status_Now set para_value='正常',flag ='N',details = '" + cpuvalue + "',create_date = '" + DateTime.Now + "' where para_name = 'cpu_running'"; tool.AccessDbclass(sql10); } else { if (cpusign == "E" || memsign == "E") { string sql10 = "update Status_Now set para_value='错误',flag ='E',details = '" + cpuvalue + memvalue + "',create_date = '" + DateTime.Now + "' where para_name = 'cpu_running'"; tool.AccessDbclass(sql10); } else { string sql10 = "update Status_Now set para_value='警告',flag ='W',details = '" + cpuvalue + memvalue + "',create_date = '" + DateTime.Now + "' where para_name = 'cpu_running'"; tool.AccessDbclass(sql10); } } } }