Top command considerations

Version 16 - Updated on 06 Nov 2017 at 12:50AM by Joachim Hansen

Description

top -b -d 0  -p 8254  | grep "^ " | awk '{ printf("%-8s %-8s %-8s %-8s %-8s %-8s %-8s %-8s %-8s %-8s %-8s %-8s\n", $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12); }' >> /home/search/Downloads/file12.txt

The command above runs forever (no -n (iterations)) and have to be cancled with CTRL + C. It has no delay time -d 0 (normal is 3 secconds) ... it seems to update in milisecconds (but dont know how often)...

It produce  very long file ... and I have to only keep unique lines...


I should consider to write the file in such a way that it can be imported as a .csv file. 


https://unix.stackexchange.com/questions/9918/printing-unique-lines

removes duplicate lines (keep line order)

cat /home/search/Downloads/file12.txt | awk '!seen[$0] {print}
     {++seen[$0]}' >> /home/search/Downloads/o.txt


PID      USER     PR       NI       VIRT     RES      SHR      S        %CPU     %MEM     TIME+    COMMAND

8254     elastic+ 20       0        6980216  2,459g   24808    S        0,0      6,3      4:07.35  java    

8254     elastic+ 20       0        6980216  2,459g   24808    S        200,0    6,3      4:07.36  java    

8254     elastic+ 20       0        6980216  2,459g   24808    S        0,0      6,3      4:07.36  java    

8254     elastic+ 20       0        6980216  2,459g   24808    S        200,0    6,3      4:07.37  java    

8254     elastic+ 20       0        6980216  2,459g   24808    S        0,0      6,3      4:07.37  java    

8254     elastic+ 20       0        6980216  2,459g   24808    S        200,0    6,3      4:07.38  java    

8254     elastic+ 20       0        6980216  2,459g   24808    S        0,0      6,3      4:07.38  java    

8254     elastic+ 20       0        6980216  2,459g   24808    S        200,0    6,3      4:07.39  java    

8254     elastic+ 20       0        6980216  2,459g   24808    S        0,0      6,3      4:07.39  java    

8254     elastic+ 20       0        6980216  2,459g   24808    S        200,0    6,3      4:07.40  java    

8254     elastic+ 20       0        6980216  2,459g   24808    S        0,0      6,3      4:07.40  java    

8254     elastic+ 20       0        6980220  2,459g   24808    S        0,0      6,3      4:07.40  java    

8254     elastic+ 20       0        6980216  2,459g   24808    S        200,0    6,3      4:07.41  java    

8254     elastic+ 20       0        6980216  2,459g   24808    S        0,0      6,3      4:07.41  java    

8254     elastic+ 20       0        6980220  2,459g   24808    S        0,0      6,3      4:07.41  java    

8254     elastic+ 20       0        6980216  2,459g   24808    S        200,0    6,3      4:07.42  java    

8254     elastic+ 20       0        6980216  2,459g   24808    S        0,0      6,3      4:07.42  java    

8254     elastic+ 20       0        6980220  2,459g   24808    S        0,0      6,3      4:07.42  java    

8254     elastic+ 20       0        6980216  2,459g   24808    S        200,0    6,3      4:07.43  java    

8254     elastic+ 20       0        6980216  2,459g   24808    S        0,0      6,3      4:07.43  java    

8254     elastic+ 20       0        6980216  2,459g   24808    S        200,0    6,3      4:07.44  java    

8254     elastic+ 20       0        6980216  2,459g   24808    S        0,0      6,3      4:07.44  java    

8254     elastic+ 20       0        6980216  2,459g   24808    S        200,0    6,3      4:07.45  java    

8254     elastic+ 20       0        6980216  2,459g   24808    S        0,0      6,3      4:07.45  java    

8254     elastic+ 20       0        6980216  2,459g   24808    S        200,0    6,3      4:07.46  java    

8254     elastic+ 20       0        6980216  2,459g   24808    S        0,0      6,3      4:07.46  java    

8254     elastic+ 20       0        6980216  2,459g   24808    S        200,0    6,3      4:07.47  java    

8254     elastic+ 20       0        6980216  2,459g   24808    S        0,0      6,3      4:07.47  java    

