统计本机内存情况和使用状况的脚本

简介: #fetch and process memory information   [ -f /proc/meminfo ] && {  #First judge whether the file exists   #-e是模式的意思,常用来保护以破折号开头的模式。
  1. #fetch and process memory information  
  2. [ -f /proc/meminfo ] && {  #First judge whether the file exists  
  3. #-e是模式的意思,常用来保护以破折号开头的模式。  
  4. #-w是全字匹配。  
  5. #-i忽略大小写。  
  6. #-d指定分割符,-f为按照分割符取出的域,2-指的是域2及以后  
  7. Buffers=`grep -we 'Buffers' /proc/meminfo | cut -d' ' -f2- | tr -d "[A-Z][a-z] "`  
  8. Cached=`grep -we 'Cached' /proc/meminfo | cut -d' ' -f2- | tr -d "[A-Z][a-z] "`  
  9. MemFree=`grep -ie 'MemFree' /proc/meminfo | cut -d' ' -f2- | tr -d "[A-Z][a-z] "`  
  10. MemTotal=`grep -ie 'MemTotal' /proc/meminfo | cut -d' ' -f2- | tr -d "[A-Z][a-z] "`  
  11. SwapCached=`grep -ie 'SwapCached' /proc/meminfo | cut -d' ' -f2- | tr -d "[A-Z][a-z] "`  
  12. SwapFree=`grep -ie 'SwapFree' /proc/meminfo | cut -d' ' -f2- | tr -d "[A-Z][a-z] "`  
  13. SwapTotal=`grep -ie 'SwapTotal' /proc/meminfo | cut -d' ' -f2- | tr -d "[A-Z][a-z] "`  
  14. }  
  15.   
  16. MEMUSED="$(( ( ( ( $MemTotal - $MemFree ) - $Cached ) - $Buffers ) / 1024 ))"  
  17. MEMTOTAL="$(( $MemTotal / 1024))"  
  18. MEMFREE="$(( $MEMTOTAL - $MEMUSED ))"  
  19. MEMPER="$(( ( $MEMUSED * 100 ) / $MEMTOTAL ))"  
  20. "$SwapTotal" -gt "1" ] && {  
  21.   SWAPUSED="$(( ( ( $SwapTotal - $SwapFree ) - $SwapCached ) / 1024 ))"  
  22.   SWAPTOTAL="$(( $SwapTotal / 1024))"  
  23.   SWAPFREE="$(( $SWAPTOTAL - $SWAPUSED ))"  
  24.   SWAPPER="$(( ( $SWAPUSED * 100 ) / $SWAPTOTAL ))"   
  25. } || {  
  26.   SWAPUSED="0"  
  27.   SWAPTOTAL="0"  
  28.   SWAPPER="0"   
  29. }  
  30.   
  31. # display the information  
  32. /bin/echo  
  33. /bin/echo "Memory"  
  34. /bin/echo "Used: $MEMUSED MB"  
  35. /bin/echo "Free: $MEMFREE MB"  
  36. /bin/echo "Total: $MEMTOTAL MB"  
  37. /bin/echo  
  38. /bin/echo "Swap"  
  39. /bin/echo "Used: $SWAPUSED MB"  
  40. /bin/echo "Free: $SWAPFREE MB"  
  41. /bin/echo "Total: $SWAPTOTAL MB"  
  42. /bin/echo  
目录
相关文章
|
7月前
|
Oracle 关系型数据库 Linux
解决在linux服务器上部署定时自动查找cpu,内存,磁盘使用量,并将查询结果写入数据库的脚本,只能手动运行实现插库操作
问题描述:将脚本名命名为mortior.sh(以下简称mo),手动执行脚本后查询数据库,表中有相应的信息,放入自动执行队列中,脚本被执行,但是查询数据库,并没有新增数据。
54 0
|
7月前
|
Shell 测试技术 Linux
通过shell脚本进行linux服务器的CPU和内存压测
通过shell脚本进行linux服务器的CPU和内存压测
225 0
|
1月前
|
存储 弹性计算 运维
调整虚拟机内存参数的 shell 脚本
【4月更文挑战第29天】
28 2
|
1月前
|
数据处理 开发者 Python
python 代码内存统计
【4月更文挑战第9天】
|
1月前
|
存储 弹性计算 运维
调整虚拟机内存参数的shell 脚本
【4月更文挑战第29天】
24 0
|
1月前
|
存储 监控 异构计算
【Python】GPU内存监控脚本
【Python】GPU内存监控脚本
|
1月前
|
监控 Shell
Shell脚本监控CPU、内存和硬盘利用率
Shell脚本监控CPU、内存和硬盘利用率
|
1月前
|
存储 负载均衡 算法
负载均衡案例:如何只用2GB内存统计20亿个整数中出现次数最多的整数
负载均衡案例:如何只用2GB内存统计20亿个整数中出现次数最多的整数
46 2
|
7月前
|
Shell
使用 shell 脚本清理内存 buff/cache
使用 shell 脚本清理内存 buff/cache
124 0
|
11月前
|
存储 Prometheus Cloud Native
FinOPS之 节点内存态统计和计算Node-metrics
董江,容器技术布道者及实践者,中国移动高级系统架构专家,曾担任华为云核心网技术专家,CloudNative社区核心成员,KubeServiceStack社区发起者,Prometheus社区PMC,Knative Committer,Grafana社区Contributer。 欢迎关注:https://kubeservice.cn/
FinOPS之 节点内存态统计和计算Node-metrics