static void RedrawServer(Server server) { var j = 0; var offset = offsets[server.HostnameOrIpAddress]; Func <int, int> rowIndex = ((p) => { var r = offset + j; j += p; return(r); }); rowIndex(1); foreach (var service in server.Services) { var nameText = string.Format("{0}:", service.DisplayName); var statusText = string.Format("{0,20}", service.LastState); var timingText = string.Format("{0,8:###.00}ms {1,8:###.00}ms +- {2,6:###.00}ms", service.LastCheckDuration.TotalMilliseconds, service.LastCheckDurationMean, service.LastCheckDurationStdDev); short statusFlags = 0; switch (service.LastState) { case ServiceState.Unknown: statusFlags = 13; break; case ServiceState.Reachable: statusFlags = 10; break; case ServiceState.Unreachable: statusFlags = 12; break; default: statusFlags = 15; break; } lock (buffer) { buffer.clearRow(rowIndex(0)); buffer.Draw(nameText, 0, rowIndex(0), 15); buffer.Draw(statusText, 20, rowIndex(0), statusFlags); buffer.Draw(timingText, 50, rowIndex(0), 15); } rowIndex(1); } }
static void Main(string[] args) { Console.OutputEncoding = Encoding.UTF8; Out.ImmediateMode = true; Out.Setup(); var perfMon = PerformanceMetricProvider.Instance; var adapters = perfMon.GetNetworkAdapters(); var graphs = new List <Panel>(); var windowWidth = Out.Window.Width; var windowHeight = Out.Window.Height; if (adapters.Length > 0) { var nicHeight = windowHeight / adapters.Length; for (var i = 0; i < adapters.Length; i++) { graphs.Add(new NetworkAdapterPanel(30, nicHeight, perfMon, adapters[i]) { X = 0, Y = nicHeight * i }); } } graphs.Add(new StatGraphPanel("Processor Usage (%)", windowWidth - 30, windowHeight / 2, 0, 100, () => perfMon.GetProcessorTime()) { X = 30, Y = 0 }); graphs.Add(new StatGraphPanel("Memory Usage (GB)", windowWidth - 30, windowHeight / 2, 0, (float)perfMon.TotalMemory.Gigabytes, () => (float)(perfMon.TotalMemory.Gigabytes - perfMon.GetFreeMemory().Gigabytes)) { X = 30, Y = windowHeight / 2 }); Out.ImmediateMode = false; while (true) { Out.Setup(); foreach (var graph in graphs) { graph.Draw(); } Out.Draw(); Thread.Sleep(1000); } }
static void Main(string[] args) { #if DEBUG //ObjectCache.Instance.Clear(); SensorFactory.RegisterSensorBuilder <IcmpSensor>(ServiceProtocol.ICMP, (sfr) => new MockedSensor()); SensorFactory.RegisterSensorBuilder <TcpPortSensor>(ServiceProtocol.TCP, (sfr) => new MockedSensor()); SensorFactory.RegisterSensorBuilder <UdpPortSensor>(ServiceProtocol.UDP, (sfr) => new MockedSensor()); #else SensorFactory.RegisterSensorBuilder <IcmpSensor>(ServiceProtocol.ICMP, (sfr) => new IcmpSensor()); SensorFactory.RegisterSensorBuilder <TcpPortSensor>(ServiceProtocol.TCP, (sfr) => new TcpPortSensor(sfr.PortNumber)); SensorFactory.RegisterSensorBuilder <UdpPortSensor>(ServiceProtocol.UDP, (sfr) => new UdpPortSensor(sfr.PortNumber)); #endif var serviceRecords = ObjectCache.Instance.GetOrSetObject("ServiceFileRecordsRegistryContent", () => LoadServiceRecordsFromFile()); ServiceFileRecordRegistry.Load(serviceRecords); ServiceFileRecordRegistry.AddServiceFileRecord(new ServiceFileRecord() { Name = "echo-icmp", DisplayName = "ping", PortNumber = 0, Protocol = ServiceProtocol.ICMP }); var serverRecords = ObjectCache.Instance.GetOrSetObject("ServerList", () => new[] { new ServerRecord() { HostnameOrIpAddress = "127.0.0.1", ServiceNames = new[] { "echo-icmp", "microsoft-ds-tcp" } }, new ServerRecord() { HostnameOrIpAddress = "ic15.at", ServiceNames = new[] { "echo-icmp", "http-tcp", "https-tcp" } }, new ServerRecord() { HostnameOrIpAddress = "8.8.8.8", ServiceNames = new[] { "echo-icmp", "domain-tcp" } }, new ServerRecord() { HostnameOrIpAddress = "8.8.4.4", ServiceNames = new[] { "echo-icmp", "domain-tcp" } } }); foreach (var serverRecord in serverRecords) { servers.Add(serverRecord.HostnameOrIpAddress, new Server(serverRecord.HostnameOrIpAddress, serverRecord.ServiceNames)); } Console.CursorVisible = false; int bufferWidth = PreferedConsoleBufferWidth > Console.BufferWidth ? PreferedConsoleBufferWidth : Console.BufferWidth; int bufferHeight = PreferedConsoleBufferHeight > Console.BufferHeight ? PreferedConsoleBufferHeight : Console.BufferHeight; Console.SetBufferSize(bufferWidth, bufferHeight); try { Console.SetWindowSize(PreferedConsoleWindowWidth, PreferedConsoleWindowHeight); } catch (Exception ex) { Console.WriteLine("ERROR: {0}", ex.Message); Console.WriteLine("== Continue With Enter =="); Console.ReadLine(); } Console.Clear(); buffer = new ConsoleBuffer(Console.BufferWidth, Console.BufferHeight, Console.BufferWidth, Console.BufferHeight); object bufferLock = new object(); buffer.Draw("= == === ==== ===== =========================================== ====== ==== === == =", 0, 0, 15); buffer.Draw("= == === ==== ===== = Fancy Console Host Monitor = ====== ==== === == =", 0, 1, 15); buffer.Draw("= == === ==== ===== =========================================== ====== ==== === == =", 0, 2, 15); int offsetIndex = 4; foreach (var s in servers.Values) { var pos = offsetIndex; offsetIndex += s.Services.Count() + 2; buffer.Draw(string.Format("#### {0}", s.FullyQualifiedHostName), 0, pos, 15); offsets.Add(s.HostnameOrIpAddress, pos); } buffer.Print(); Observable.Merge( servers.Values.Select(server => Observable.Interval(TimeSpan.FromSeconds(1.0)).Select(_ => server)) ) .Do(server => { lock (server) { server.UpdateServices(); } }) .Do(server => { lock (server) { RedrawServer(server); } }) .Sample(TimeSpan.FromSeconds(0.5)) .Do(_ => buffer.Print()) .RunAsync(CancellationToken.None) ; Console.ReadKey(); }