Linux free command

81 views
Skip to first unread message

jvan

unread,
Mar 5, 2010, 7:45:13 AM3/5/10
to dim_STAT
Hello All,

To detect memory leaks we want to use the free command on linux
machines.

Output of free:
#free
total used free shared buffers
cached
Mem: 5972748 5901336 71412 0 468256
4314976
-/+ buffers/cache: 1118104 4854644
Swap: 32764528 99640 32664888

Via awk i make one line of this output:
free -s 5 | awk ' /[[:digit:]]/ { if ($1 == "Mem:") printf("%s %s %s
%s %s %s ", $2, $3, $4, $5, $6, $7); if ($1 == "-/+") printf("%s %s ",
$3, $4); if ($1 == "Swap:") printf("%s %s %s\n", $2, $3, $4);}'

5972748 5899368 73380 0 468256 4315036 1116076 4856672 32764528 99640
32664888
5972748 5907752 64996 0 468256 4315040 1124456 4848292 32764528 99640
32664888
5972748 5900940 71808 0 468256 4315048 1117636 4855112 32764528 99640
32664888
5972748 5913076 59672 0 468256 4315052 1129768 4842980 32764528 99640
32664888
5972748 5900788 71960 0 468256 4315056 1117476 4855272 32764528 99640
32664888
5972748 5900820 71928 0 468256 4315060 1117504 4855244 32764528 99640
32664888

I have created a script LfreeSTAT.sh

#cat LfreeSTAT.sh
#!/bin/ksh
exec /usr/bin/free -s 5 | /bin/awk ' /[[:digit:]]/ { if ($1 == "Mem:")
printf("%s %s %s %s %s %s ", $2, $3, $4, $5, $6, $7); if ($1 == "-/+")
printf("%s %s ", $3, $4); if ($1 == "Swap:") printf("%s %s %s\n", $2,
$3, $4);}'

Gives the same output as above.

Changed the access file to include this script and restart the
STATsrv.
command Test /etc/STATsrv/bin/LfreeSTAT.sh

Created an add-on-STAT:
#
=======================================================================
# Test: dim_STAT New STAT Description
#
=======================================================================
Test
11
0
Test Statistic(s)
Test %i


#
=======================================================================
# Column: column3 (Mem_total)
#
=======================================================================
column3
1
1
Mem_total
free total physical memory
0
#
=======================================================================
# Column: column4 (Mem_used)
#
=======================================================================
column4
1
2
Mem_used
free used physical memory
0
#
=======================================================================
# Column: column5 (Mem_free)
#
=======================================================================
column5
1
3
Mem_free
free free physical memory
0
#
=======================================================================
# Column: column6 (Mem_shared)
#
=======================================================================
column6
1
4
Mem_shared
free shared physical memory
0
#
=======================================================================
# Column: column7 (Mem_buffers)
#
=======================================================================
column7
1
5
Mem_buffers
free buffers physical memory
0
#
=======================================================================
# Column: column8 (Mem_cached)
#
=======================================================================
column8
1
6
Mem_cached
free cached physical memory
0
#
=======================================================================
# Column: column9 (Application_used)
#
=======================================================================
column9
1
7
Application_used
free used physical - buffers - cached
0
#
=======================================================================
# Column: column10 (Application_free)
#
=======================================================================
column10
1
8
Application_free
free total physical - Application_used
0
#
=======================================================================
# Column: column11 (swap_total)
#
=======================================================================
column11
1
9
swap_total
free total swap memory
0
#
=======================================================================
# Column: column12 (swap_used)
#
=======================================================================
column12
1
10
swap_used
free used swap memory
0
#
=======================================================================
# Column: column13 (swap_free)
#
=======================================================================
column13
1
11
swap_free
free free swap memory
0