8254     elastic+ 20       0        6980216  2,459g   24808    S        200,0    6,3      4:07.48  java    

8254     elastic+ 20       0        6980216  2,459g   24808    S        0,0      6,3      4:07.48  java    

8254     elastic+ 20       0        6980216  2,460g   24808    S        200,0    6,3      4:07.49  java    

8254     elastic+ 20       0        6980216  2,460g   24808    S        200,0    6,3      4:07.50  java    

8254     elastic+ 20       0        6980216  2,460g   24808    S        0,0      6,3      4:07.50  java    

8254     elastic+ 20       0        6980216  2,460g   24808    S        200,0    6,3      4:07.51  java    

8254     elastic+ 20       0        6980216  2,460g   24808    S        0,0      6,3      4:07.51  java    

8254     elastic+ 20       0        6980216  2,460g   24808    S        200,0    6,3      4:07.52  java    

8254     elastic+ 20       0        6980216  2,460g   24808    S        0,0      6,3      4:07.52  java    

8254     elastic+ 20       0        6980216  2,460g   24808    S        200,0    6,3      4:07.53  java    

8254     elastic+ 20       0        6980216  2,460g   24808    S        0,0      6,3      4:07.53  java    

8254     elastic+ 20       0        6980216  2,460g   24808    S        200,0    6,3      4:07.54  java    

8254     elastic+ 20       0        6980216  2,460g   24808    S        0,0      6,3      4:07.54  java    

8254     elastic+ 20       0        6980216  2,460g   24808    S        200,0    6,3      4:07.55  java    

8254     elastic+ 20       0        6980216  2,460g   24808    S        0,0      6,3      4:07.55  java    

8254     elastic+ 20       0        6980216  2,460g   24808    S        200,0    6,3      4:07.56  java    

8254     elastic+ 20       0        6980216  2,460g   24808    S        0,0      6,3      4:07.56  java    

8254     elastic+ 20       0        6980216  2,460g   24808    S        200,0    6,3      4:07.57  java    

8254     elastic+ 20       0        6980216  2,460g   24808    S        0,0      6,3      4:07.57  java    

8254     elastic+ 20       0        6980216  2,460g   24808    S        200,0    6,3      4:07.58  java    

8254     elastic+ 20       0        6980216  2,460g   24808    S        0,0      6,3      4:07.58  java    

8254     elastic+ 20       0        6980216  2,460g   24808    S        200,0    6,3      4:07.59  java    

8254     elastic+ 20       0        6980216  2,460g   24808    S        0,0      6,3      4:07.59  java    

8254     elastic+ 20       0        6980216  2,460g   24896    S        200,0    6,3      4:07.60  java    

8254     elastic+ 20       0        6980276  2,460g   24896    S        0,0      6,3      4:07.60  java    

8254     elastic+ 20       0        6980216  2,460g   24896    S        0,0      6,3      4:07.60  java    

8254     elastic+ 20       0        6980240  2,460g   24896    S        0,0      6,3      4:07.60  java    

8254     elastic+ 20       0        6980220  2,460g   24896    S        0,0      6,3      4:07.60  java    

8254     elastic+ 20       0        6980316  2,460g   24896    S        0,0      6,3      4:07.60  java    

8254     elastic+ 20       0        6980316  2,460g   24896    S        200,0    6,3      4:07.61  java    

8254     elastic+ 20       0        6980316  2,460g   24896    S        0,0      6,3      4:07.61  java    

8254     elastic+ 20       0        6980316  2,460g   24996    S        0,0      6,3      4:07.61  java    

8254     elastic+ 20       0        6980340  2,460g   24996    S        0,0      6,3      4:07.61  java    

8254     elastic+ 20       0        6980328  2,460g   24996    S        0,0      6,3      4:07.61  java    

8254     elastic+ 20       0        6980320  2,460g   24996    S        0,0      6,3      4:07.61  java    

8254     elastic+ 20       0        6980416  2,460g   24996    S        0,0      6,3      4:07.61  java    

8254     elastic+ 20       0        6980416  2,460g   24996    S        200,0    6,3      4:07.62  java    

8254     elastic+ 20       0        6980416  2,460g   24996    S        0,0      6,3      4:07.62  java    

