Unam1024 / TemplateOSLinux-plus

MIT License
6 stars 6 forks source link

Negative value for used memory #3

Open evgeniy-pupkov opened 6 years ago

evgeniy-pupkov commented 6 years ago

Hello! I'm receiving negative values for used memory item. It is related to '-w ' key for 'free' command in a script.

#cat /etc/redhat-release 
CentOS Linux release 7.5.1804 (Core)

But running 'free' with no -w gives:

#free
              total        used        free      shared  buff/cache   available
Mem:        3879576      345564     1706380      190400     1827632     3000856

And so, $2-$4-$6-$7 gives negative value.

Running 'free' with -w gives values, that are good after arithmetics:

              total        used        free      shared     buffers       cache   available
Mem:        3879576      345320     1706488      190400        2088     1825680     3001084

$2-$4-$6-$7 = 345320

I gonna remove this check in my setup and hardcode free -w, but it's kind a crutch. May be it's better to check 'free' version instead of release?

# free --version
free from procps-ng 3.3.10
hjfeng1988 commented 6 years ago

I find this problem too,Script memory_zabbix_master_item.sh must suit CentOS 6.X,Not CentOS 7.X.

MemUsage=`free | awk 'NR==2 {printf("%d %d %d %d",$2,$4,$6,$7)}'`
Cached=`echo $MemUsage | awk '{print $4}'`

On CentOS 7.x,Command free seventh column is available