I can select it when creating a new collect. But i never see the
collects when i wont to analyze the inputs.
In the /etc/STATsrv/log/access.log logfile I see next:
STATsrv-25095:> Connect -> [138.203.236.96] CMD= "STAT_LIST" TIME: Fri
Mar 5 13:34:55 2010
STATsrv-25095:> Exit -> [138.203.236.96] CMD= "STAT_LIST" TIME: Fri
Mar 5 13:34:55 2010
STATsrv-25099:> Connect -> [138.203.236.96] CMD= "STAT_LIST" TIME: Fri
Mar 5 13:34:57 2010
STATsrv-25099:> Exit -> [138.203.236.96] CMD= "STAT_LIST" TIME: Fri
Mar 5 13:34:57 2010
STATsrv-25100:> Connect -> [138.203.236.96] CMD= "STAT_LIST" TIME: Fri
Mar 5 13:34:57 2010
STATsrv-25100:> Exit -> [138.203.236.96] CMD= "STAT_LIST" TIME: Fri
Mar 5 13:34:57 2010
STATsrv-25441:> Connect -> [138.203.236.96] CMD= "Test 5" TIME: Fri
Mar 5 13:35:05 2010
STATsrv-25831:> Connect -> [138.203.236.96] CMD= "Test 5" TIME: Fri
Mar 5 13:35:55 2010
STATsrv-26437:> Connect -> [138.203.236.96] CMD= "Test 5" TIME: Fri
Mar 5 13:36:45 2010
STATsrv-27145:> Connect -> [138.203.236.96] CMD= "Test 5" TIME: Fri
Mar 5 13:37:35 2010
STATsrv-27846:> Connect -> [138.203.236.96] CMD= "Test 5" TIME: Fri
Mar 5 13:38:25 2010
STATsrv-28589:> Connect -> [138.203.236.96] CMD= "Test 5" TIME: Fri
Mar 5 13:39:15 2010
STATsrv-29172:> Connect -> [138.203.236.96] CMD= "Test 5" TIME: Fri
Mar 5 13:40:05 2010
STATsrv-29531:> Connect -> [138.203.236.96] CMD= "Test 5" TIME: Fri
Mar 5 13:40:55 2010

#psg free
root 25443 25442 0 13:35 pts/6 00:00:00 /usr/bin/free -s 5
root 25833 25832 0 13:35 pts/6 00:00:00 /usr/bin/free -s 5
root 26439 26438 0 13:36 pts/6 00:00:00 /usr/bin/free -s 5
root 27147 27146 0 13:37 pts/6 00:00:00 /usr/bin/free -s 5
root 27848 27847 0 13:38 pts/6 00:00:00 /usr/bin/free -s 5
root 28591 28590 0 13:39 pts/6 00:00:00 /usr/bin/free -s 5
root 29174 29173 0 13:40 pts/6 00:00:00 /usr/bin/free -s 5
root 29533 29532 0 13:40 pts/6 00:00:00 /usr/bin/free -s 5

So it starts every 50 sec a new free process.
What I'm a doing wrong?

Greetings,

Joey

(dim)

unread,
Mar 5, 2010, 8:56:07 AM3/5/10
to dim_STAT
Hi Joey,

let's start from the beginning: first of all let's fix your command
printing free output..

1. you set a fixed timeout within your script, so it'll not print data
on a requested interval :-)
2. you pipe the whole output to "awk" which is not flushing your data
by default (to check it you may simply start:
$ LfreeSTAT.sh | more

and you'll see that even within 1 minute there will be no output :-)
and that's the main problem why you don't see any data :-)

To fix it quickly you may change your script to:

===========================================================
while true
do
/usr/bin/free | /bin/awk ' /[[:digit:]]/ { if ($1 == "Mem:")


printf("%s %s %s %s %s %s ", $2, $3, $4, $5, $6, $7); if ($1 == "-/

+")
printf("%s %s ", $3, $4); if ($1 == "Swap:") printf("%s %s %s\n",
$2,
$3, $4);}'

sleep $1
done
===========================================================

in this case:
$ LfreeSTAT.sh 10

will really print data every 10 sec. and as awk will be involved on
each iteration the output will be flushed for sure :-)

then if you want to get a more in depth data about memory usage on
your Linux system you may write a script getting data directly from "/
proc/meminfo"

After that I think everything will work for you :-) as well you may
get a look on some debug tips discussed within this thread:
http://groups.google.com/group/dimstat/browse_thread/thread/47df741ed10aa96f

Rgds,
-Dimitri

jvan

unread,
Mar 5, 2010, 9:28:18 AM3/5/10
to dim_STAT
Hey Dimitri,

This does the job, thanks a lot.

Greetings,

Joey

CapPlan

unread,
Mar 5, 2010, 9:57:42 AM3/5/10
to dim_STAT
Hi Joey and Dimitri,

