private void 查看图表ToolStripMenuItem_Click(object sender, EventArgs e) { try { Predicate <Config.MonitorConfig> match = null; Api.Record record; if (this.lvRecords.SelectedItems.Count >= 1) { record = (Api.Record) this.lvRecords.SelectedItems[0].Tag; if (match == null) { match = i => i.RecordId == record.RecordId; } Config.MonitorConfig monitorCfg = this.fLogin.Config.GetMonitors().Find(match); if (monitorCfg != null) { new FMonitorChart(monitorCfg).Show(); } } } catch (Win32Exception) { } catch (Exception exception) { MessageBox.Show(exception.Message); this._logger.Error("fmonitor.showchart has an error:{0}", new object[] { exception }); } }
private void 查看图表ToolStripMenuItem_Click(object sender, EventArgs e) { try { Predicate <Config.MonitorConfig> match = null; DnsPodApi.Record record; if (lvRecords.SelectedItems.Count >= 1) { record = (DnsPodApi.Record)lvRecords.SelectedItems[0].Tag; if (match == null) { match = i => i.RecordId == record.RecordId; } Config.MonitorConfig monitorCfg = AppStatus.Default.Config.GetMonitors().Find(match); if (monitorCfg != null) { new FMonitorChart(monitorCfg).Show(); } } } catch (Win32Exception) { } catch (Exception exception) { MessageBox.Show(exception.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error); _logger.Error("fmonitor.showchart has an error:{0}", new object[] { exception }); } }
public void ThreadProcess(object state) { Predicate <Config.MonitorConfig> predicate2 = null; Predicate <Config.MonitorConfig> match = null; int recordid = (int)state; MonitorHistory h = MonitorHistory.Get(recordid); while (true) { try { if (match == null) { if (predicate2 == null) { predicate2 = x => x.RecordId == recordid; } match = predicate2; } Config.MonitorConfig item = this._cfg.GetMonitors().Find(match); if (item == null) { return; } string status = this.CheckHttp(h, item); if (status != item.Status) { int num = 0; while (num < 3) { if (this.CheckHttp(h, item) != status) { break; } num++; Thread.Sleep(0x2710); } if (num >= 2) { DStatusChanged statusChanged = this.m_StatusChanged; if (statusChanged != null) { statusChanged(item.RecordId, status); } } } Thread.Sleep((int)((item.MonitorInteval * 60) * 0x3e8)); } catch (SocketException) { } catch (Exception exception) { this._logger.Error("ThreadProcess error:{0}", new object[] { exception }); } } }
private string CheckHttp(MonitorHistory h, Config.MonitorConfig item) { string str = "unknow"; int result = 0x3e7; try { TcpClient client2 = new TcpClient { ReceiveTimeout = 0x1388, SendTimeout = 0x1388 }; TcpClient client = client2; client.Connect(item.Ip, item.Port); NetworkStream stream = client.GetStream(); string domain = item.Domain; if (item.Subdomain != "@") { domain = string.Format("{0}.{1}", item.Subdomain, item.Domain); } string s = string.Format("GET / HTTP/1.1\r\nHOST:{0}\r\n\r\n", domain); byte[] bytes = Encoding.ASCII.GetBytes(s); stream.Write(bytes, 0, bytes.Length); byte[] buffer = new byte[0x400]; int count = stream.Read(buffer, 0, 0x400); if (!int.TryParse(Encoding.ASCII.GetString(buffer, 0, count).Substring(9, 3), out result)) { str = "down"; } else { str = "ok"; } client.Close(); } catch (Exception) { str = "down"; } h.WriteData(DateTime.Now, str == "down"); Action <string> info = this.m_Info; if (info != null) { info(string.Format("{0}:监控结果:ip={1},status={2},statuscode={3}", new object[] { DateTime.Now.ToLongTimeString(), item.Ip, str, result })); } return(str); }
private void btnOk_Click(object sender, EventArgs e) { try { int num; IPAddress address; int num2; if (!int.TryParse(txtPort.Text, out num)) { MessageBox.Show("端口填写不正确"); return; } if (chkQiehuan.Checked && (int.TryParse(txtBakvalue.Text, out num2) || !IPAddress.TryParse(txtBakvalue.Text, out address))) { MessageBox.Show("备用IP填写不正确"); return; } Config.MonitorConfig config2 = new Config.MonitorConfig { Domain = domain.Name, Subdomain = record.Name, Ip = record.Value, Status = "unknow", Port = num, DomainId = domain.DomainId, RecordId = record.RecordId, BakValue = txtBakvalue.Text, Line = record.Line, Qiehuan = chkQiehuan.Checked, SmartQiehuan = false, MonitorInteval = int.Parse(cmbMonitorInterval.Text) }; Config.MonitorConfig item = config2; AppStatus.Default.Config.AddMonitor(item); AppStatus.Default.Monitor.StartMonitor(record.RecordId); } catch (Exception exception) { MessageBox.Show(exception.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error); new Logger("ui").Error("fmonitor.enableddns has an error:{0}", new object[] { exception }); } base.Close(); }
private void BindData() { if (base.InvokeRequired) { ThreadStart method = new ThreadStart(this.BindData); base.Invoke(method); } else { try { List <Api.Record> recordList = this.fLogin.Api.GetRecordList(this.domain.DomainId); this.lvRecords.Items.Clear(); this.lvRecords.Groups.Clear(); ListViewGroup group = new ListViewGroup("状态:宕机"); ListViewGroup group2 = new ListViewGroup("状态:正常"); ListViewGroup group3 = new ListViewGroup("状态:未知"); ListViewGroup group4 = new ListViewGroup("未监控"); this.lvRecords.Groups.Add(group); this.lvRecords.Groups.Add(group2); this.lvRecords.Groups.Add(group3); this.lvRecords.Groups.Add(group4); using (List <Api.Record> .Enumerator enumerator = recordList.GetEnumerator()) { Predicate <Config.MonitorConfig> predicate2 = null; Api.Record record; Predicate <Config.MonitorConfig> match = null; while (enumerator.MoveNext()) { record = enumerator.Current; if (record.RecordType == "A") { string text = "未知"; if (match == null) { if (predicate2 == null) { predicate2 = i => i.RecordId == record.RecordId; } match = predicate2; } Config.MonitorConfig config = this.fLogin.Config.GetMonitors().Find(match); record.IsMonitor = config != null; ListViewItem item2 = new ListViewItem(string.Format("{0}.{1}.", record.Name, this.domain.Name)) { Group = group4 }; ListViewItem item = item2; if (config != null) { switch (config.Status) { case "unknow": text = "未知"; item.Group = group3; break; case "down": text = "宕机"; item.UseItemStyleForSubItems = true; item.BackColor = Color.Red; item.Group = group; break; case "ok": text = "正常"; item.Group = group2; break; } } item.Tag = record; item.SubItems.Add(record.Value); item.SubItems.Add(record.RecordType); item.SubItems.Add(record.Line); item.SubItems.Add(text); if (config != null) { item.SubItems.Add(config.Qiehuan ? "是" : "否"); item.SubItems.Add(config.SmartQiehuan ? "智能切换" : config.BakValue); item.SubItems.Add(config.Ip); } this.lvRecords.Items.Add(item); } } } } catch (Exception exception) { this._logger.Error("fddns.binddata has an error:{0}", new object[] { exception }); } } }
public FMonitorChart(Config.MonitorConfig monitorCfg) : this() { this.monitorCfg = monitorCfg; }