4

I want to extract some fields out of output of command xentop. It's like top command; provides an ongoing look at cpu usage,memory usage,...in real time. If I run this command in batch mode, I will have its output as you see in a file:

      NAME  STATE   CPU(sec) CPU(%)     MEM(k) MEM(%)  MAXMEM(k) MAXMEM(%) VCPUS NETS NETTX(k) NETRX(k) VBDS   VBD_OO   VBD_RD   VBD_WR  VBD_RSECT  VBD_WSECT SSID
  Domain-0 -----r      13700   33.0    7127040   85.9   no limit       n/a     8    0        0        0    0        0        0        0          0          0    0
     fed18 -----r        738  190.6    1052640   12.7    1052672      12.7     3    1   259919     8265    1        0    82432    22750    2740966    1071672    0

and running this

cat file| tr '\r' '\n' | sed 's/[0-9][;][0-9][0-9][a-Z]/ /g' | col -bx | awk '{print $1,$4,$6}'

on this file gives me what I want

NAME CPU(%) MEM(%)
Domain-0 33.0 85.9
fed18 190.6 12.7

but my script doesn't work on realtime output of xentop. I even tried to just run xentop one time by setting itteration option as 1(xentop -i 1) but It does not work! How can I pipe output of xentop as "not" realtime to my script?

Peggy
  • 639
  • 9
  • 28
  • So what's the problem with piping `xentop -b` ? – cnicutar Sep 07 '13 at 12:45
  • @cnicutar:It doesn't return anything!!! I first redirect output of it into a file and then pipe the file to my script. I can't even do this because redirecting its output to a file make several series of lines but I just want the first series of lines. – Peggy Sep 07 '13 at 13:32
  • I don't have `xentop` but I played with `top` for a bit. If I run `top -b | ...(filtering)` I also don't get anything, but I can do `top -b > foo.txt` then `cat foo.txt | ...` and that works (as you observed for `xentop`). If I do `top -b -n 1 | ...(filtering)` then it worked as descired. For `xentop` that's `xentop -b -i 1 | ...`. Not sure where that might leave you but to try `xentop -b -i 1 | ...` and, if that works, then you can periodically call it to update the data. – lurker Sep 07 '13 at 18:43
  • 3
    The problem is that `top` and `xentop` are really designed for console periodic output, not for script output to file. If you want to have periodic output to file, why would you not periodically call `ps` with suitable options from a script and filter that to file? – lurker Sep 07 '13 at 18:46
  • 1
    I bet you can get all the information you want to extract from `xentop` with `snmpwalk`. – Red Cricket Sep 08 '13 at 00:52
  • @mbratch:The problem with `xentop -b -i 1 | ...` is that xentop doesn't show for example cpu usage as it starts, it shows it right after some itteration so I should determine `i` as more than 1 and periodically get the output of last done itteration of that.As I think it may be possible! – Peggy Sep 08 '13 at 05:57
  • @mbratch:And the problem with `ps` is that it should be run in guest, but I want "host" to monitor guest. – Peggy Sep 08 '13 at 05:59
  • What do you mean that *`ps`... should be run in guest*? `ps` can be run by any user. – lurker Sep 08 '13 at 11:33
  • @MBRATCH:I know! I mean in virtualization I don't want to be dependent to guest itself, I want host to get guests's stats independently, xentop do so.It doesnt have to be run on guest system,I run it on host system to get guest's stats. – Peggy Sep 08 '13 at 12:49

2 Answers2

0

It may not be sending any output to the standard output stream. There are several ways of sending output to the screen without using stdout. A quick google search didn't provide much information about how it works internally.

Jay
  • 13,803
  • 4
  • 42
  • 69
0

I use xentop version 1.0 on xenserver 7.0 like :

[root@xen] xentop -V
xentop 1.0

[root@xen] cat /etc/centos-release
XenServer release 7.0.0-125380c (xenenterprise)

If you want to save the xentop output you can do it with '-b' (batch mode) and '-i' (number of iterations before exiting) options :

[root@xen] xentop -b -i 1
NAME  STATE   CPU(sec) CPU(%)     MEM(k) MEM(%)  MAXMEM(k) MAXMEM(%) VCPUS NETS NETTX(k) NETRX(k) VBDS   VBD_OO   VBD_RD   VBD_WR  VBD_RSECT  VBD_WSECT SSID
Domain-0 -----r     132130    0.0    4194304    1.6    4194304       1.6    16    0        0        0    0        0        0        0          0          0    0
MY_VM --b---       5652    0.0   16777208    6.3   16915456       6.3     4    0        0        0    1        -        -        -          -          -    0 

[root@xen] xentop -b -i 1 > output.txt
[root@xen] cat output.txt
NAME  STATE   CPU(sec) CPU(%)     MEM(k) MEM(%)  MAXMEM(k) MAXMEM(%) VCPUS NETS NETTX(k) NETRX(k) VBDS   VBD_OO   VBD_RD   VBD_WR  VBD_RSECT  VBD_WSECT SSID
Domain-0 -----r     132130    0.0    4194304    1.6    4194304       1.6    16    0        0        0    0        0        0        0          0          0    0
MY_VM --b---       5652    0.0   16777208    6.3   16915456       6.3     4    0        0        0    1        -        -        -          -          -    0 
Aegirops
  • 51
  • 1
  • 4