private void FMonitorChart_Paint(object sender, PaintEventArgs e) { Graphics graphics = base.CreateGraphics(); int y = 180; graphics.FillRectangle(new SolidBrush(Color.White), this.MarginLeft, y, 10, 10); graphics.FillRectangle(new SolidBrush(Color.Green), this.MarginLeft + 100, y, 10, 10); graphics.FillRectangle(new SolidBrush(Color.Red), this.MarginLeft + 200, y, 10, 10); Font font = new Font("04b_08", 6f); Brush brush = new SolidBrush(Color.Black); graphics.DrawString("无数据", font, brush, (float)(this.MarginLeft + 20), (float)y); graphics.DrawString("正常", font, brush, (float)(this.MarginLeft + 120), (float)y); graphics.DrawString("宕机", font, brush, (float)(this.MarginLeft + 220), (float)y); MonitorHistory history = new MonitorHistory(this.monitorCfg.RecordId); this.drawRule(0, 100); this.drawRule(12, 150); List <MonitorData> oneDayHistorys = history.GetOneDayHistorys(DateTime.Now); foreach (MonitorData data in oneDayHistorys) { this.drawMonitorData(this.getTimePoint(data.Time), data.Down); } }
protected override void OnStart(string[] args) { Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory; Logger.Init(); MonitorHistory.Init(); Logger logger = new Logger("service"); logger.Error("begin start", new object[0]); try { this.Config = DNSPodClientLite.Config.Load("service.xml"); this.Api = new DNSPodClientLite.Api(this.Config.LoginEmail, this.Config.LoginPassword, this.Config.GetLocal()); this.Ddns = new DDns(this.Config.LastIp, this.Config.GetLocal()); this.Ddns.IPChanged += new Action <string>(this._ddns_IPChanged); this.Ddns.Start(); this.Monitor = new HttpMonitor(this.Config); this.Monitor.StatusChanged += new HttpMonitor.DStatusChanged(this.Monitor_StatusChanged); this.Monitor.Start(); logger.Error("end start", new object[0]); } catch (Exception exception) { logger.Error("start 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 }); } } }
public static MonitorHistory Get(int recordid) { lock (typeof(MonitorData)) { MonitorHistory history; if (!_history.TryGetValue(recordid, out history)) { history = new MonitorHistory(recordid); _history.Add(recordid, history); } return(history); } }
private static void Main(string[] args) { Logger.Init(); MonitorHistory.Init(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var dialog = new LoginDialog(); if (dialog.ShowDialog() == DialogResult.OK) { Application.Run(new ControlPanelForm()); } }
private static void Main(string[] args) { if (Environment.UserInteractive) { Logger.Init(); MonitorHistory.Init(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new FLogin()); } else { ServiceBase.Run(new Service1()); } }
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); }