How to display PODs CPU/MEM resource consumption by node(s)

Solution Verified - Updated

Environment

  • Red Hat OpenShift Container Platform (RHOCP)
    • 4

Issue

  • Need to check the POD resource consumption from the node(s).
  • oc adm top node does not offer to display the POD usage on the node
  • oc adm top pod does not offer to display the POD usage for a specific node

Resolution

Disclaimer: Please note that the sample code within this article is provided for customer benefit, but, is not supported by Red Hat. Customers can use it "as it is" or by customizing it appropriately. Red Hat does not support custom code. Please refer to the Scope of coverage (What Red Hat supports) for further details.

Running the script ocadmtop_node.sh attached to the KCS should allow displaying the POD resources by Node.

Script Usage
ocadmtop_node.sh [-c|-m|-p] [-C] [-u <m|u|n>] [-n <namesapce>] [-A|-L <label1>,<label2>,...|-H <host1>,<host2>,...] [-o <nodes|list|json>|-l|-j] [-t <TIMEOUT>] [-d {0-10}] [-v|-h]
  -c: Sort by CPU (default)
  -m: Sort by Memory
  -p: Sort by namespace/pod
  -C: Display the container details. (Default: false)
  -u: Set the PODs' CPU unit to millicore (m), microcore (u) or nanocore (n). (Default: m)
  -n: Filter on a specific namespace PODs
  -A: Retrieve All nodes (default)
  -L: Retrieve node(s) matching all labels
  -H: Retrieve node(s) by hostname
  -o: Set the format
      - nodes: Grouped by nodes                             (default)
      - list:  Not grouped by nodes                         (short option: '-l')
      - json:  raw json format using nanocores as CPU unit  (short option: '-j')
  -t: The length of time to wait before giving up on a single server request. Non-zero values should contain a
      corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests.
  -d: Debug/loglevel mode. Provide additional 'oc --loglevel' ouput. (Recommended value: 6)
  -v: Display the version
  -h: Display this help
ocadmtop_node.sh - Version:  1.2.0
Examples
  • Displaying ALL nodes (default) sorted by CPU (default)

    $ ./ocadmtop_node.sh
    
  • Displaying all master nodes sorted by MEM

    $ ./ocadmtop_node.sh -L node-role.kubernetes.io/master -m
    
  • Displaying some nodes sorted by POD

    $ ./ocadmtop_node.sh -H master-1.lab.example.com,master-2.lab.example.com -p
    
  • Displaying a node sorted by CPU with loglevel 6

    $ ./ocadmtop_node.sh -H master-1.lab.example.com -d 6
    
  • Displaying a node sorted by CPU in nanocore unit with loglevel 6

    $ ./ocadmtop_node.sh -H master-1.lab.example.com -u n -d 6
    
  • Displaying all worker nodes as list (not group by nodes) sorted by CPU in microcore

    $ ./ocadmtop_node.sh -L node-role.kubernetes.io/worker -l -u u
    

Note:
the latest version of the script should be attached in the KCS, or can be downloaded from the Github source: Content from github.com is not included.ocadmtop

Root Cause

There is an internal RFE created to request the oc adm top pod to display the hosted node, this task is still in 'to do' state.

SBR
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.