Kir Kolyshkin (k001) wrote in openvz,
Kir Kolyshkin
k001
openvz

vzubc: better cat /proc/user_beancounters

Managing user beancounters is not for the faint of heart, I must say. One has to read through a lot of documentation and understand all this stuff pretty well. Despite the fact we have made a great improvement recently, a feature called VSwap, many people still rely on traditional beancounters.

This post is about a utility I initially wrote for myself in May 2011. Surely I have added it to vzctl, it is available since vzctl 3.0.27. Simply speaking, it is just a replacement for cat /proc/user_beancounters, and of course it can do much more than cat.

Here's a brief list of vzubc features:

  1. Shows human-readable held, maxheld, barrier, limit, and fail counter for every beancounter, fitting into standard 80-columns terminal (unlike /proc/user_beancounters on an x86_64 system)

  2. Values that are in pages (such as physpages) are converted to bytes

  3. Long values are then converted to kilo-, mega-, gigabytes etc, similar to -h flag for ls or df

  4. For held and maxheld, it shows how close the value to the barrier and the limit, in per cent

  5. Can be used both inside CT and on HN

  6. User can specify CTIDs or CT names to output info about specific containers only

  7. Optional top-like autoupdate mode (internally using "watch" utility)

  8. Optional "relative failcnt" mode (show increase in UBC fail counters since the last run

  9. Optional quiet mode (only shows "worth to look at" UBCs, ie ones close to limits and/or with failcnt)



Now, this is how default vzubc output for a particular VE (with non-vswap configuration) looks like:
# vzubc 1009
----------------------------------------------------------------
CT 1009      | HELD Bar% Lim%| MAXH Bar% Lim%| BAR | LIM | FAIL
-------------+---------------+---------------+-----+-----+------
     kmemsize|1.52M  11%  10%|1.81M  13%  12%|13.7M|14.1M|    - 
  lockedpages|   -    -    - |   -    -    - |   8M|   8M|    - 
  privvmpages| 2.6M   1%   1%|4.32M   2%   2%| 256M| 272M|    - 
     shmpages|   -    -    - |   -    -    - |  84M|  84M|    - 
      numproc|  10    4%   4%|  15    6%   6%| 240 | 240 |    - 
    physpages|17.3M   -    - |18.6M   -    - |   - |   - |    - 
  vmguarpages|   -    -    - |   -    -    - | 132M|   - |    - 
 oomguarpages|1.52M   2%   - |1.52M   2%   - | 102M|   - |    - 
   numtcpsock|   2  0.6% 0.6%|   3  0.8% 0.8%| 360 | 360 |    - 
     numflock|   1  0.5% 0.5%|   2    1%   1%| 188 | 206 |    - 
       numpty|   -    -    - |   -    -    - |  16 |  16 |    - 
   numsiginfo|   -    -    - |   6    2%   2%| 256 | 256 |    - 
    tcpsndbuf|34.1K   2%   1%|51.1K   3%   2%|1.64M|2.58M|    - 
    tcprcvbuf|  32K   2%   1%|  48K   2%   2%|1.64M|2.58M|    - 
 othersockbuf|2.26K 0.2% 0.1%|14.6K   1% 0.7%|1.07M|   2M|    - 
  dgramrcvbuf|   -    -    - |   -    -    - | 256K| 256K|    - 
 numothersock|  44   12%  12%|  47   13%  13%| 360 | 360 |    - 
   dcachesize| 618K  18%  17%| 627K  18%  17%|3.25M|3.46M|    - 
      numfile| 114    1%   1%| 125    1%   1%|9.09K|9.09K|    - 
    numiptent|  20   15%  15%|  20   15%  15%| 128 | 128 |    - 
    swappages|   -    -    - |   -    -    - |   - |   - |    - 
----------------------------------------------------------------



As you can see, it shows all beancounters in human-readable form. Zero or unlimited values are shown by a dash. It also shows the ratio of held and maxheld to barrier and limit, in per cent.

Now, let's try to explore functionality available via command-line switches.

First of all, -q or --quiet enables quiet mode to only show beancounters with fails and those with held/maxheld values close to limits. If vzubc --q produces empty output, that probably means you don't have to worry about anything related to UBC. There are two built-in thresholds for quiet mode, one for barrier and one for limit. They can be changed to your liking using -qh and -qm options.

Next, -c or --color enables using colors to highlight interesting fields. In this mode "warnings" are shown in yellow, and "errors" are in red. Here a warning means a parameter close to limit (same thresholds are used as for the quiet mode), and an error means non-zero fail counter.

The following screenshot demonstrates the effect of -c and -q options. I have run a forkbomb inside CT to create a resource shortage:



Now, -r or --relative is the ultimate answer to the frequently asked "how do I reset failcnt?" question. Basically it saves the current failcnt value during the first run, and shows its delta (rather than the absolute value) during the next runs. This is how it works:



There is also -i or --incremental flag to activate a mode in which an additional column shows a difference in held value from the previous run, so you can see the change in usage. This option also affects quiet mode: all lines with changed held values are shown.

Here's a screenshot demonstrating the "color, relative, incremental, quiet" mode for vzubc:



Finally, you can use -w or --watch to enable a la top mode, to monitor beancounters. It's not as powerful as top, in fact it just uses watch(1) tool to run vzubc every 2 seconds and that's it. Please note that this mode is not compatible with --color, and you have to press Ctrl-C to quit. Oh, and since I am not a big fan of animated gifs, there will be no screenshot.

Man page vzubc(8) man page gives you more formal description of vzubc, including some minor options I haven't described here. Enjoy.

Tags: cli, user beancounters, vzctl, vzubc
Subscribe
Comments for this post were disabled by the author