Esempio n. 1
0
        public override CPUReport GetReport(int deviceID, IStartEndTime start_end)
        {
            CPUReport report = null;
            IEnumerable <DeviceData> data = DB.GetDeviceData(deviceID, ECollectorType.CPUUsage, start_end);

            //var definition = new { Value = string.Empty };

            foreach (DeviceData d in data)
            {
                try
                {
                    //var value = JsonConvert.DeserializeAnonymousType(d.value, definition);
                    var    value       = JsonConvert.DeserializeObject <ValueClass <string> >(d.value);
                    string percent_str = value.Value;
                    if (long.TryParse(percent_str, out long percent))
                    {
                        if (report == null)
                        {
                            report = new CPUReport();
                        }
                        report.Insert((int)percent, d.timeStamp);
                    }
                }
                catch (Exception)
                {
                }
            }

            return(report);
        }
Esempio n. 2
0
        private AllApplicationsHistory GetAppChanges(int deviceID, IStartEndTime start_end)
        {
            Database db = new Database();
            AllApplicationsHistory changes = db.GetApplicationChanges(deviceID, start_end);

            return(changes);
        }
Esempio n. 3
0
        private List <string> GetAllProcesses(int deviceID, IStartEndTime start_end)
        {
            Database      db        = new Database();
            List <string> processes = db.GetAllDeviceProcesses(deviceID, start_end);

            return(processes);
        }
Esempio n. 4
0
        public override DiskReport GetReport(int deviceID, IStartEndTime start_end)
        {
            IEnumerable <DeviceData> data = DB.GetDeviceData(deviceID, ECollectorType.Disk, start_end);
            //var definition = new { Value = new Dictionary<string, Dictionary<string, string>>() };
            Dictionary <string, DiskReport.DiskInfo> disk_info = new Dictionary <string, DiskReport.DiskInfo>(StringComparer.InvariantCultureIgnoreCase);

            foreach (DeviceData d in data)
            {
                try
                {
                    //var value = JsonConvert.DeserializeAnonymousType(d.value, definition);
                    var           value = JsonConvert.DeserializeObject <DictToDictValue <string, string, string> >(d.value);
                    List <string> disks = value.Value.Keys.ToList();
                    disks.Sort();

                    foreach (string disk in disks)
                    {
                        Dictionary <string, string> disk_data = value.Value[disk];

                        if (disk_info.TryGetValue(disk, out DiskReport.DiskInfo info) == false)
                        {
                            info            = new DiskReport.DiskInfo(disk);
                            disk_info[disk] = info;
                        }

                        if (disk_data.TryGetValue("Used", out string used_str) &&
                            disk_data.TryGetValue("Capacity", out string capacity_str))
                        {
                            if (long.TryParse(used_str, out long used) &&
                                long.TryParse(capacity_str, out long capacity) &&
                                capacity > 0)
                            {
                                int percent_used = (int)((double)used / (double)capacity * 100.0);
                                info.Insert(percent_used, d.timeStamp);
                            }
                        }
                    }
                }
                catch (Exception)
                {
                }
            }

            DiskReport    report    = null;
            List <string> all_disks = disk_info.Keys.ToList();

            if (all_disks.Count > 0)
            {
                report = new DiskReport();
                all_disks.Sort();
                all_disks.ForEach(d => report.disks.Add(disk_info[d]));
            }

            return(report);
        }
Esempio n. 5
0
        public override MemoryReport GetReport(int deviceID, IStartEndTime start_end)
        {
            MemoryReport             report = null;
            IEnumerable <DeviceData> data   = DB.GetMemoryData(deviceID, start_end);

            foreach (DeviceData d in data)
            {
                try
                {
                    var value = JsonConvert.DeserializeObject <DictValue <string, string> >(d.value);
                    if (value != null)
                    {
                        ProcessValue(ref report, d, value.Value);
                    }
                }
                catch (Exception)
                {
                }
            }

            return(report);
        }
