We help IT Professionals succeed at work.

linux command for adminstration

marrowyung
marrowyung asked
on
hi,

in redhatl linux and AIX unix, how to use command to check:

1) CPU used ?
2) RAM used and left
3) diskspace used and left

how to add volume using command  ?

anyway to use Graphic mode to present that in linux without monitoring tools ?
Comment
Watch Question

murugesandinsWe like KT across the universe.  C C++ shell script Automation /bin/bash /bin/bash.exe /bin/ksh /bin/mksh.exe AIX CYGWIN_NT HP-UX Linux MINGW32 MINGW64 SunOS Windows_NT
BRONZE EXPERT

Commented:
/usr/bin/vmstat
/usr/bin/top -n 1
/usr/bin/free -b
/usr/bin/free -k
/usr/bin/free -m
/usr/bin/man vmstat 2>&1 | /usr/bin/col -bx > vmstat.txt
/usr/bin/man free
/usr/bin/man top
/usr/bin/df
# or
/usr/bin/bdf
if [ -f /proc/meminfo ]; then /usr/bin/grep Free /proc/meminfo;fi
/usr/bin/cat /proc/meminfo
marrowyungSenior Technical architecture (Data)

Author

Commented:
hi,

tks. any high level explaination on what the above command do ?
murugesandinsWe like KT across the universe.  C C++ shell script Automation /bin/bash /bin/bash.exe /bin/ksh /bin/mksh.exe AIX CYGWIN_NT HP-UX Linux MINGW32 MINGW64 SunOS Windows_NT
BRONZE EXPERT

Commented:
@marrowyung

Executing man command
>> man vmstat

it used to display related details and usage of those commands.
From man vmstat command:

vmstat - Report virtual memory statistics
...
The -d reports disk statistics (2.5.70 or above required)

Press space bar to read more
press 1G to go to first line of manual
press Shift G to go to end of manual

you can redirect manual output:
example:
/usr/bin/man vmstat 2>&1 | /usr/bin/col -bx > vmstat.txt
After this you can view vmstat.txt
vi vmstat.txt

/usr/bin/free -b
byte kilobyte megabyt -b -k -m... from manual

df / bdf commands available based on operating system.
View manual of df / bdf / top

At Linux system /proc/meminfo
file used to have MemFree HighFree LowFree SwapFree.
you can use
/usr/bin/cat /proc/meminfo
for more information.
if you execute
/usr/bin/top
it will quit until you press q
/usr/bin/top -n 1
to display current status.
-n representing iterations => -n : Number of iterations limit as:  -n number
from man top

Inside manual search using
/-n
Enter
press n to go to next line having -n
press N to go to previous line having -N
press q to quit manual
Executive IT Director, MVE
BRONZE EXPERT
Most Valuable Expert 2019
Commented:
Install linux distro and work with it
http://www.tablespace.net/quicksheet/aix-quicksheet.pdf
https://sysaix.com/basic-linux-unix-commands-cheat-sheet
https://developer.ibm.com/articles/au-aix_cmds
marrowyungSenior Technical architecture (Data)

Author

Commented:
hi,

those commands are the same in AIX solars UNIX?
murugesandinsWe like KT across the universe.  C C++ shell script Automation /bin/bash /bin/bash.exe /bin/ksh /bin/mksh.exe AIX CYGWIN_NT HP-UX Linux MINGW32 MINGW64 SunOS Windows_NT
BRONZE EXPERT

Commented:
@marrowyung

Currently I am not having AIX/HP-UX/UNIX/SunOS OS.
Used them still 2013 (still AIX 5.3 and SunOS 2.8 HP-UX 11.00 still 11.23 PA-RISC IPF) .

Most probably used to be the same.

Few commands(df/bdf) varies.
Hence informed use
1) which ls
which df
which bdf
...
2) type ls
type ...
3) alias ls 2>/dev/null
4)
bdf at HP-UX
5) man df
man bdf
...
6) Verify that PATH environment variable having:

$ echo "$PATH"
/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/bin:.
$ # From above output I have removed my personal directories.

Open in new window



/usr/local/sbin
/usr/sbin
/sbin
/usr/local/bin
/usr/bin
/bin
/bin
.

Following line may be out of scope
C C++ Compiler commands varies based on OS/installed binaries by admin
g++
gcc
xlC
aCC
c++
CC
cc
cl.exe
TC.EXE
TCC.EXE
David FavorFractional CTO
BRONZE EXPERT
Distinguished Expert 2019
Commented:
1) CPU used ?

net16 # cat /proc/cpuinfo | grep -i "model name" | sort -u
model name	: Intel(R) Xeon(R) D-2123IT CPU @ 2.20GHz

Open in new window


2) RAM used and left

net16 # free -hg
              total        used        free      shared  buff/cache   available
Mem:            62G         11G         12G        1.7G         38G         48G
Swap:           17M          0B         17M

Open in new window


3) diskspace used and left

For storage space usage...

net16 # df -h
Filesystem      Size  Used Avail Use% Mounted on
udev             32G     0   32G   0% /dev
tmpfs           6.3G  1.7M  6.3G   1% /run
/dev/md4        3.6T  1.1T  2.4T  33% /
tmpfs            32G     0   32G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs            32G     0   32G   0% /sys/fs/cgroup
/dev/loop1       92M   92M     0 100% /snap/core/8689
/dev/loop3       92M   92M     0 100% /snap/core/8592
/dev/md2        991M  215M  710M  24% /boot
/dev/sda1       510M  6.1M  504M   2% /boot/efi
tmpfs           1.0M     0  1.0M   0% /var/snap/lxd/common/ns
/dev/loop4       67M   67M     0 100% /snap/lxd/13487
/dev/loop0       67M   67M     0 100% /snap/lxd/13522

