コード例 #1
0
ファイル: Form1.cs プロジェクト: borigandi/Gadyushnik
 private void CheckSelectedProcessRAM_Button_Click(object sender, EventArgs e)
 {
     try
     {
         RamInfo.GetRAMInfoSelectedProcess(comboBox1.SelectedItem.ToString());
     }
     catch (Exception)
     {
         MessageBox.Show("Ви не обрали процес!", "УВАГА");
     }
 }
コード例 #2
0
ファイル: HeartBeat.cs プロジェクト: pascal4651/ExamProject
 /// <summary>
 /// Gather all informations about the server and the program
 /// </summary>
 /// <param name="servicename">Name of the service from where this is collected</param>
 /// <param name="programVersion">Versionname of the program/service</param>
 public void CollectData(string servicename, string programVersion)
 {
     this.Servername     = Process.GetCurrentProcess().MachineName;
     this.Disks          = DiskInfo.CollectData().ToArray();
     this.Uptime         = DateTime.Now.Subtract(Process.GetCurrentProcess().StartTime);
     this.Cpu            = CpuInfo.CollectData(this.Uptime);
     this.Ram            = RamInfo.CollectData();
     this.Timestamp      = DateTime.Now;
     this.Servicename    = servicename;
     this.ServiceVersion = programVersion;
 }
コード例 #3
0
ファイル: HeartBeat.cs プロジェクト: pascal4651/ExamProject
            /// <summary>
            /// Collect information about RAM usage
            /// </summary>
            /// <returns>ram information</returns>
            public static RamInfo CollectData()
            {
                RamInfo res = new RamInfo()
                {
                    PagedMemorySize       = Process.GetCurrentProcess().PagedMemorySize64,
                    PagedSystemMemorySize = Process.GetCurrentProcess().PagedSystemMemorySize64,
                    PrivateMemorySize     = Process.GetCurrentProcess().PrivateMemorySize64,
                    PeakPagedMemorySize   = Process.GetCurrentProcess().PeakPagedMemorySize64
                };

                return(res);
            }
コード例 #4
0
        private void OnMachineInfoRequest(INetworkConnection con, Packet packet)
        {
            bool cpu, gpu, drives, mainboard, os, ram;

            cpu = gpu = drives = mainboard = os = ram = false;

            PacketGenericMessage m = packet as PacketGenericMessage;

            m.ReplyPacket = CreateStandardReply(packet, ReplyType.OK, "");

            if (m.Parms.GetBoolProperty("cpu").GetValueOrDefault(false))
            {
                cpu = true;
                CPUInfo ci = MachineInfo.ReadCPUInfo();
                m.ReplyPacket.Parms.SetProperty("cpu", ci.ToString());
            }
            if (m.Parms.GetBoolProperty("gpu").GetValueOrDefault(false))
            {
                gpu = true;
                VideoCardInfo gi = MachineInfo.ReadGPUInfo();
                m.ReplyPacket.Parms.SetProperty("gpu", gi.ToString());
            }
            if (m.Parms.GetBoolProperty("drives").GetValueOrDefault(false))
            {
                drives = true;
                PatcherLib.DriveInfo di = MachineInfo.ReadLogicalDiskInfo();
                m.ReplyPacket.Parms.SetProperty("drives", di.ToString());
            }
            if (m.Parms.GetBoolProperty("mainboard").GetValueOrDefault(false))
            {
                mainboard = true;
                MotherboardInfo mi = MachineInfo.ReadMotherboardInfo();
                m.ReplyPacket.Parms.SetProperty("mainboard", mi.ToString());
            }
            if (m.Parms.GetBoolProperty("os").GetValueOrDefault(false))
            {
                os = true;
                OperatingSystemInfo osr = MachineInfo.ReadOperatingSystemInfo();
                m.ReplyPacket.Parms.SetProperty("os", osr.ToString());
            }
            if (m.Parms.GetBoolProperty("ram").GetValueOrDefault(false))
            {
                ram = true;
                RamInfo ri = MachineInfo.ReadRAMInfo();
                m.ReplyPacket.Parms.SetProperty("ram", ri.ToString());
            }

            if (MachineInfoRequestArrived != null)
            {
                MachineInfoRequestArrived(cpu, gpu, mainboard, drives, os, ram);
            }
        }
