/// <summary> /// Constructor /// </summary> public SystemIdleMonitor(float thd_cpu, float thd_hdd, float thd_net, int duration_sec) { //Queue int capacity = duration_sec; queCpu = new MonitorQueue(thd_cpu, capacity); //thdがマイナスなら無効状態で作成される。 queHDD = new MonitorQueue(thd_hdd, capacity); queNet = new MonitorQueue(thd_net, capacity); Counter = new SystemCounter(); Counter.HDD.SetPrefix(BytePerSec.MiBps); Counter.Network.SetPrefix(bitPerSec.Mibps); timer = new Timer(new TimerCallback(timer_Tick)); }
/// <summary> /// 画面表示用のテキスト作成 /// </summary> /// <returns></returns> public string MonitorState() { lock (sync) { string cpuformat = "{0,6:##0} % ", hddformat = "{0,6:###0.0} MiB/s ", netformat = "{0,6:###0.0} Mibps"; string space = new string(' ', 13); string line; var state = new StringBuilder(); state.AppendLine(" CPU HDD Network"); //Threshold line = ""; line += "Threshold :"; line += queCpu.Enable ? string.Format(cpuformat, queCpu.Threshold) : space; line += queHDD.Enable ? string.Format(hddformat, queHDD.Threshold) : space; line += queNet.Enable ? string.Format(netformat, queNet.Threshold) : space; state.AppendLine(line); //Average line = ""; line += " Average :"; line += queCpu.Enable ? string.Format(cpuformat, queCpu.Average) : space; line += queHDD.Enable ? string.Format(hddformat, queHDD.Average) : space; line += queNet.Enable ? string.Format(netformat, queNet.Average) : space; state.AppendLine(line); //Value line = ""; line += " Value :"; line += queCpu.Enable ? string.Format(cpuformat, queCpu.LatestValue) : space; line += queHDD.Enable ? string.Format(hddformat, queHDD.LatestValue) : space; line += queNet.Enable ? string.Format(netformat, queNet.LatestValue) : space; state.AppendLine(line); //Fill var quelist = new MonitorQueue[] { queCpu, queHDD, queNet }; quelist = quelist.Where((que) => que.Enable).ToArray(); if (quelist.Any()) { line = ""; line += " Fill :"; line += string.Format(" {0,3:##0} / {1,3:##0}", quelist[0].Count, quelist[0].Capacity); state.AppendLine(line); } return(state.ToString()); } }