服务器监控 - 获取服务器信息 [英] server monitoring - get server information

查看:68
本文介绍了服务器监控 - 获取服务器信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如何编写程序来获取服务器信息(例如cpu使用情况)?应该使用什么协议?

[这项工作应该用服务器IP和用户通过,服务器问我们然后服务器给我们提供它的信息。]

谢谢。


how can i write a program to get the server information(example cpu usage)? what protocol should be used?
[this work should be done with "IP of server" and a "user & pass that, server asked us" then server give us its information.]
thank you.

推荐答案

或者你可以试试这个。这是C#!



使用System;

使用System.Collections.Generic;

使用System.ComponentModel;

使用System.Data;

使用System.Drawing;

使用System.Linq;

使用System。文字;

使用System.Windows.Forms;

使用System.Diagnostics;



命名空间CPU_Utilization_Monitor

{

公共部分类Form1:表格

{

public Form1()

{

InitializeComponent();

}



int totalHits = 0;



公共对象getCPUCOunter()

{



PerformanceCounter cpuCounter = new PerformanceCounter();

cpuCounter.CategoryName =Processor;

cpuCounter.CounterName =%Processor Time;

cpuCounter.InstanceName =_ Total;



//将始终从0开始

dynamic firstValue = cpuCounter.NextValue();

System.Threading.Thread.Sleep(1000);

//现在匹配任务管理器阅读

dynamic secondValue = cpuCounter.NextValue();



返回secondValue;



}





private void Timer1_Tick(System.Object sender,System。 EventArgs e)

{

int cpuPercent =(int)getCPUCOunter();

if(cpuPercent> = 90)

{

totalHits = totalHits + 1;

if(totalHits == 60)

MessageBox.Show(ALERT 90%使用1分钟);

totalHits = 0;

}

其他

{

totalHits = 0;

}



label1.Text = cpuPercent +%CPU;

label3。 Text = totalHits +秒数超过20%;



}



}

}
or else you can try this one. It's C#!

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

namespace CPU_Utilization_Monitor
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

int totalHits = 0;

public object getCPUCOunter()
{

PerformanceCounter cpuCounter = new PerformanceCounter();
cpuCounter.CategoryName = "Processor";
cpuCounter.CounterName = "% Processor Time";
cpuCounter.InstanceName = "_Total";

// will always start at 0
dynamic firstValue = cpuCounter.NextValue();
System.Threading.Thread.Sleep(1000);
// now matches task manager reading
dynamic secondValue = cpuCounter.NextValue();

return secondValue;

}


private void Timer1_Tick(System.Object sender, System.EventArgs e)
{
int cpuPercent = (int)getCPUCOunter();
if (cpuPercent >= 90)
{
totalHits = totalHits + 1;
if (totalHits == 60)
MessageBox.Show("ALERT 90% usage for 1 minute");
totalHits = 0;
}
else
{
totalHits = 0;
}

label1.Text = cpuPercent + " % CPU";
label3.Text = totalHits + " seconds over 20% usage";

}

}
}


这篇关于服务器监控 - 获取服务器信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