コード例 #5
0
        //Form loading Setup
        private void Monitoring_Load(object sender, EventArgs e)
        {
            //Setup the RAM info
            ramProgressBar.Maximum = RamInfo.TotalRamInMB();
            ramAmountLabel.Text    = "Amount of RAM = " + Convert.ToString(Math.Round(RamInfo.TotalRamInMB() / MbInGB, 1)) + "GB";

            //Setup the Computer name for counters
            cpuCounter.MachineName       = compName;
            sysUpTimeCounter.MachineName = compName;

            DiskInfo.CheckDiskC();

            //cpuTemperatureTimer.Start();
        }
コード例 #6
0
        public async Task <ActionResult> GetBaseInfo()
        {
            List <CpuInfo> cpuInfo   = SystemInfo.GetCpuInfo();
            RamInfo        ramInfo   = SystemInfo.GetRamInfo();
            string         osVersion = SystemInfo.GetOsVersion();
            var            total     = new StringBuilder();
            var            free      = new StringBuilder();
            var            usage     = new StringBuilder();

            SystemInfo.DiskTotalSpace().ForEach(kv => { total.Append(kv.Key + kv.Value + " | "); });
            SystemInfo.DiskFree().ForEach(kv => free.Append(kv.Key + kv.Value + " | "));
            SystemInfo.DiskUsage().ForEach(kv => usage.Append(kv.Key + kv.Value.ToString("P") + " | "));
            IList <string> mac  = SystemInfo.GetMacAddress();
            IList <string> ips  = SystemInfo.GetIPAddress();
            var            span = DateTime.Now - CommonHelper.StartupTime;
            var            boot = DateTime.Now - SystemInfo.BootTime();

            return(Content(await new { runningTime = $"{span.Days}天{span.Hours}小时{span.Minutes}分钟", bootTime = $"{boot.Days}天{boot.Hours}小时{boot.Minutes}分钟", cpuInfo, ramInfo, osVersion, diskInfo = new { total = total.ToString(), free = free.ToString(), usage = usage.ToString() }, netInfo = new { mac, ips } }.ToJsonStringAsync().ConfigureAwait(false), "application/json"));
        }
コード例 #7
0
        private static void getRamInfo()
        {
            RamBoardInfoList = new List <RamBoardInfo>();

            ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMemory");

            int    ramFrequency = 0;
            string ramType      = "";

            foreach (var queryObj in searcher.Get())
            {
                var ramBoard = new RamBoardInfo(queryObj["PartNumber"].ToString(), Convert.ToInt64(queryObj["Capacity"]) / 1024 / 1024);
                ramFrequency = Convert.ToInt32(queryObj["Speed"]);
                ramType      = RamTypeToString(Convert.ToInt32(queryObj["MemoryType"]));
                RamBoardInfoList.Add(ramBoard);
            }

            GetPhysicallyInstalledSystemMemory(out long totalRamSize);
            totalRamSize /= 1024;

            ramInfo = new RamInfo(totalRamSize, ramType, ramFrequency, 0);
        }
コード例 #8
0
ファイル: Form1.cs プロジェクト: borigandi/Gadyushnik
 private void CheckAllProcessesRAM_Button_Click(object sender, EventArgs e)
 {
     RamInfo.GetRAMInfoAllProcesses();
 }