Open in new window


For inode usage...

net16 # df -ih
Filesystem     Inodes IUsed IFree IUse% Mounted on
udev             7.9M   530  7.9M    1% /dev
tmpfs            7.9M   946  7.9M    1% /run
/dev/md4         233M  3.6M  230M    2% /
tmpfs            7.9M     1  7.9M    1% /dev/shm
tmpfs            7.9M     3  7.9M    1% /run/lock
tmpfs            7.9M    18  7.9M    1% /sys/fs/cgroup
/dev/loop1        13K   13K     0  100% /snap/core/8689
/dev/loop3        13K   13K     0  100% /snap/core/8592
/dev/md2          64K   583   64K    1% /boot
/dev/sda1           0     0     0     - /boot/efi
tmpfs            7.9M     3  7.9M    1% /var/snap/lxd/common/ns
/dev/loop4       1.4K  1.4K     0  100% /snap/lxd/13487
/dev/loop0       1.4K  1.4K     0  100% /snap/lxd/13522

Open in new window


4) those commands are the same in AIX solars UNIX?

Maybe. Depends on many factors.

#1 will only work on Linux machines. You will have to check your AIX + Solaris docs, for your specific version, to find the correct command... if a command like this exists...

#2 will work across most UNIX-esque machines.

#3 will usually produce output + will be correct/incorrect based on your UNIX type + file system type, so the more exotic the attached storage, the more chance reported usage will be... slightly or grossly incorrect...
nociSoftware Engineer
BRONZE EXPERT
Distinguished Expert 2019

Commented:
Maybe you need tools like sysstat to make some recording in time so you can more or less see the varying data.
(sysstat should also be available UNIX systems at least on AIX and i guess also on Solaris).
marrowyungSenior Technical architecture (Data)

Author

Commented:
murugesandins,

/usr/bin/top -n 1
to display current status.
-n representing iterations => -n : Number of iterations limit as:  -n number
from man top

Inside manual search using
/-n
Enter
press n to go to next line having -n
press N to go to previous line having -N
press q to quit manual

I do not understand that, is that means type "man top" to read the manual to understand the top command ?

David Favor,

"# cat /proc/cpuinfo | grep -i "model name" | sort -u"

what is sort -u means ?
I also can see only one column but what actually u means?


"free -hg"

then what should be this:

/usr/bin/free -b

/usr/bin/free -k
/usr/bin/free -m

?

"For inode usage..."

what is inode?


noci,

usually what tools for linux and unix proactive monitoring ?
nociSoftware Engineer
BRONZE EXPERT
Distinguished Expert 2019
Commented:
man top is request the MANual page for the program top.
man -k blah  requests an index for the keyword blah (in commands or descriptions).

man is the command ... for more info use: man man

If the man program is no installed try to install it including the manual pages. All manual pages have  a standard layout.

Also online you can find these pages:   https://linux.die.net/man/
Almost ALL commands on linux have a manpage.   In some case the page redirect to the info package. (Mostly the basic GNU tools).
man sort can answer the sort -u question  (-u removes duplicates.....) check it: here: https://linux.die.net/man/1/sort

man free for more info on free.
free -b  -- report size in byte units,  -k report size in kilo-byte units, -m report size in megabyte units, -h report size in Human units (autoscaling).


Inode = the 1 location where everything about a file is administrated, EXCEPT the name. (This is fairly basic filesystem knowlegde.., if you know what a file is, you should also know what a directory is. If you are system manager, or programmer you SHOULD also know about Inodes, ACL;s, Bitmaps, etc. etc.).
The name is in a directory,  a directory is a list of (name,inode) pairs.
A file can have many names. (so called hardlinks).