8254     elastic+ 20       0        6980420  2,460g   24996    S        0,0      6,3      4:07.62  java    

8254     elastic+ 20       0        6980416  2,460g   25080    S        0,0      6,3      4:07.62  java    

8254     elastic+ 20       0        6980420  2,460g   25080    S        0,0      6,3      4:07.62  java    

8254     elastic+ 20       0        6980440  2,460g   25080    S        0,0      6,3      4:07.62  java    

8254     elastic+ 20       0        6980428  2,460g   25080    S        0,0      6,3      4:07.62  java    

8254     elastic+ 20       0        6980416  2,460g   25080    S        200,0    6,3      4:07.63  java    

8254     elastic+ 20       0        6980416  2,460g   25080    S        0,0      6,3      4:07.63  java    

8254     elastic+ 20       0        6980516  2,460g   25080    S        0,0      6,3      4:07.63  java    

8254     elastic+ 20       0        6980516  2,460g   25080    S        200,0    6,3      4:07.64  java    

8254     elastic+ 20       0        6980516  2,460g   25080    S        0,0      6,3      4:07.64  java    

8254     elastic+ 20       0        6980516  2,460g   25180    S        0,0      6,3      4:07.64  java    

8254     elastic+ 20       0        6980580  2,460g   25180    S        0,0      6,3      4:07.64  java    

8254     elastic+ 20       0        6980544  2,460g   25180    S        0,0      6,3      4:07.64  java    

8254     elastic+ 20       0        6980624  2,460g   25180    S        0,0      6,3      4:07.64  java    

8254     elastic+ 20       0        6980624  2,460g   25180    S        200,0    6,3      4:07.65  java    

8254     elastic+ 20       0        6980624  2,460g   25180    S        0,0      6,3      4:07.65  java    

8254     elastic+ 20       0        6980624  2,460g   25180    S        200,0    6,3      4:07.66  java    

8254     elastic+ 20       0        6980624  2,460g   25180    S        0,0      6,3      4:07.66  java    

8254     elastic+ 20       0        6980628  2,460g   25180    S        0,0      6,3      4:07.66  java    

8254     elastic+ 20       0        6980684  2,460g   25288    S        0,0      6,3      4:07.66  java    

8254     elastic+ 20       0        6980628  2,460g   25288    S        0,0      6,3      4:07.66  java    

8254     elastic+ 20       0        6980648  2,460g   25288    S        0,0      6,3      4:07.66  java    

8254     elastic+ 20       0        6980640  2,460g   25288    S        0,0      6,3      4:07.66  java    

8254     elastic+ 20       0        6980624  2,460g   25288    S        0,0      6,3      4:07.66  java    

8254     elastic+ 20       0        6980728  2,460g   25288    S        0,0      6,3      4:07.66  java    

8254     elastic+ 20       0        6980728  2,460g   25288    S        200,0    6,3      4:07.67  java    

8254     elastic+ 20       0        6980728  2,460g   25288    S        0,0      6,3      4:07.67  java    

8254     elastic+ 20       0        6980728  2,460g   25288    S        200,0    6,3      4:07.68  java    

8254     elastic+ 20       0        6980728  2,460g   25288    S        0,0      6,3      4:07.68  java    

8254     elastic+ 20       0        6980728  2,460g   25288    S        200,0    6,3      4:07.69  java    

8254     elastic+ 20       0        6980728  2,460g   25288    S        0,0      6,3      4:07.69  java    

8254     elastic+ 20       0        6980728  2,460g   25288    S        200,0    6,3      4:07.70  java    

8254     elastic+ 20       0        6980728  2,460g   25288    S        0,0      6,3      4:07.70  java    

8254     elastic+ 20       0        6980728  2,460g   25288    S        200,0    6,3      4:07.71  java    

8254     elastic+ 20       0        6980728  2,460g   25288    S        0,0      6,3      4:07.71  java    

8254     elastic+ 20       0        6980728  2,460g   25288    S        200,0    6,3      4:07.72  java    

8254     elastic+ 20       0        6980728  2,460g   25288    S        0,0      6,3      4:07.72  java    

8254     elastic+ 20       0        6980728