Esempio n. 6
0
        public List <NetworkStatus> GetNetworkStatuses(IStartEndTime start_end)
        {
            List <NetworkStatus> statuses = new List <NetworkStatus>();
            DateTimeOffset       dt       = new DateTimeOffset(2017, 10, 23, 11, 42, 33, TimeSpan.FromHours(-6));

            statuses.Add(new NetworkStatus()
            {
                name                       = "Status A1",
                deviceID                   = 2,
                successfulPing             = true,
                dateSuccessfulPingOccurred = dt,
                datePingAttempted          = dt,
                ipAddress                  = "1.2.3.4",
                hasBeenPinged              = true,
            });
            statuses.Add(new NetworkStatus()
            {
                name                       = "Status A2",
                deviceID                   = 15,
                successfulPing             = false,
                dateSuccessfulPingOccurred = dt,
                datePingAttempted          = dt,
                ipAddress                  = "2.3.4.5",
                hasBeenPinged              = true,
            });
            statuses.Add(new NetworkStatus()
            {
                name                       = "Status A3",
                deviceID                   = 11,
                successfulPing             = false,
                dateSuccessfulPingOccurred = null,
                datePingAttempted          = dt,
                ipAddress                  = "3.4.5.6",
                hasBeenPinged              = false,
            });

            return(statuses);
        }
Esempio n. 7
0
        private ReportData GetCPUReport(int deviceID, string reportTypes, IStartEndTime start_end)
        {
            EReportSubType[] types = JsonConvert.DeserializeObject <EReportSubType[]>(reportTypes);
            ReportData       rd    = new ReportData(deviceID, start_end);
            Database         db    = new Database();

            foreach (EReportSubType type in types)
            {
                switch (type)
                {
                case EReportSubType.Memory:
                    Memory m = new Memory(db);
                    rd.memory = m.GetReport(deviceID, start_end);
                    break;

                case EReportSubType.Disk:
                    Disk d = new Disk(db);
                    rd.disk = d.GetReport(deviceID, start_end);
                    break;

                case EReportSubType.CPU:
                    CPU c = new CPU(db);
                    rd.cpu = c.GetReport(deviceID, start_end);
                    break;

                case EReportSubType.NIC:
                    NIC n = new NIC(db);
                    rd.nic = n.GetReport(deviceID, start_end);
                    break;

                default:
                    break;
                }
            }

            return(rd);
        }
Esempio n. 8
0
        public override NICReport GetReport(int deviceID, IStartEndTime start_end)
        {
            NICReport report = null;
            IEnumerable <DeviceData> data = DB.GetDeviceData(deviceID, ECollectorType.NICUsage, start_end);

            //var definition = new { Value = new Dictionary<string, string>() };

            foreach (DeviceData d in data)
            {
                try
                {
                    //var value = JsonConvert.DeserializeAnonymousType(d.value, definition);
                    var value = JsonConvert.DeserializeObject <DictValue <string, string> >(d.value);
                    if (value.Value.TryGetValue("Avg", out string avg_str) &&
                        value.Value.TryGetValue("BPS", out string bps_str))
                    {
                        double avg;
                        Int64  bps;
                        if (double.TryParse(avg_str, out avg) &&
                            Int64.TryParse(bps_str, out bps))
                        {
                            if (report == null)
                            {
                                report = new NICReport();
                            }
                            report.Insert((int)(avg + 0.5f), d.timeStamp, (int)bps);
                        }
                    }
                }
                catch (Exception)
                {
                }
            }

            return(report);
        }
Esempio n. 9
0
 public List <DeviceData> GetDeviceData(long deviceID, ECollectorType collectorType, IStartEndTime start_end)
 {
     return(new List <DeviceData>());
 }
Esempio n. 10
0
        public List <DeviceData> GetDeviceData(long deviceID, ECollectorType collectorType, IStartEndTime start_end)
        {
            List <DeviceData> device_data = new List <DeviceData>();

            device_data.Add(new DeviceData()
            {
                collectorID = 2233, dataID = 3344, timeStamp = DateTimeOffset.Now.AddHours(-6), value = "{}"
            });
            return(device_data);
        }