Monitoring tools:  icinga, nagios, munin, mrtg, cacti, sysstat, logrotate, calamaris, telegraf, nessus, grafana and then some;  all with their own focus, etc. so take your pick.
Be advised that monitoring systems may require very heavy dedicated systems due the the profile of the data to be processed... (A lot [ 1000 - 1000000's] of units  of very small chunks of data 1-8 bytes / unit).
murugesandinsWe like KT across the universe.  C C++ shell script Automation /bin/bash /bin/bash.exe /bin/ksh /bin/mksh.exe AIX CYGWIN_NT HP-UX Linux MINGW32 MINGW64 SunOS Windows_NT
BRONZE EXPERT
Commented:
>> "man top" to read the manual to understand the top command ?
Yes.
After typing "man top" you can search string inside man help (like the way you are searching inside vi)
Example:
$ man sort

Open in new window

we can search -u by typing /-u
Enter
That will display following lines (unique)
       -u, --unique
              with -c, check for strict ordering; without -c, output only the first of an equal run
Type q to quit manual.

inode comment:
Initially created following directories
$ /usr/bin/mkdir  ./testing ./Version1 ./Version2

Open in new window

Created two empty files having the same name testing
$ /usr/bin/touch ./testing/testing ./Version1/testing

Open in new window

Name remains the same for file name and directory name.
This can be achieved using inode ( inode => index node by all operating systems => like the way of PRIMARY KEY at database)
$ /usr/bin/ls -ltrid ./testing/testing ./testing ./Version1 ./Version2
123593 drwxr-xr-x 2 murugesandins murugesandins 4096 Mar 12 12:50 ./Version1
123599 -rw-r--r-- 1 murugesandins murugesandins    0 Mar 12 12:50 ./testing/testing
123592 drwxr-xr-x 2 murugesandins murugesandins 4096 Mar 12 12:50 ./testing
123598 drwxr-xr-x 2 murugesandins murugesandins 4096 Mar 12 12:50 ./Version2

Open in new window

First column representing inode (being different)
Third column representing number of links.
After this creating soft link for the file ./testing/testing
$ /usr/bin/ln -s ./testing/testing ./Version2/testing
$ /usr/bin/ls -ltrid ./testing/testing ./testing ./Version1 ./Version2 ./Version2/testing
123593 drwxr-xr-x 2 murugesandins murugesandins 4096 Mar 12 12:50 ./Version1
123599 -rw-r--r-- 1 murugesandins murugesandins    0 Mar 12 12:50 ./testing/testing
123592 drwxr-xr-x 2 murugesandins murugesandins 4096 Mar 12 12:50 ./testing
123601 lrwxrwxrwx 1 murugesandins murugesandins   17 Mar 12 12:50 ./Version2/testing -> ./testing/testing
123598 drwxr-xr-x 2 murugesandins murugesandins 4096 Mar 12 12:50 ./Version2
$

Open in new window

Here you can see that soft link ./Version2/testing and original file ./testing/testing having reference count 2 (number of links)
However inode is different for those two files soft link use new inode.

After this created hard link for a new file.
$  /usr/bin/touch ./testing/NewFile
$#Creating hard link
$ /usr/bin/ln ./testing/NewFile ./Version2/NewFile
$ /usr/bin/ls -litr ./testing/NewFile ./Version2/NewFile
123602 -rw-r--r-- 2 murugesandins murugesandins 0 Mar 12 12:56 ./Version2/NewFile
123602 -rw-r--r-- 2 murugesandins murugesandins 0 Mar 12 12:56 ./testing/NewFile
$

Open in new window

Hard link having same index number 123602 and number of reference count being 2

We can search the files or directory using inum
$ find ./ -type f -inum 123602
./testing/NewFile
./Version2/NewFile
$ find ./ -type d -inum 123598
./Version2

Open in new window

marrowyungSenior Technical architecture (Data)

Author

Commented:
noci,

why use this :
-u, --unique

return only one record! as all the SAME so just report once?

"-h report size in Human units (autoscaling)."

I do not understand what human unit here means.

"Monitoring tools:  icinga, nagios, munin, mrtg, cacti, sysstat, logrotate, calamaris, telegraf, nessus, grafana and then some;  all with their own focus, etc. so take your pick.
"

so no one is the best, nagios is too general ?

murugesandins,

"After this creating soft link for the file ./testing/testing"

inode is the 6 digit number on the left ?


"ls -ltrid"

what is the use of it ?
murugesandinsWe like KT across the universe.  C C++ shell script Automation /bin/bash /bin/bash.exe /bin/ksh /bin/mksh.exe AIX CYGWIN_NT HP-UX Linux MINGW32 MINGW64 SunOS Windows_NT
BRONZE EXPERT
Commented:
@marrowyung

a)-u, --unique
Taking an example for using -u option.
$ /usr/bin/free -b
             total       used       free     shared    buffers     cached
Mem:    2634223616  669564928 1964658688          0  304476160  257228800
-/+ buffers/cache:  107859968 2526363648
Swap:   1073733632          0 1073733632

Open in new window

Now going to translate single space to new line using /usr/bin/tr command:
$ /usr/bin/free -b  | /usr/bin/tr " " "\n"













total
...

Open in new window

Multiple blank lines will be there since we replaced each space to new lines.
We can remove those duplicated lines using:
/usr/bin/sort -u
$ /usr/bin/free -b  | /usr/bin/tr " " "\n" | /usr/bin/sort -u

-/+
0
1073733632
108003328
1964515328
2526220288
257228800
2634223616
304476160
669708288
buffers
buffers/cache:
cached
free
Mem:
shared
Swap:
total
used

Open in new window

b)-h report size in Human units
Example of using /usr/bin/df or bdf command
$ /usr/bin/df | /usr/bin/head -2
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/hda1               101086     21163     74704  23% /boot
$ /usr/bin/df -h | /usr/bin/head -2
Filesystem            Size  Used Avail Use% Mounted on
/dev/hda1              99M   21M   73M  23% /boot

Open in new window

you can under stand the meaning of human readable format having
"Size  Used Avail Use%"

c)
inode is the 6 digit number on the left ?
$ /usr/bin/ls -i .

Open in new window

If we execute above command it used to display inode for all files and directories at current directory excluding sub directories.
Example:
inodeNumber1 filename1 inodeNumber2 filename2
inodeNumber1 dirname1 inodeNumber2 filename3
...
To obtain the inode number of current directory alone we can execute:
$ /usr/bin/ls -id .
12328 .

Open in new window

Yes, first column of ls command used to display inode number if we are using -i option.

-l option from ls:
Type NumberofLinux UserName GroupName Size LastModifiedDate SoftLinkName -> Original
OR
Type NumberofLinux UserName GroupName Size LastModifiedDate SoftLinkName1 -> SoftLinkName2
-t option from ls
sort by modified time
-r option from ls
reverse order while sorting
you can view the same using "/usr/bin/man ls" command

Among the commands I have typed here
use related path (it varies based on administrator OS installation)
/usr/bin/man or /bin/man
/usr/bin/ls or /bin/ls
...
d)
>> so no one is the best
$#Comment
$#It depends on reading manual, and frequent usage of all available commands at related operating system including the requirement.

Open in new window

nociSoftware Engineer
BRONZE EXPERT
Distinguished Expert 2019

Commented:
If you have  32 core machine you will get 32 blocks of lines, the grep gets a certain item, and the sort -u makes it into a single line.
If you only get ONE line with your system, you have a single core machine... Those are getting extinct.... (or a VM   ;-).
(how about running that command on a super computer with 64K cores......)