I spotted something in this thread and want to ask for clarifications:

Joey mentioned "Changed the access file to include this script and
restart the STATsrv."

- Is this to update the STAT_LIST or is there another reason for
restarting the STATsrv?

- How can a new add-on STAT like this LfreeSTAT.sh be added to an
existing collect using the same collect ID? I am hoping to be able to
add the new STAT without having to stop an active collect, recycle the
ID then restart the collect with the new STAT. I want to avoid losing
collected data (or having to save and restore).

Thanks for your input,
Tom

Dimitri

unread,
Mar 5, 2010, 12:55:51 PM3/5/10
to dim...@googlegroups.com
Hi Tom,

1. you never need to stop STAT-service :-) except if you want to
upgrade it to the newer version or simply want to suspend collects for
a while, etc.

2. there is no "normal" way to add any new STAT into an already
existing collect, as well you don't need to keep the same collect
forever for every server - at any time you may stop an existing
collect, and simply start a new one (with a new ID) including more or
less stats according your needs :-)

But well, as everything is based on scripts too, you may always hack
them to do what you want ;-) - every time when you're starting a new
collect there is a restart script created automatically.. - it's
called ".restart.{DBNAME}.{CollectID}" and you may find it generally
under "/apps/client". You may edit the file corresponding to your DB
and collect, and change the line containing the list of STATs and add
or remove some of them - so on the next stop/restart you'll see more
or less stats within your collect :-)

Rgds,
-Dimitri

> --
> You received this message because you are subscribed to the Google Groups
> "dim_STAT" group.
> To post to this group, send email to dim...@googlegroups.com.
> To unsubscribe from this group, send email to
> dimstat+u...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/dimstat?hl=en.
>
>

CapPlan

unread,
Mar 5, 2010, 2:09:25 PM3/5/10
to dim_STAT
Hi Dimitri,

I knew there had to be a way :-)

So there are still more undocumented features.. the hidden .restart
files!

Thanks very much for the quick response, this is great!
Tom

(dim)

unread,
Mar 5, 2010, 5:56:14 PM3/5/10
to dim_STAT
Hi Tom,

I cannot call it "feature" - it's more likely a hack :-)
as well you may hack many things in dim_STAT or do things in different
manner, etc.
For example, historically there are start and stop scripts which are
created on every new collect, and you have an option to start the
collect or just create these scripts (and I wanted already to remove
it, but there are still some users who use these scripts and not
starting collects via web interface :-))

But well, better you know how the tool is working - more confident
you're (at least it's what I think) - so nothing hidden, just ask :-))

Rgds,
-Dimitri

Message has been deleted

jvan

unread,
Mar 9, 2010, 3:04:46 AM3/9/10
to dim_STAT
Hi Dimitri,

I have still one more question. I made some changes in the Add-On STAT
description manually(Just another name for 2 columns), then i deleted
the one i was using and restored the changed Add-On. For new collect
this is working fine, but the old collects i have made with the old
Add-On seem to be lost? Is there a way to recover them or are they
lost forever?

Kr,

Joey

Alain Chéreau

unread,
Mar 9, 2010, 3:32:25 AM3/9/10
to dim...@googlegroups.com
Hi Joey,

When you create a new Add-On stat, Dimstat create a table
in the MySQL database to store your data.
The list, type and name of columns is defined by your stat description.

When you create a new Add-On stat with the name of an old one,
dimstat drop the old table and create the new one.

If you have not made a backup before, there is no way to get your old data back.

Regards.

Alain.
 
2010/3/9 jvan <Joey.Van_...@alcatel-lucent.com>
Hi Dimitri,
--

Dimitri

unread,
Mar 9, 2010, 4:24:51 AM3/9/10
to dim...@googlegroups.com
Thanks Alain - it's exactly how it works :-)
Add-On is a high level operation, so every time you create a new
Add-On it'll cleanup all information in the database corresponding to
its name (and drop any corresponding tables too). And as you may see
there is no "Modify" option in web interface - only Add New or Delete
(and Restore is managed as Add New) - so you drop all Add-On data on
every operation (except Save :-)).

Rgds,
-Dimitri

>> dimstat+u...@googlegroups.com<dimstat%2Bunsu...@googlegroups.com>

Reply all
Reply to author
Forward
0 new messages