Esempio n. 11
0
        private MachineData GetMachineData(int deviceID, string machineParts, IStartEndTime start_end)
        {
            EMachinePart[] parts = JsonConvert.DeserializeObject <EMachinePart[]>(machineParts);
            MachineData    md    = new MachineData(deviceID, start_end);
            Database       db    = new Database();

            foreach (EMachinePart part in parts)
            {
                switch (part)
                {
                case EMachinePart.CPU:
                    md.cpu = GetDeviceData($"GetCPUData {deviceID}", deviceID, ECollectorType.CPUUsage, start_end);
                    break;

                case EMachinePart.Memory:
                    md.memory = GetMemoryData($"GetMemoryData {deviceID}", deviceID, start_end, db);
                    break;

                case EMachinePart.DiskUsage:
                {
                    Dictionary <string, List <DiskUsageData> > data = db.GetDiskData(deviceID, start_end);
                    List <HardDisk> smart = db.GetSMARTData(deviceID);

                    Dictionary <string, DiskUsageWithSmartData> disk_dict = new Dictionary <string, DiskUsageWithSmartData>();
                    foreach (KeyValuePair <string, List <DiskUsageData> > dvp in data)
                    {
                        string drive_letter         = dvp.Key.Trim();
                        DiskUsageWithSmartData disk = new DiskUsageWithSmartData()
                        {
                            driveLetter = dvp.Key,
                            diskUsage   = dvp.Value,
                        };
                        HardDisk hd = smart.Find(s => s.DriveLetters.Contains(drive_letter));
                        if (hd != null)
                        {
                            disk.smartData = hd;
                        }

                        disk_dict[drive_letter] = disk;
                    }
                    md.diskUsage = disk_dict;
                }
                break;

                case EMachinePart.DiskPerformance:
                {
                    List <DeviceData> dataList = GetDeviceData($"DiskSpeed {deviceID}", deviceID, ECollectorType.DiskSpeed, start_end);
                    Dictionary <string, List <DeviceData> > dictData = new Dictionary <string, List <DeviceData> >();
                    foreach (var data in dataList)
                    {
                        DictionaryData d        = JsonConvert.DeserializeObject <DictionaryData>(data.value);
                        string         diskName = string.Empty;
                        if (d != null && d.Data.TryGetValue("Disk Name", out diskName))
                        {
                            List <DeviceData> datalist = null;
                            if (dictData.TryGetValue(diskName, out datalist) == false)
                            {
                                datalist           = new List <DeviceData>();
                                dictData[diskName] = datalist;
                            }
                            datalist.Add(data);
                        }
                    }
                    md.diskPerformance = dictData;
                }
                break;

                case EMachinePart.NIC:
                    md.nic = GetDeviceData($"GetNICData {deviceID}", deviceID, ECollectorType.NICUsage, start_end);
                    break;

                case EMachinePart.SystemErrors:
                    md.systemErrors = db.GetSystemErrors(deviceID, start_end);
                    break;

                case EMachinePart.ApplicationErrors:
                    md.applicationErrors = db.GetApplicationErrors(deviceID, start_end);
                    break;

                case EMachinePart.Processes:
                    md.processes = db.GetDeviceProcesses(deviceID);
                    break;

                case EMachinePart.Database:
                    md.database = db.GetMostRecentValueForDevice(deviceID, ECollectorType.DatabaseSize);
                    break;

                case EMachinePart.Applications:
                    md.applications = db.GetDeviceApplications(deviceID);
                    break;

                case EMachinePart.Services:
                {
                    ValueInfo v          = db.GetMostRecentValueForDevice(deviceID, ECollectorType.Services);
                    var       definition = new { Value = new List <string>() };
                    var       value      = JsonConvert.DeserializeAnonymousType(v.value, definition);

                    md.services = new Services(value.Value)
                    {
                        timestamp = v.timestamp
                    };
                }
                break;

                case EMachinePart.UPS:
                    md.ups = GetDeviceData($"GetUpsData {deviceID}", deviceID, ECollectorType.UPS, start_end);
                    break;

                case EMachinePart.NumMachineParts:
                    break;

                default:
                    break;
                }
            }

            return(md);
        }
Esempio n. 12
0
        private List <NetworkStatus> GetNetworkStatus(IStartEndTime start_end)
        {
            List <NetworkStatus> statuses = m_repo.GetNetworkStatuses(start_end);

            return(statuses);
        }
Esempio n. 13
0
        private List <DeviceData> GetMemoryData(string header, long deviceID, IStartEndTime start_end, Database db)
        {
            List <DeviceData> data = db.GetMemoryData(deviceID, start_end);

            return(data);
        }
Esempio n. 14
0
        private List <DeviceData> GetDeviceData(string header, long deviceID, ECollectorType collectorType, IStartEndTime start_end)
        {
            //Stopwatch watch = Stopwatch.StartNew();
            List <DeviceData> data = m_repo.GetDeviceData(deviceID, collectorType, start_end);

            return(data);
        }
Esempio n. 15
0
 public abstract T GetReport(int deviceID, IStartEndTime start_end);
Esempio n. 16
0
 public List <NetworkStatus> GetNetworkStatuses(IStartEndTime start_end)
 {
     return(new List <NetworkStatus>());
 }
Esempio n. 17
0
 public ReportData(int deviceID, IStartEndTime start_end)
 {
     id       = deviceID;
     startEnd = start_end;
 }
Esempio n. 18
0
 public MachineData(int deviceID, IStartEndTime start_end)
 {
     id       = deviceID;
     startEnd = start_end;
 }