コード例 #1
0
        private void PopulateStaticStatTable()
        {
            CommandResultTuple usageCmdResult = null;

            MiscTools.SpawnBackgroundWorker(() => usageCmdResult = ManagerHandler.SshHandler.RunCommand("mpstat -o JSON"), () =>
            {
                if (usageCmdResult.ExitCode == 0)
                {
                    var result = JsonConvert.DeserializeObject <MPStatResult>(usageCmdResult.StdOut);
                    // hostname --I | sed 's/ /\\n/' | head -n 1
                    var localip = ManagerHandler.SshHandler.RunCommandSafe("hostname --ip-address | head -n 1").StdOut;
                    var extip   = ManagerHandler.SshHandler.RunCommandSafe("curl ipinfo.io/ip").StdOut;

                    var host = result.SysStat.Hosts[0];

                    this.Invoke((MethodInvoker)(() =>
                    {
                        hostName_Label.Text = host.NodeName;
                        os_Label.Text = host.SysName;
                        osVersion_Label.Text = host.Release;
                        architecture_Label.Text = host.Machine;
                        localIP_Label.Text = localip;
                        externalIP_Label.Text = extip;
                    }));
                }
            });
        }
コード例 #2
0
        private void PopulateCpuUsageTable()
        {
            CommandResultTuple cmdresult = null;

            MiscTools.SpawnBackgroundWorker(() => cmdresult = ManagerHandler.SshHandler.RunCommand("mpstat -o JSON"), () =>
            {
                if (cmdresult.ExitCode == 0)
                {
                    var result     = JsonConvert.DeserializeObject <MPStatResult>(cmdresult.StdOut);
                    var numthreads = result.SysStat.Hosts[0].NumberOfCpus;

                    _CpuUsageTableControls = new Control[3, numthreads];

                    _CpuUsageTableControls       = new Control[3, numthreads + 1];
                    _CpuUsageTableControls[0, 0] = averageCpuUsage_Label;
                    _CpuUsageTableControls[1, 0] = averageCpuUsage_ProgressBar;
                    _CpuUsageTableControls[2, 0] = averageCpuFreq_Label;


                    for (int i = 0; i < numthreads; i++)
                    {
                        var rowstyle = new RowStyle(SizeType.Absolute, 20);
                        this.Invoke((MethodInvoker)(() =>
                        {
                            cpuLoad_TableLayoutPanel.RowCount += 1;
                            cpuLoad_TableLayoutPanel.RowStyles.Add(rowstyle);

                            var threadNumLbl = new Label {
                                Text = "" + i, AutoSize = true
                            };
                            var usageProgBar = new ProgressBar {
                                Dock = DockStyle.Fill
                            };
                            var freqLbl = new Label {
                                Text = "? MHz", AutoSize = true
                            };

                            _CpuUsageTableControls[0, i + 1] = threadNumLbl;
                            _CpuUsageTableControls[1, i + 1] = usageProgBar;
                            _CpuUsageTableControls[2, i + 1] = freqLbl;

                            cpuLoad_TableLayoutPanel.Controls.Add(threadNumLbl);
                            cpuLoad_TableLayoutPanel.Controls.Add(usageProgBar);
                            cpuLoad_TableLayoutPanel.Controls.Add(freqLbl);
                        }));
                    }
                    this.Invoke((MethodInvoker)(() =>
                    {
                        cpuLoad_TableLayoutPanel.RowCount += 1;
                        cpuLoad_TableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Percent));
                    }));
                }
            });
        }