Ejemplo n.º 1
0
        public async Task <CollectedData> Collect()
        {
            CollectedData dataItem = null;

            try
            {
                var allProcesses = await GetProcesses();

                dataItem = new CollectedData
                {
                    InterruptsPerSeconds  = (float)Math.Round(_systemCounters["Interrupts"].NextValue(), 2),
                    InterruptsTimePercent = (float)Math.Round(_systemCounters["InterruptsTime"].NextValue(), 2),

                    TotalRamMBytes     = (float)Math.Round(_totalRamMbyte, 2),
                    RamUsagePercentage = (float)Math.Round(100 - (_systemCounters["FreeRam"].NextValue() / (_totalRamMbyte / 100)), 2),
                    UsageRamMBytes     = (float)Math.Round(_totalRamMbyte - _systemCounters["FreeRam"].NextValue(), 2),

                    CpuUsagePercentage = (float)Math.Round(_systemCounters["CPU"].NextValue(), 2),

                    LocalDiskTotalMBytes     = (float)Math.Round(GetDiskTotalMbytes()),
                    LocalDiskUsageMBytes     = (float)Math.Round(GetDiskUsageMbytes()),
                    LocalDiskUsagePercentage = (float)Math.Round(100 - _systemCounters["LocalDisk"].NextValue(), 2),

                    Processes      = allProcesses,
                    ProcessesCount = allProcesses.Count,
                    Time           = DateTime.Now
                };
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            return(dataItem);
        }
Ejemplo n.º 2
0
        public async Task <CollectedData> Collect()
        {
            CollectedData dataItem = null;

            try
            {
                var allProcesses = await GetProcesses();

                dataItem = new CollectedData
                {
                    //InterruptsPerSeconds = _systemCounters["Interrupts"].NextValue(),
                    //InterruptsTimePercent = _systemCounters["InterruptsTime"].NextValue(),

                    TotalRamMBytes     = (float)Math.Round(GetTotalRam(), 2),
                    RamUsagePercentage = (float)Math.Round(GetUsageRamPercentages(), 2),
                    UsageRamMBytes     = (float)Math.Round(GetUsageRam(), 2),

                    CpuUsagePercentage = (float)Math.Round(GetUsageCpuPercentages(), 2),

                    LocalDiskTotalMBytes     = (float)Math.Round(GetDiskTotalMbytes(), 2),
                    LocalDiskUsageMBytes     = (float)Math.Round(GetDiskTotalMbytes() - GetDiskFreeMbytes(), 2),
                    LocalDiskUsagePercentage = (float)Math.Round(GetLocalDiskUsagePercent(), 2),

                    Processes      = allProcesses,
                    ProcessesCount = allProcesses.Count,
                    Time           = DateTime.Now
                };
            }
            catch (Exception)
            {
                // ignored
            }
            return(dataItem);
        }
Ejemplo n.º 3
0
        private void TestData(CollectedData date)
        {
            float cpu  = 0;
            float ram  = 0;
            float pram = 0;

            foreach (var item in date.Processes)
            {
                cpu  += item.PCpu;
                ram  += item.RamMBytes;
                pram += item.PRam;
            }
            System.Console.WriteLine($"cpu:{cpu} \t ram:{ram} \t pram:{pram}");
        }
Ejemplo n.º 4
0
        public async Task <bool> SendAsync(CollectedData dataItem)
        {
            TestData(dataItem);
            var myContent = JsonConvert.SerializeObject(dataItem);

            var buffer = Encoding.UTF8.GetBytes(myContent);

            var byteContent = new ByteArrayContent(buffer);

            byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            var response = await _client.PostAsync(_uri, byteContent);

            return(response.StatusCode == HttpStatusCode.Created);
        }