public DataSources(List<Meter> meters) { prevFileCheck = new Dictionary<string, DateTime>(); prevFileValue = new Dictionary<string, int>(); monitor = new NetworkMonitor(); adapters = monitor.Adapters; MEMORYSTATUSEX memStatus = new MEMORYSTATUSEX(); if (GlobalMemoryStatusEx(memStatus)) TotalRAM = (int)((float)memStatus.ullTotalPhys / 1024 / 1024); bool startedMonitoring = false; foreach (Meter meter in meters) switch (meter.Data) { case "CPU usage": if (cpuCounter == null) { cpuCounter = new PerformanceCounter(); cpuCounter.CategoryName = "Processor"; cpuCounter.CounterName = "% Processor Time"; cpuCounter.InstanceName = "_Total"; } break; case "Available memory": case "Used memory": if (ramCounter == null) ramCounter = new PerformanceCounter("Memory", "Available MBytes"); break; case "Recycle bin file count": case "Recycle bin size": binQuery = new SHQUERYRBINFO(); break; case "Download speed": case "Upload speed": if (!startedMonitoring) { monitor.StartMonitoring(); startedMonitoring = true; } break; case "System volume": case "Audio peak level": if (audioDevice == null) { MMDeviceEnumerator DevEnum = new MMDeviceEnumerator(); audioDevice = DevEnum.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eMultimedia); } break; } }
private static void networkUsage_DoWork(object sender, DoWorkEventArgs e) { try { Dictionary<String, object> objArgument = (Dictionary<String, object>)e.Argument; List<String> arguements = (List<String>)objArgument["DefragArguements"]; string logpath = string.Empty; monitor = new NetworkMonitor(); adapters = monitor.Adapters; CsvRow row = CheckBandwidthUsage(System.DateTime.Now); //Usage File Path if (row != null) { string strpath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\" + ConfigurationManager.AppSettings["ClientName"]; //string strpath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\" + Globals.ProductName; if (!Directory.Exists(strpath)) { Directory.CreateDirectory(strpath); } logpath = strpath +"\\"+ (@"NetworkUsage.csv"); ThreadPool.QueueUserWorkItem(new WaitCallback(delegate(object state) { csvFileWiter.WriteRow(row, logpath); })); } } catch (Exception Ex) { WriteLog("Log Path :: " + Ex); } finally { if (csvFileWiter != null) { } } }
private static Dictionary<string, double> NetworkUsage() { Dictionary<string, double> temp = new Dictionary<string, double>(); double DownloadSpeed = 0; double UploadSpeed = 0; NetworkMonitor monitor = new NetworkMonitor(); NetworkAdapter[] adapters = monitor.Adapters; // Start a timer to obtain new performance counter sample every second. monitor.StartMonitoring(); for (int i = 0; i < 10; i++) { foreach (NetworkAdapter adapter in adapters) { // The DownloadSpeedKbps and UploadSpeedKbps are // double values. DownloadSpeed += adapter.DownloadSpeedKbps; UploadSpeed += adapter.UploadSpeedKbps; } System.Threading.Thread.Sleep(1000); // Sleeps for one second. } // Stop the timer. Properties of adapter become invalid. monitor.StopMonitoring(); temp.Add("upload", (UploadSpeed/8)*1024); temp.Add("download", (DownloadSpeed/8)*1024); return temp; }
private NetworkAdapter[] FoundNetworkAdapter() { _monitor = new NetworkMonitor(); var adaptersTemp = _monitor.Adapters; return adaptersTemp; }