Centos record commonly used commands

Foreword

Because the needs of the project need to find memory, disk read and write, performance and other data on centos command, need to be integrated, and show it in written in Python web, so finishing something.

1. Memory

free -g

              total        used        free      shared  buff/cache   available
Mem:             15           0           0           0          14          14
Swap:             7  

Check out the data or not to be treated so directly detect processed data
free -g |awk 'NR==2 {print "{\"total_memory\":"$2"}"}'
so check out the data pretty much.

{"total_memory":15}

2. CPU

lscpu
Here Insert Picture Description
I just need this thing, so it changed the next.
lscpu |sed -n '4p'|awk '{print "{\"CPU\":"$2"}"}'

{"CPU":8}

3. The total amount of disk capacity and disk remaining

dfCheck out this more difficult to read,
so were consolidated
df -Ph /data |awk '{if(NR >1) print "{\"total_disk\":\""$2"\"}"}'disk total
df -Ph /data |awk '{if(NR >1) print "{\"avail_disk\":\""$4"\"}"}'remaining amount of disk
can also be combined query.

df -Ph /data |awk '{if(NR >1)  print "{\"total_disk\":\""$2"\",\"avail_disk\":\""$4"\"}"}'

Data out is good to see the json format.

4. The read and write speed of the disk

Use the iostat this is the need to install, can be installed under.
I direct this integration,

iostat  |grep -v "dm" |awk '{ if(NR >6 && $1 != "") {print "{\"disk_name\":\""$1 "\",\"disk_read\":"$3 ",\"disk_write\":"$4"}"}}'\

The operating system version

cat /etc/redhat-release |awk '{print $1,$2"-"$3,$4}'

postscript

These are the operation and maintenance help me write, and began learning now to the operation and maintenance of knowledge and organize our department. If badly written, or you have a better hope Daniel criticism.

Published 31 original articles · won praise 4 · Views 2995

Guess you like

Origin blog.csdn.net/judgerwang/article/details/104917946