English 中文(简体)
如何获得CPU/Processor使用计算机的平均数?
原标题:How to get the average CPU/Processor Usage of a computer?

现在,Im正在与PHP和Perl一起开展一项方案,读到计算机系统数据,我们一直在利用SNMP收集数据(或被迫数据)。 在检索数据之后,我们本应将数据储存在数据库中,然后利用数据绘制线图。

目前,Im使用这种手稿检索CPU/Processor使用计算机。

  $MIB1 = ".1.3.6.1.2.1.25.3.3.1.2"; #Cpu Processors
  $HOST = shift; #or localhost for testing

  $count = 0;
      #print out all the processors of the computer and their values
      #SNMP is used with perl because of the libraries
      #snmpwalk retrieves information from the computers by the computer name and MIB
      #as there are many values, they are stored in an array to be used
      (@values) = &snmpwalk("$HOST","$MIB1");
      foreach $value (@values)
      {
          $count++;
          if ($value) {
              #fixes the value for presentation
              $goodvalue = &strip_comment($value);
              #prints out the result. $count will count out the processor number
              print "CPU Usage of Processor $count: $goodvalue%
"; }
              if ($value > 90){
                  #warns user if the processor usage is over 90%
                  print "Warning: CPU Usage over 90%! 
"
              }
          else { warn "No response from host :$HOST:
"; } #provides error
      }

或者说,国家计算机程序系统检索了一些个人处理器,许多人应当知道,在一台计算机上可以有许多处理器,因此将这一数据储存在一个数据库中并不十分实用(例如,如果一台计算机只有2个处理器,下台有4个,整个会议室有100个)。

因此,我不禁要问,谁能帮助改进这一法典或加以修改,以便我能够把所有这些内容加在一起,并找到通用的万国邮联/加工商使用工具并将其储存在数据库中。 因为我不敢肯定如何去做,因为当时只有1名加工商的通道扫描,可能不知道有多少人。

提前感谢。

问题回答

利用东道方和小区块作为双重关键,而一个集团则获得平均数。

这方面的例子有三轮驱动力。

第一编:

CREATE TABLE cpu (host string, cpu integer, load integer, primary key (host, cpu));

然后插入一些测试数据(用您的手稿进行):

INSERT INTO cpu (host, cpu, load) VALUES ("appserv", 1, 25);
INSERT INTO cpu (host, cpu, load) VALUES ("appserv", 2, 15);
INSERT INTO cpu (host, cpu, load) VALUES ("dbserv", 1, 10);
INSERT INTO cpu (host, cpu, load) VALUES ("dbserv", 2, 30);
INSERT INTO cpu (host, cpu, load) VALUES ("dbserv", 3, 5);
INSERT INTO cpu (host, cpu, load) VALUES ("dbserv", 4, 5);

现在,你们可以找到每个东道国的平均装载量,这些载荷可以用购买力平价检索和规划:

SELECT host, avg(load) FROM cpu GROUP BY host;

appserv|20.0
dbserv|12.5

所有东道国的总平均数:

SELECT avg(load) FROM cpu;

15.0

或者发现任何高负荷的东道方:

SELECT host FROM cpu WHERE load > 25;

dbserv

您很可能想提出一个您所有电脑的表格,并将其与上述表格连接起来,与一台电脑交换主机。

所有这些都假设你重新使用一个关系数据库(即MySQL、Oracle等)。





相关问题
Why does my chdir to a filehandle not work in Perl?

When I try a "chdir" with a filehandle as argument, "chdir" returns 0 and a pwd returns still the same directory. Should that be so? I tried this, because in the documentation to chdir I found: "...

How do I use GetOptions to get the default argument?

I ve read the doc for GetOptions but I can t seem to find what I need... (maybe I am blind) What I want to do is to parse command line like this myperlscript.pl -mode [sth] [inputfile] I can use ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...

热门标签