https://unix.stackexchange.com/questions/9918/printing-unique-lines

awk -v OFS='\t' '{print $5, $1}'


11 = time 

10 = mem

9 = CPU

8 = S

7 = Shared 

6 = RES

5 = VIRT

    %MEM - simply RES divided by total physical memory
          CODE - the `pgms' portion of quadrant 3
          DATA - the entire quadrant portion of VIRT plus all
                 explicit mmap file-backed pages of quadrant 3
          RES  - anything occupying physical memory which, beginning with
                 Linux-4.5, is the sum of the following three fields:
                 RSan - quadrant pages, which include any
                        former quadrant pages if modified
                 RSfd - quadrant and quadrant pages
                 RSsh - quadrant pages
          RSlk - subset of RES which cannot be swapped out (any quadrant)
          SHR  - subset of RES (excludes 1, includes all & 4, some 3)
          SWAP - potentially any quadrant except 4
          USED - simply the sum of RES and SWAP
          VIRT - everything in-use and/or reserved (all quadrants)


top -b -d 0 -p 8254 | grep "^ " | awk -v OFS='\t' '{print  $5, $6, $7, $9, $10, $11}' >> /home/search/Downloads/test3.csv

Print in  a tabular seperated file (.csv) ... -v is for setting a variable...

This includes the header text for the colums multiple times (a instance of header text every odd number of lines).

http://man7.org/linux/man-pages/man1/top.1.html




 cat /home/search/Downloads/file12.txt | awk '!seen[$0] {print}
     {++seen[$0]}' >> /home/search/Downloads/a.csv


 cat /home/search/Downloads/file12.txt | awk 'NR%2==0' | awk '!seen[$0] {print}
     {++seen[$0]}' >> /home/search/Downloads/a.csv

1.Print every second line 

2.only print unique (seen once) line.

 

https://superuser.com/questions/606272/how-to-get-excel-to-interpret-the-comma-as-a-default-delimiter-in-csv-files


top -b -d 0 -p 8254 | grep "^ " | awk -v OFS='\;' '{print  $5, $6, $7, $9, $10, $11}' >> /home/search/Downloads/test10.csv



The commands below runs a infinite scrips that monitor the performance of a given application, writes the performance messures to disk in a .csv file with the ; delimiter. The script have to quit the script by using CTRL + C. The top command has 0 ADDED delay, but how often it refreshes is unknown. This may largly depend on the system call request/response time. The script should be started just before indexing/searching and be termiated shortly after. The latter scripts cleans up the .csv file by removing column headers that is in every odd number of lines. Then only unique lines are kept in their chronological order (there order in the file is still kept).  I make the assumption that by removing the duplicate lines that I essentially get the performance messuruments during index/search execution. But otherwise VIRT etc should be more or less stable.  Of course Elasticsearch might have a thread that perform some other task before, during or after the search/indexing process. 


top -b -d 0 -p 8254 | grep "^ " | awk -v OFS=';' '{print $5, $6, $7, $9, $10, $11}' >> /home/search/Downloads/test20.csv

 cat /home/search/Downloads/test20.csv | awk 'NR%2==0' | awk '!seen[$0] {print}
{++seen[$0]}' >> /home/search/Downloads/d.csv


https://askubuntu.com/questions/231995/how-to-separate-fields-with-space-or-tab-in-awk

https://stackoverflow.com/questions/2560411/how-to-remove-every-other-line-with-sed




TIME+  --  CPU Time, hundredths
           The same as TIME, but reflecting more granularity through
           hundredths of a second.


       *  | s  :Change-Delay-Time-interval
              You will be prompted to enter the delay time, in seconds,
              between display updates.

              Fractional seconds are honored, but a negative number is not
              allowed.  Entering 0 causes (nearly) continuous updates, with
              an unsatisfactory display as the system and tty driver try to
              keep up with top's demands.  The delay value is inversely
              proportional to system loading, so set it with care.

              If at any time you wish to know the current delay time, simply
              ask for help and view the system summary on the second line.


Now that I have my excel file for the dummy dataset indexing in elastic search... I take virt and plot a graph of that... and modify the seccond axis by replacing the 1-70 or so values with the time+ column data but selecting all of the time data that is in min:sec.ms????