1

I want to develop program that can monitor many Unix client's CPU/Memory share.
A Unix client program written in C runs the command popen to get CPU / memory information and send it to the server using sockets.

Example, On Solaris 11, use the following command to get CPU / Memory information.

CPU : top -n 1 |grep "CPU"|sed -n 1p|awk '{print $3}'|sed 's/[^0-9.0-9]//g'|awk '{print 100-$1}'
Memory : top -n 1 |grep \"Mem\" |awk '{print $2, $5}'|sed 's/[^0-9]/ /g'|awk '{print $2/$1*100}'

There is a problem here.
Solaris 9, 10 have no top command.
HP-UX can not use grep because it can not execute commands once.
AIX's topas, too.

If you have other command or way, please recommend to me.

김진영
  • 57
  • 1
  • 5
  • did you check the `apropos` cmd to find similar services for top (that really suprizes me, but Solaris doc doesn't list top). But more importantly each pipeline can be reduced to 1 `awk` program, i.e. top | awk '/Mem/{gsub(/[^0-9]/," ");print $2/$1*100}'` You'll need to rearrange your $2,$5, etc so you really get the output you want. Good luck. – shellter May 30 '18 at 04:33
  • 5
    Solaris: `prstat`. Many systems monitoring solutions have agents that do exactly that, and some of there are OpenSourced so you could have a look. Ex. Zabbix, Nagios. But note that the vast majority of these tools (including paid ones) do not work properly on partions, virtual systems, cloud systems, ... They do not have access to the hyper visor data so they report numbers that do not mean anything. Ex. 50% of CPU when the entitlement changes is not the same as time goes by. Impossible to compare. – Nic3500 Jun 09 '18 at 00:36

1 Answers1

1

You know in HP-UX you can use a glance. And you can use top but it is a not better decision.

noute
  • 114
  • 3
  • 13