Human units.....
0-1024 =   units
1024 -- 1024 * 1024 = 0-1024 K
1024*1024 --  1024 * 1024 * 1024 = 0-1024 M
etc. etc.  Auto scaling the untis to a Human comprehensible form
1073741824 = 1Gi

Define BEST....
Best in storing measurements in 100 of data points / second, ro 1M data points / second
Best in fastest for detecting anomalies (what kind of anomalies)...
Best in Graphing image plots
Best in Rasing Alarms...
All monitor software has starting point with a vision of it's developpers. So there's a whole lot of differences.
Some started as raising alarms for anomalies and later also take measurements
Other started as massive datapoint collectors  that can  later started warning about strange results.

So FIRST you need to decide what you want from ANY Monitor (most important stuff, net important item....) Then you compare that to what the various software can do for you. THEN you can decide on what is best. I cannot decide for you what criteria to use for your situation etc. and advise on that.

wrt. Inode:    The Inode = a data structure. I hold all meta data of the file. The Inode-ID is indeed the 0-n digit number on the left hen you do ls -li
The number of preallocated file description structures is determined when you format a disk.  It cannot be chnged unless you enlarge the disk. If all i-nodes are in use you get a disk-full error even if there are still free blocks.
You can test this with a dummy disk if you like where you only allow for 20 inodes or so. Try to create some files. (nice excersize: use the loopback mount option use a pseudo disk in a file.
You can create a filesystem like Ext2 in a file created with
dd if=/dev/zero of=pseudodisk.dsk bs=1M count=1024,
mke2fs -N 20 pseudodisk.dsk ,
mkdir /tmp/test
mount -o loop pseudodisk.dsk test
ls -l /tmp/test
touch /tmp/test/file1
touch /tmp/test/file2
....
until you get an error....
remove:
umount /tmp/test
rm pseudodisk.dsk
rmdir /tmp/test
marrowyungSenior Technical architecture (Data)

Author

Commented:
murugesandins,

"you can under stand the meaning of human readable format having"'

ok

noci,

"Define BEST...."

me, provide meaningful information to troubleshoot, and tell us clearly what should we do !

"The number of preallocated file description structures is determined when you format a disk.  It cannot be chnged unless you enlarge the disk. If all i-nodes are in use you get a disk-full error even if there are still free blocks."

so actaully we don'tuse the inode number,right ?I wonder how userfull it is .


"You can test this with a dummy disk if you like where you only allow for 20 inodes or so"

20 disk  therefore ?

"until you get an error....
remove:
umount /tmp/test
rm pseudodisk.dsk
rmdir /tmp/test

what is the error for ?
marrowyungSenior Technical architecture (Data)

Author

Commented:
hi,

top commmand is dynamic and it change over time, is there any command how RAM and disk usage in real time like top ?
nociSoftware Engineer
BRONZE EXPERT
Distinguished Expert 2019
Commented:
You do use inodes like ip addresses, the inodes are what is important on a disk, only we humans are better at remembering names, hence a directory with name/number translations.
Directories are the DNS of filesystem.

With 20 inodes you can address 20 objects on a disk.  Root directory + 19 other files and/or directories.
The inode number is needed if you need to recover data from the disk incase of damaged directories.
(After first recovery) you will have a lost+found directory with all recovered files as #{inodenumber}...

Any inode holds the owner, group, acl, permissionmask, link count, storage allocation structures.
For the OS at large (except the filesystem handler) the inode number is the only item needed.
If you need to know more: search on documentation of filesystems. ext2 is probably the most accessible type of docs.
debugfs can helpgettng some more insight.... before removing the test container use debugfs on it.
(man debugfs formore info)

The error is when you try to allocate the 21'st inode that isn't there (there are 20 reseved ... ) if you want to learn thing try them on a test system.
(it might happen that in the place of 20 inodes (on disk actually 30 or so can be placed) in that case you get 30. -N 20 means at least 20 inodes to be reserved.
I nodes may not be the first thing you look for ... those are if you need to recover from disk damage.

About Best:
I want the BEST car in the world...... (The question)
Question is what best...
Fastest...?
Holding the biggest load...?
Holding the biggest load on a public road..?
Be able to drive off-road?
Off-road where:
- in water, ?
- in swamps, ?
- in mountains...?
- in sand dunes ?
Highest car?
Be able to drive under water?
Be able to drive in mount everest?
Should it fly as well?....
Least prone in accidents?
It helps if i would tell you i have a ore mine next to a swamp .. so my trucks need to transport several 100Tons of ore/day and need to pass through wetlands.


Simple question...
For your question about BEST monitor tool...
i have no idea on where to start so some more questions, feel free to add more info ...
What platforms to include: Linux, OpenVMS, Windows, DOS, Mac, *BSD,  Cisco, HPE networks, ...?
What network: flat single LAN, multi lan
What amount of devices: 1-10, 10-100, 100-1000, 10000+, 100000+ > 1M?
What amount of logdata is produced on the systems: 1 log line/ hour, 10 loglines / hour 10M loglines / hour, 10G loglines / hour?
What amount of logdata is produced on the 1GB/day, 10GB/day, 100GB/Day,  1TB / Day
How long should data be available after an event, 1 minutes, 1 hour, 1 day, 1 week, 1 month, 1 year, indefinitely?
Is this an HA environement (if so the RTO/RPO criteria please, & other requirements), Hobby project, ...
What applications are involved (Webserver, backup tooling, ......)

If you have no idea a good start would be to start structural logging....
logrotate, logwatch  and send logging to a central system for processing. (aka logserver, , look for SIEM tooling as well logalyze, splunk, ... )
icinga / nagios might be another one. (on its own system)
cacti / munin might be useful to collect data over time. (if things get big you will need other tools). [ collectd, prometheus ]
netflow processing tools might be handy in the case you have routers capable of providing data, ....
This may in all cases need adjustment if scale gets bigger...  and you will still need to develop your own interfaces etc. for any equipment the developpers didn't have.
Some tools are nice for handling 1TB of logging / day...  and those are most probably completely useless for small scale projects.

I have no insight in your actual requirements, so obviously there is a BEST solution for you, but it would be hard to determine what the criteria are..
From your questions i get it you  also have no idea what you need so you can do only one thing start with a few tools and see if it fits. If it doesn;t fit, see what is missing and either fix the tool by adding more capabilities, or select another tool with the newly gained insight... rinse & repeat.
madunixExecutive IT Director, MVE
BRONZE EXPERT
Most Valuable Expert 2019
Commented:
>> top commmand is dynamic and it change over time, is there any command how RAM and disk usage in real time like top ?

You can use iostat, it  can be used to report the disk read/write rates
https://www.opsdash.com/blog/disk-monitoring-linux.html 
https://www.kencorner.com/monitoring-tools-in-linux-ubuntu/ 
https://lintut.com/best-command-line-tools-for-linux-performance-monitring/ 
https://www.cyberciti.biz/tips/shell-script-to-watch-the-disk-space.html 


murugesandinsWe like KT across the universe.  C C++ shell script Automation /bin/bash /bin/bash.exe /bin/ksh /bin/mksh.exe AIX CYGWIN_NT HP-UX Linux MINGW32 MINGW64 SunOS Windows_NT
BRONZE EXPERT
Commented:
@marrowyung

I have updated my comments to use $1...
>> top commmand is dynamic and it change over time,
>> is there any command how RAM and disk usage in real time like top ?
We can use functions/shell script using top/vmstat/free/df/bdf/... available commands at current OS:
$ unalias SampleRam >/dev/null 2>&1
$ unset -f SampleRam
SampleRam ()
{
        if [ 0 -eq $# ]
        then
                #if no parameter passed
                /usr/bin/top -n 1
        #Validating first parameter
        elif [ 1 -eq $# ] && [ "$(echo "$1" | /usr/bin/grep -iq "RAM";echo $?)" = "0" ]
        then
                #We can validate the same using $2 ... ${10} ...
                /usr/bin/top -n 1
        else
                echo "Update the function SampleRam using following parameter:"
                echo "SampleRam $@"
        fi
        #Or required command
        return $?
}
$ SampleRam
...
$ SampleRam ram
...
$ SampleRam RaM
...
$ SampleRam murugesandins
$ SampleRam murugesandins
Update the function SampleRam using following parameter:
SampleRam murugesandins
$# Above command used to display output of related command inside SampleRam
$ # We can write the same using a script
$ /usr/bin/cat  SampleRam.sh
#!/bin/bash
#Before defining any function validate if any alias SampleRam='...' available or not
type SampleRam 2>&1 | /usr/bin/grep "aliased" >/dev/null 2>&1
#If available $? used to be zero
if [ 0 -eq $? ]
then
        unalias SampleRam
fi
unset -f SampleRam
SampleRam ()
{
        if [ 0 -eq $# ]
        then
                #if no parameter passed
                /usr/bin/top -n 1
        #Validating first parameter
        elif [ 1 -eq $# ] && [ "$(echo "$1" | /usr/bin/grep -iq "RAM";echo $?)" = "0" ]
        then
                #We can validate the same using $2 ... ${10} ...
                /usr/bin/top -n 1
        else
                echo "Update the function SampleRam using following parameter:"
                echo "SampleRam $@"
        fi
        #Or required command
        return $?
}
SampleRam
SampleRam ram
SampleRam RaM
SampleRam murugesandins
$ /bin/chmod u+x  ./SampleRam.sh
$ ./SampleRam.sh
...
Update the function SampleRam using following parameter:
SampleRam murugesandins
$

Open in new window

nociSoftware Engineer
BRONZE EXPERT
Distinguished Expert 2019
Commented:
sysstat might even be more handy then fiddeling with top/vmstat etc.  
(if you are after performance figures that is).
Collectd  might be better at collecting data ready for graphs.
CDP is a tool to help simple graphing, otherwise you can look into grafana for graphs.
marrowyungSenior Technical architecture (Data)

Author

Commented:
noci,

"sysstat might even be more handy then fiddeling with top/vmstat etc.  "

I don't have this command in CentOS.

what can I do ?  any screenshot the result of sysstat ?


"CDP is a tool to help simple graphing, otherwise you can look into grafana for graphs."

third party chargable tools ?


murugesandins,

"SampleRam ()"

you are creating a SampleRam.sh as a script and run it by doing ./SampleRam.sh ?


madunix,

I don't have iostat, what package I have to yum install ?

any screenshot the result of iostat ?

by your link:
https://lintut.com/best-command-line-tools-for-linux-performance-monitring/


I also don't not have dstat

any screenshot the result of dstat ?

BTW, other than top command for CPU, what other command can provide more information than top and also dynamic ?
nociSoftware Engineer
BRONZE EXPERT
Distinguished Expert 2019

Commented:
sysstat is the package, sa1 sa2 etc. are the command to run it and produce intermediate files (data collection) and reporting.
man sysstat  can help, you may need to install it first.

CGP, Grafana should all be FOSS.
https://grafana.org
https://github.com/pommi/CGP

iotop can be a dynamic viewer without recording on io statistics.
marrowyungSenior Technical architecture (Data)

Author

Commented:
"man sysstat
"

I don't have sysstat at all, can't man it

"iotop can be a dynamic viewer without recording on io statistics."

iotop also can't find in CentOS, what is missing?
murugesandinsWe like KT across the universe.  C C++ shell script Automation /bin/bash /bin/bash.exe /bin/ksh /bin/mksh.exe AIX CYGWIN_NT HP-UX Linux MINGW32 MINGW64 SunOS Windows_NT
BRONZE EXPERT

Commented:
>> "SampleRam ()"
>> you are creating a SampleRam.sh as a script and run it by doing ./SampleRam.sh ?
Yes.

sysstat iotop / ... (a. handle disk space b. Confirmation to install any applications c. git/svn/TFS/SMTP d. HTML document having the description, requirement, steps followed, Changes viewed before and after installation Example: /usr/bin/df -h, approved by, command executed by, dd-mmm-yyyy HH:mm:SS NN, start date, end date, location)
$#From root user or
$ /usr/bin/yum -y install sysstat
$ /usr/bin/sudo /usr/bin/yum -y install sysstat
$ /usr/bin/sudo /usr/bin/yum -y install iotop

Open in new window

murugesandinsWe like KT across the universe.  C C++ shell script Automation /bin/bash /bin/bash.exe /bin/ksh /bin/mksh.exe AIX CYGWIN_NT HP-UX Linux MINGW32 MINGW64 SunOS Windows_NT
BRONZE EXPERT

Commented:
Because of your comment I have installed dstat :) at my system
$ /usr/bin/yum -y install dstat

Open in new window

marrowyungSenior Technical architecture (Data)

Author

Commented:
yum -y install  ok, tks man.

"yum -y install sysstat"

but this one, once installed, still say command not found! iotop is ok


madunix,

"You can use iostat, it  can be used to report the disk read/write rate"

iostat is not dynamic, the result is not chaning over time.

I have to keep typing this command.
murugesandinsWe like KT across the universe.  C C++ shell script Automation /bin/bash /bin/bash.exe /bin/ksh /bin/mksh.exe AIX CYGWIN_NT HP-UX Linux MINGW32 MINGW64 SunOS Windows_NT
BRONZE EXPERT
Commented:
@marrowyung

#Include required directories based on requirement.
for REQUIREDDIR in /usr/local/sbin \
/usr/sbin \
/sbin \
/usr/local/bin \
/usr/bin \
/bin \
/etc/init.d \
/root/bin \
/usr/java/jdk1.6.0_31/bin \
/usr/kerberos/bin \
/usr/kerberos/sbin \
.
do
        if [ -d "$REQUIREDDIR" ]
        then
                if [ "." = "$REQUIREDDIR" ]
                then
                        echo "$PATH" |\
                        /usr/bin/grep -E ":\.:|:\.$|^\.:" >/dev/null 2>&1
                        if [ 0 -ne $? ]
                        then
                                export PATH="$PATH:$REQUIREDDIR"
                        fi
                elif [ "/etc/init.d" = "$REQUIREDDIR" ]
                then
                        echo "$PATH" |\
                        /usr/bin/grep -E ":\/etc\/init\.d:|:\/etc\/init\.d$|^\/etc\/init\.d:" >/dev/null 2>&1
                        if [ 0 -ne $? ]
                        then
                                export PATH="$PATH:$REQUIREDDIR"
                        fi
                elif [ "/usr/java/jdk1.6.0_31/bin" = "$REQUIREDDIR" ]
                then
                        echo "$PATH" |\
                        /usr/bin/grep -E ":\/usr\/java\/jdk1\.6\.0_31\/bin:|:\/usr\/java\/jdk1\.6\.0_31\/bin$|^\/usr\/java\/jdk1\.6\.0_31\/bin:" >/dev/null 2>&1
                        if [ 0 -ne $? ]
                        then
                                export PATH="$PATH:$REQUIREDDIR"
                        fi
                else
                        echo "$PATH" |\
                        /usr/bin/grep -E ":$REQUIREDDIR:|:$REQUIREDDIR$|^$REQUIREDDIR:" >/dev/null 2>&1
                        if [ 0 -ne $? ]
                        then
                                export PATH="$PATH:$REQUIREDDIR"
                        fi
                fi
        fi
done
#echo $PATH |\
#/usr/bin/tr ":" "\n"
#You can change required directory path per the requirement.
#Example:
$ export PATH="/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/usr/java/jdk1.6.0_31/bin:/bin:$ORACLE_HOME/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/home/murugesandins/bin:."
$#Change related directories /home/murugesandins/bin to required directories => /root/asd1/asd2 or ...

Open in new window


To handle dynamic I used to use (change 1 pid of init to related process)
$ /usr/bin/sudo /usr/bin/top -n 1
$ /usr/bin/sudo /usr/sbin/lsof -p 1
$ /usr/bin/sudo /usr/sbin/lsof -i:22

Open in new window

Better to know Required process name or Required process id for monitoring.

$ echo OUTPUT USING /usr/bin/top for process 1
OUTPUT USING /usr/bin/top for process 1
$ /usr/bin/top -n 1 -p 1 | /usr/bin/head -7
...
$ echo OUTPUT USING /usr/bin/top and /usr/bin/sed
OUTPUT USING /usr/bin/top and /usr/bin/sed
$ /usr/bin/top -n 1 -p 1 | /usr/bin/sed "s/^[//g;s/\[H//g;s/\[2J//g;s/(B\[m//g;s/\[[0-9][0-9]\;[0-9][0-9]m//g;s/\[K$//;s/\[[0-9]m//g;s/\[J//;s/\[[0-9]\;[0-9]H\[K\[[0-9][0-9]\;[0-9]H\[?[0-9][0-9]l\[?[0-9][0-9]h$//;s/\[[0-9]\;[0-9]H//;/^[:space:]*$/d"

[code]
$ /usr/bin/cat 29175082.sh
#!/usr/bin/bash
/usr/bin/clear
echo OUTPUT USING TOP
echo Press Enter
read
/usr/bin/top -n 1 -p 1 | /usr/bin/head -7
echo OUTPUT USING /usr/bin/top and /usr/bin/sed
echo Press Enter
read
/usr/bin/top -n 1 -p 1 | /usr/bin/sed "s/;s/\[H//g;s/\[2J//g;s/(B\[m//g;s/\[[0-9][0-9]\;[0-9][0-9]m//g;s/\[K$//;s/\[[0-9]m//g;s/\[J//;s/\[[0-9]\;[0-9]H\[K\[[0-9][0-9]\;[0-9]H\[?[0-9][0-9]l\[?[0-9][0-9]h$//;s/\[[0-9]\;[0-9]H//;/^[:space:]*$/d"

Open in new window

Either use related path to top, sed, ... OR top / sed ...
marrowyungSenior Technical architecture (Data)

Author

Commented:
hi,

are both query doing the same thing ?
murugesandinsWe like KT across the universe.  C C++ shell script Automation /bin/bash /bin/bash.exe /bin/ksh /bin/mksh.exe AIX CYGWIN_NT HP-UX Linux MINGW32 MINGW64 SunOS Windows_NT
BRONZE EXPERT

Commented:
@marrowyung

Leave my old comment.
I have given old comment on replacing special characters using sed.
Example:
$ /usr/bin/top -n 1 -p 1 | /usr/bin/head -1  > delete.txt

Open in new window

Content of delete.txt
(Btop - 07:16:17 up  1:45,  2 users,  load average: 0.00, 0.00, 0.00(B

Open in new window

Using sed we can obtain that file content at readable format:
$ /usr/bin/sed -i 's/^[//g;s/\[H//g;s/\[2J//g;s/(B//g;s/\[m//g;s/\[[0-9][0-9]\;[0-9][0-9]m\[K//g;' delete.txt

Open in new window

^[ => Ctrl v Ctrl => without space
Content of delete.txt
top - 07:16:17 up  1:45,  2 users,  load average: 0.00, 0.00, 0.00

Open in new window

murugesandinsWe like KT across the universe.  C C++ shell script Automation /bin/bash /bin/bash.exe /bin/ksh /bin/mksh.exe AIX CYGWIN_NT HP-UX Linux MINGW32 MINGW64 SunOS Windows_NT
BRONZE EXPERT
Commented:
Hence we can obtain the output of top command at readable format using:
$ /usr/bin/top -n 1 -p 1 > delete.txt

Open in new window

Content of delete.txt
(Btop - 07:18:35 up  1:47,  2 users,  load average: 0.00, 0.00, 0.00(B
Tasks:(B(B   1 (Btotal,(B(B   0 (Brunning,(B(B   1 (Bsleeping,(B(B   0 (Bstopped,(B(B   0 (Bzombie(B
Cpu(s):(B(B  0.1%(Bus,(B(B  0.2%(Bsy,(B(B  0.0%(Bni,(B(B 99.5%(Bid,(B(B  0.1%(Bwa,(B(B  0.1%(Bhi,(B(B  0.0%(Bsi,(B(B  0.0%(Bst(B
Mem: (B(B  2572484k (Btotal,(B(B   411564k (Bused,(B(B  2160920k (Bfree,(B(B    29940k (Bbuffers(B
Swap:(B(B  1048568k (Btotal,(B(B        0k (Bused,(B(B  1048568k (Bfree,(B(B   262464k (Bcached(B

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                  (B
(B    1 root      15   0 10360  760  632 S  0.0  0.0   0:01.08 init                                                                     (B
[?12l[?25h

Open in new window


We can make this output at readable format using:
$ /usr/bin/top -n 1 -p 1 | /usr/bin/sed "s/^[//g;s/\[H//g;s/\[2J(B\[m//g;s/(B\[m\[39\;49m\[K//g;s/(B\[m\[39\;49m(B\[m//g;s/(B\[m\[39\;49m//g;s/\[6\;1H//g;" > delete.txt

Open in new window

content of delete.txt
top - 07:30:22 up  1:59,  2 users,  load average: 0.00, 0.00, 0.00
Tasks:   1 total,   0 running,   1 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.1%us,  0.2%sy,  0.0%ni, 99.5%id,  0.1%wa,  0.1%hi,  0.0%si,  0.0%st
Mem:   2572484k total,   412252k used,  2160232k free,    30388k buffers
Swap:  1048568k total,        0k used,  1048568k free,   262464k cached

[7m  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                  
(B[m    1 root      15   0 10360  760  632 S  0.0  0.0   0:01.08 init                                                                     
[J[K[36;1H[?12l[?25h

Open in new window

murugesandinsWe like KT across the universe.  C C++ shell script Automation /bin/bash /bin/bash.exe /bin/ksh /bin/mksh.exe AIX CYGWIN_NT HP-UX Linux MINGW32 MINGW64 SunOS Windows_NT
BRONZE EXPERT
Commented:
$ /usr/bin/cat 29175082.sh
#!/bin/bash
#Here  pressing Ctrl v Ctrl [ without space
#Output at terminal
/usr/bin/top -n 1 -p 1
#OR
/usr/bin/top -n 1 -p 1 | /usr/bin/sed "s/;s/\[H//g;s/\[2J//g;s/(B\[m//g;s/\[[0-9][0-9]\;[0-9][0-9]m//g;s/\[K$//;s/\[[0-9]m//g;s/\[J//;s/\[[0-9]\;[0-9]H\[K\[[0-9][0-9]\;[0-9]H\[?[0-9][0-9]l\[?[0-9][0-9]h$//;s/\[[0-9]\;[0-9]H//;/^[:space:]*$/d"

echo -----------------------------
#Output redirected to delete.txt
/usr/bin/top -n 1 -p 1 | /usr/bin/sed "s/;s/\[H//g;s/\[2J//g;s/(B\[m//g;s/\[[0-9][0-9]\;[0-9][0-9]m//g;s/\[K$//;s/\[[0-9]m//g;s/\[J//;s/\[[0-9]\;[0-9]H\[K\[[0-9][0-9]\;[0-9]H\[?[0-9][0-9]l\[?[0-9][0-9]h$//;s/\[[0-9]\;[0-9]H//;/^[:space:]*$/d" > delete.txt

Open in new window


Output:
$ ./29175082.sh
top - 07:40:06 up  2:08,  2 users,  load average: 0.00, 0.00, 0.00
Tasks:   1 total,   0 running,   1 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.2%sy,  0.0%ni, 99.5%id,  0.1%wa,  0.1%hi,  0.0%si,  0.0%st
Mem:   2572484k total,   412580k used,  2159904k free,    30724k buffers
Swap:  1048568k total,        0k used,  1048568k free,   262468k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
    1 root      15   0 10360  760  632 S  0.0  0.0   0:01.08 init



























top - 07:40:07 up  2:08,  2 users,  load average: 0.00, 0.00, 0.00
Tasks:   1 total,   0 running,   1 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.2%sy,  0.0%ni, 99.5%id,  0.1%wa,  0.1%hi,  0.0%si,  0.0%st
Mem:   2572484k total,   412720k used,  2159764k free,    30724k buffers
Swap:  1048568k total,        0k used,  1048568k free,   262468k cached
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
    1 root      15   0 10360  760  632 S  0.0  0.0   0:01.08 init
-----------------------------

Open in new window

Content of delete.txt
top - 07:40:07 up  2:08,  2 users,  load average: 0.00, 0.00, 0.00
Tasks:   1 total,   0 running,   1 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.2%sy,  0.0%ni, 99.5%id,  0.1%wa,  0.1%hi,  0.0%si,  0.0%st
Mem:   2572484k total,   412844k used,  2159640k free,    30724k buffers
Swap:  1048568k total,        0k used,  1048568k free,   262468k cached
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                  
    1 root      15   0 10360  760  632 S  0.0  0.0   0:01.08 init                                                                     

Open in new window

marrowyungSenior Technical architecture (Data)

Author

Commented:
tks will check it soon as I am preparing other task, tks for it.

seems i need to learn bash command and linux script?

so I need to create a .sh file and when run it  with your content above, I just do that on the command line:

#/<my sh file>.sh ?
murugesandinsWe like KT across the universe.  C C++ shell script Automation /bin/bash /bin/bash.exe /bin/ksh /bin/mksh.exe AIX CYGWIN_NT HP-UX Linux MINGW32 MINGW64 SunOS Windows_NT
BRONZE EXPERT

Commented:
Yes.
I feel that $PS1 at your current terminal is #
Assume that your file name is 29175082.sh

Example codes to execute ./29175082.sh
$ echo "Value of PS1 [$PS1]"
Value of PS1 [$ ]
$ export PS1='# '
# echo "Value of PS1 [$PS1]"
Value of PS1 [# ]
# ./29175082.sh
....
...
related output
....
#

Open in new window

nociSoftware Engineer
BRONZE EXPERT
Distinguished Expert 2019
sysstat commands are: sar sadc .  (iostat, mpstat, tapestat, etc.)  and consists of some cron jobs & config files.
( /etc/sysstat  & /etc/sysstat.ioconf ).

reports & files are left in /var/log/sa
marrowyungSenior Technical architecture (Data)

Author

Commented:
murugesandins,

$ echo "Value of PS1 [$PS1]"

the command prompt is #, so why the $ is need in this case ?

or $ is just say it is a variable ?

I feel that $PS1 at your current terminal is #

so you mean $ is the terminal command prompt symbol at my end ?

noci,

reports & files are left in /var/log/sa

tks , but what is this suppose to mean?

sysstat commands are: sar sadc .  (iostat, mpstat, tapestat, etc.)  and consists of some cron jobs & config files.
( /etc/sysstat  & /etc/sysstat.ioconf ).

so for SOME command only I need to vi the config file too if I need to run them ? seems too much work to run a command to check OS resource..
marrowyungSenior Technical architecture (Data)

Author

Commented:
tks al. but I will come back later as I still have other things to do.
nociSoftware Engineer
BRONZE EXPERT
Distinguished Expert 2019
Monitoring system resources is watching for trends... that is load over time... (days, weeks, months) with various densities in intervals.

sysstat is something that runs permanently (from cron) and produces daily reports. you will have to configure if you want 5 days retension or 20 days retension. etc.
most of the monitoring tools need some kind of configuration. Even top might need that. (unless the defaults are sufficient).

Prompt are: by default: # denoting root, $  indicating normal user.
PS1 is a variable,.. to make a more elaborate prompt. in setting the PS1 string normal bash exapnsions rules are used:
so X="-$Y-"   means X get the vaue of Y with a dash before & after.  (the expansion is done during assigning the string, not when showing the prompt).

For PS1 prompt there are also some expantions done during showing of the prompt: \h, \u etc for hostname & username.
murugesandinsWe like KT across the universe.  C C++ shell script Automation /bin/bash /bin/bash.exe /bin/ksh /bin/mksh.exe AIX CYGWIN_NT HP-UX Linux MINGW32 MINGW64 SunOS Windows_NT
BRONZE EXPERT
$ echo wELcOME | /usr/bin/wc > /dev/null 2>&1