Exemplo n.º 1
0
        public void InitializeNICs()
        {
            var nics = new PerformanceCounterCategory("Network Interface").GetInstanceNames();

            if (nics.Any())
            {
                foreach (var nic in nics)
                {
                    sentPerformanceCounters.Add(new PerformanceCounter("Network Interface", "Bytes Sent/sec", nic));
                    receivePerformanceCounters.Add(new PerformanceCounter("Network Interface", "Bytes Received/sec", nic));
                }

                ReadNicDataFromDatabase();
            }
            else
            {
                _logger.LogDebug("No NICs found");
            }
        }
Exemplo n.º 2
0
        private List <ProcessUsage> GetProcessNames()
        {
            var processesNames = new PerformanceCounterCategory("Process").GetInstanceNames().Distinct();
            var processes      = Process.GetProcesses(".")
                                 .Where(x => processesNames.Any(pn => pn == x.ProcessName))
                                 .GroupBy(g => g.ProcessName);
            List <ProcessUsage> pcList = new List <ProcessUsage>()
            {
                new ProcessUsage {
                    ProcessName = "_Total"
                }
            };

            foreach (var pg in processes)
            {
                var pName = Process.GetProcessesByName(pg.Key);
                if (pg.Count() == 1)
                {
                    pcList.Add(new ProcessUsage
                    {
                        ProcessName = pg.First().ProcessName,
                        Pid         = pg.First().Id
                    });
                }
                else
                {
                    int id = 1;
                    foreach (var p in pg)
                    {
                        pcList.Add(new ProcessUsage
                        {
                            ProcessName = p.ProcessName + "#" + id,
                            Pid         = p.Id
                        });
                        id++;
                    }
                }
            }

            return(pcList);
        }