コード例 #9
0
        /// <summary>
        /// Creates an anonymous usage record.  This method spends 10 seconds measuring CPU usage.  Returns null if any BlueIris.exe processes close while CPU usage is being measured, or if no BlueIris.exe processes were open.
        /// </summary>
        /// <returns></returns>
        public static Upload_Record GetPerfDataRecord()
        {
            Upload_Record record = new Upload_Record();

            // Begin measuring CPU usage.
            using (PerformanceCounter totalCpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total"))
            {
                totalCpuCounter.NextValue();
                Stopwatch sw = new Stopwatch();
                sw.Start();
                List <Process> biProcs = Process.GetProcesses().Where(p => p.ProcessName.ToLower() == "blueiris").ToList();
                if (biProcs.Count < 1)
                {
                    Logger.Info("Unable to generate anonymous performance data record because Blue Iris is not running.");
                    return(null);
                }
                TimeSpan[] startTimes = new TimeSpan[biProcs.Count];
                for (int i = 0; i < biProcs.Count; i++)
                {
                    startTimes[i] = biProcs[i].TotalProcessorTime;
                }

                // Wait for CPU usage to happen.
                Thread.Sleep(10000);

                // Take CPU usage measurements.
                record.CpuUsage = (byte)Math.Round(totalCpuCounter.NextValue());
                sw.Stop();
                TimeSpan totalTime = TimeSpan.Zero;
                for (int i = 0; i < biProcs.Count; i++)
                {
                    biProcs[i].Refresh();
                    if (biProcs[i].HasExited)
                    {
                        Logger.Info("Unable to generate anonymous performance data record because Blue Iris exited while CPU usage was being measured.");
                        return(null);
                    }
                    totalTime += biProcs[i].TotalProcessorTime - startTimes[i];
                }
                double fraction = totalTime.TotalMilliseconds / sw.Elapsed.TotalMilliseconds;
                record.BiCpuUsage = (byte)Math.Round((fraction / Environment.ProcessorCount) * 100);
                record.CpuThreads = (short)Environment.ProcessorCount;

                long physicalMemUsage = 0;
                long virtualMemUsage  = 0;
                foreach (Process p in biProcs)
                {
                    if (record.BiVersion == null)
                    {
                        record.BiVersion = p.MainModule.FileVersionInfo.FileVersion + " " + (MainSvc.Is64Bit(p) ? "x64" : "x86");
                    }
                    physicalMemUsage += p.WorkingSet64;
                    virtualMemUsage  += p.VirtualMemorySize64;
                }
                record.BiMemUsageMB            = (int)(physicalMemUsage / 1000000);
                record.BiPeakVirtualMemUsageMB = (int)(virtualMemUsage / 1000000);

                foreach (Process p in biProcs)
                {
                    IntPtr handle = p.MainWindowHandle;
                    if (handle == IntPtr.Zero)
                    {
                        // This is the service.
                    }
                    else
                    {
                        // This is the console.
                        record.ConsoleOpen = true;
                        try
                        {
                            WINDOWPLACEMENT placement = new WINDOWPLACEMENT();
                            if (GetWindowPlacement(handle, ref placement))
                            {
                                if (placement.showCmd == 2)
                                {
                                    // Minimized
                                    record.ConsoleWidth  = -2;
                                    record.ConsoleHeight = -2;
                                }
                                else
                                {
                                    // Not Minimized
                                    RECT Rect = new RECT();
                                    if (GetWindowRect(handle, ref Rect))
                                    {
                                        record.ConsoleWidth  = (short)NumberUtil.Clamp(Rect.right - Rect.left, 0, short.MaxValue);
                                        record.ConsoleHeight = (short)NumberUtil.Clamp(Rect.bottom - Rect.top, 0, short.MaxValue);
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Logger.Debug(ex);
                        }
                    }
                }
                if (biProcs.Count > 1 && !record.ConsoleOpen)
                {
                    record.ConsoleOpen = true;
                }
            }

            record.Secret = Program.settings.secret;
            record.OS     = GetOsVersion();
            CpuInfo cpuInfo = GetCpuInfo();

            if (cpuInfo == null)
            {
                record.CpuModel = "Unknown";
                record.CpuMHz   = NumberUtil.ParseInt(cpuInfo.maxClockSpeed);
            }
            else
            {
                record.CpuModel = cpuInfo.GetModel();
                record.CpuMHz   = NumberUtil.ParseInt(cpuInfo.maxClockSpeed);
            }
            record.HelperVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
            record.HwAccel       = (byte)RegistryUtil.GetHKLMValue <int>(@"SOFTWARE\Perspective Software\Blue Iris\Options", "hwaccel", 0);
            record.ServiceMode   = RegistryUtil.GetHKLMValue <int>(@"SOFTWARE\Perspective Software\Blue Iris\Options", "Service", 0) == 1;
            if (RegistryUtil.GetHKLMValue <int>(@"SOFTWARE\Perspective Software\Blue Iris\Options", "limitlive", 0) == 0)
            {
                record.LivePreviewFPS = -2;
            }
            else
            {
                record.LivePreviewFPS = (short)RegistryUtil.GetHKLMValue <int>(@"SOFTWARE\Perspective Software\Blue Iris\Options", "livefps", -1);
            }

            ComputerInfo computerInfo = new ComputerInfo();

            record.MemMB     = (int)(computerInfo.TotalPhysicalMemory / 1000000);
            record.MemFreeMB = (int)(computerInfo.AvailablePhysicalMemory / 1000000);

            RamInfo ramInfo = GetRamInfo();

            record.RamGiB        = ramInfo.GiB;
            record.RamChannels   = ramInfo.Channels;
            record.DimmLocations = ramInfo.DimmLocations;
            record.RamMHz        = ramInfo.MHz;

            // Get camera info.
            // Get frame rates (only accessible via BI's web server).
            Dictionary <string, double> fpsMap = new Dictionary <string, double>();

            BiServerInfo.Reload();
            if (BiServerInfo.enabled)
            {
                try
                {
                    using (WebClient wc = new WebClient())
                    {
                        string session  = CameraWebInterfaceLinker.GetSecureAuthenticatedSession(wc);
                        string response = wc.UploadString(CameraWebInterfaceLinker.GetJsonURL(), "{\"cmd\":\"camlist\",\"session\":\"" + session + "\"}");
                        wc.UploadString(CameraWebInterfaceLinker.GetJsonURL(), "{\"cmd\":\"logout\",\"session\":\"" + session + "\"}");
                        CamListResponse camListResponse = JsonConvert.DeserializeObject <CamListResponse>(response);
                        if (camListResponse != null && camListResponse.result == "success")
                        {
                            foreach (CameraListCamera camera in camListResponse.data)
                            {
                                if (camera.group == null)
                                {
                                    fpsMap[camera.optionValue] = camera.FPS;
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.Debug(ex, "Error reading camera list from web server.");
                }
            }

            // Get camera info from registry
            List <Upload_Camera> cameras = new List <Upload_Camera>();

            RegistryKey camerasKey = RegistryUtil.GetHKLMKey(@"SOFTWARE\Perspective Software\Blue Iris\Cameras");

            foreach (string camName in camerasKey.GetSubKeyNames())
            {
                RegistryKey camKey = camerasKey.OpenSubKey(camName);
                if (RegistryUtil.GetIntValue(camKey, "enabled", 0) != 1)
                {
                    continue;
                }
                string        shortName = RegistryUtil.GetStringValue(camKey, "shortname");
                Upload_Camera cam       = new Upload_Camera();

                if (fpsMap.TryGetValue(shortName, out double fps))
                {
                    cam.FPS = (byte)NumberUtil.Clamp(Math.Round(fps), 0, 255);
                }
                else
                {
                    int interval = RegistryUtil.GetIntValue(camKey, "interval", 1000000);
                    if (interval <= 0)
                    {
                        cam.FPS = 0;
                    }
                    else
                    {
                        cam.FPS = (byte)NumberUtil.Clamp(Math.Round(10000000.0 / interval), 0, 255);
                    }
                }
                cam.CapType     = (byte)RegistryUtil.GetIntValue(camKey, "screencap", 0);
                cam.Hwaccel     = (byte)RegistryUtil.GetIntValue(camKey, "ip_hwaccel", 0);
                cam.LimitDecode = RegistryUtil.GetIntValue(camKey, "smartdecode", 0) == 1;
                cam.Pixels      = RegistryUtil.GetIntValue(camKey, "fullxres", 0) * RegistryUtil.GetIntValue(camKey, "fullyres", 0);
                cam.Type        = (byte)RegistryUtil.GetIntValue(camKey, "type", 0);
                RegistryKey motionKey = camKey.OpenSubKey("Motion");
                cam.MotionDetector    = RegistryUtil.GetIntValue(motionKey, "enabled", 0) == 1;
                cam.RecordTriggerType = (byte)RegistryUtil.GetIntValue(motionKey, "continuous", 0);
                RegistryKey clipsKey = camKey.OpenSubKey("Clips");
                cam.RecordFormat = (byte)RegistryUtil.GetIntValue(clipsKey, "movieformat", 0);
                cam.DirectToDisk = RegistryUtil.GetIntValue(clipsKey, "transcode", 0) == 0;
                cam.VCodec       = RegistryUtil.GetStringValue(clipsKey, "vcodec");
                cameras.Add(cam);
            }

            record.cameras = cameras.ToArray();
            record.gpus    = GetGpuInfo().Select(g => new Upload_Gpu()
            {
                Name = g.Name, Version = g.DriverVersion
            }).ToArray();

            return(record);
        }
コード例 #10
0
 //Calculating the free RAM
 private void ramcount()
 {
     ramProgressBar.Text  = Convert.ToString(Math.Round(RamInfo.FreeRamInMB() / MbInGB, 1)) + " GB";
     ramProgressBar.Value = RamInfo.FreeRamInMB();
 }