Process monitoring using top, gnuplot and ruby

Had been thinking a lot and (not doing anything) researching on the web to find methods to monitor specific application performances, i.e. %CPU, %RAM utilization, etc.

Having had a Lenovo G400 for about 8 years now with 1 GB RAM, and still making passes at compilers. Recent applications are all about user experience and all the unwanted glitter. And I had to be informed about ones that are a hog, to be blown out.

Finally got myself to script a monitoring.

In a nutshell, I launch the script to monitor resources using top and log to a file. Use the app, launch, do stuff, exit.Stop monitoring and generate the application performance profile.

> ./ptool.rb mtop
> ./ptool.rb mtop_kill
> ./ptool.rb mtop_report > mtop.csv

And a small script to generate the graph using gnuplot.
> ./mtop.plot

google-chrome-stable/Version 37.0.2062.120/Arch Linux 32bit
google-chrome

chromium/Version 37.0.2062.120 (281580)/Arch Linux 32bit
chromium

Below is the code listing:

#!/usr/bin/ruby
# name: ptool.rb
# author: bucket.size@gmail.com

require 'pp'

USER='jb'
PUSER='jb'
PNAME='chrom'

TI = { cpu: 8, mem:9 }

def mtop tag='sys', remote='localhost'
  cmd = "top -u #{PUSER} -d 2 -b > /tmp/top_#{tag}-#{remote}.log &"
  if remote != 'localhost'
    cmd = "rsh #{USER}@#{remote} "+cmd
  end
  puts cmd
  system(cmd)
end

def mtop_kill tag='sys', remote='localhost'
  cmd = "pkill -f \"top -u #{PUSER} -d 2 -b\" &"
  if remote != 'localhost'
    cmd = "rsh #{USER}@#{remote} "+cmd
  end
  system(cmd)
end

def mtop_report tag='sys', remote='localhost'
  r, t, acpu, amem =[], 0.0, 0.0, 0.0
  File.open("/tmp/top_#{tag}-#{remote}.log") do |f|
    acc=[]
    f.each_line do |line|
      # accum
      if (line =~ /#{PNAME}/)
        # puts line
        cpu, mem = line.split(" ")[TI[:cpu]].to_f, line.split(" ")[TI[:mem]].to_f
        acc << [cpu, mem]
      end

      # reduce/iter
      if (line =~ /^top/)
        #pp acc
        #puts '-------------'
        ccpu, cmem = 0.0, 0.0
        acc.each do |e|
          ccpu, cmem = ccpu+e[0], cmem+e[1]
        end
        acc=[]
        acpu, amem = acpu+ccpu, amem+cmem
        r << [t += 2, ccpu, cmem]
      end
    end
  end
  # average
  r << [acpu/r.size, amem/r.size]
  cvs_out r
  r
end

def cvs_out rlist
  av = rlist.pop
  puts "time,cpu,mem,acpu,amem"
  r = rlist.each do |e|
    puts "#{e[0]},#{e[1]},#{e[2]},#{av[0]},#{av[1]}"
  end
end

self.send ARGV[0]
#!/usr/bin/gnuplot
# adapted from (http://gnuplot.sourceforge.net/demo/histograms.1.gnu)
# name: mtop.plot
# author: bucket.size@gmail.com

#set terminal pngcairo  transparent enhanced font "arial,10" fontscale 1.0 size 800, 300 
set terminal pngcairo  enhanced font "arial,10" fontscale 1.0 size 800, 300
set output 'mtop.png'
set key inside right top vertical Right noreverse noenhanced autotitles nobox
set datafile missing '-'
#set style data linespoints
set style data lines
set xtics border in scale 1,0.5 nomirror rotate by -45  offset character 0, 0, 0 autojustify
set xtics  norangelimit font ",8"
set xtics   ()
set title "app. perf. data"
set datafile separator ","
plot 'mtop.csv' using 1:2 title '%cpu',\
      '' using 1:3 title '%mem',\
      '' using 1:4 title 'a-cpu',\
      '' using 1:5 title 'a-mem'

share linux partitions using samba over LAN

Partitions can be automounted either by linux or nautilus on access.

set up partition mounts points correctly

Partitions can be automounted either by linux or nautilus on access.

  1. partitions automounted on access from nautilus don’t work well with samba

    this is something todo with ‘fuseblk’ driver or access parameter

    line from mtab that quirks with samba

    /dev/sda6 /media/swetha/sg fuseblk rw,nosuid,nodev,allow_other,default_permissions,blksize=4096 0 0

  2. edit /etc/fstab to manually configue mounting.

    below config works and is accessible for all users.

    /dev/sda6 /media/sg ntfs-3g defaults,windows_names,locale=en_US.utf8 0 0

  3. remount

    sudo umount /dev/sda6 sudo mount -a

set up samba share correctly

Nautilus provides a way to create temporary network shares.

  1. don’t create shares from nautilus, disable all shares managed by nautilus.
  2. install smbd, samba
  3. install system-config-samba.

    apt-get install system-config-samba

  4. create shares using system-config-samba run as root with sudo.

    sudo system-config-samba

    select the folder to which to partition is mounted

    set visible

    set access to users

  5. restart samba

    sudo service smbd restart

Given your ubuntu box IP address is 192.168.1.10.

You should now be able to access all the linux shares at \\192.168.1.10 or from another linux box at smb://192.168.1.10.

Filing my first RTI

Noted a discrepancy in claim settling with a bank. Decided to get the records of the recurrent deposits made.

RTI Act, 2005 is a Law that provides a machinery for a Citizen to exercise and realize his basic right – Right To Information.

Its actually quite simple to seek information under this Act and it is very legally binding.

I’ll elaborate more on that later. For starters, it’s just best to read up the Act publication. It’s about 27 pages in total, the first 14 being relevant and adequate for a first time applicant.

http://rti.gov.in/rti-act.pdf

The documentation does not provide for a requisition form template, hence created one for the above purpose – template.

Dawn unto the dinosaur

Been out of blogging for a while and now just out of curiosity, just logged in. Glad I started it a couple of years back. But it’s just that if feel the world or my thoughts have regressed. I’ve just become or am becoming like everybody else, in a way of saying that I’m becoming a nobody.

Well, actually I don’t really fret not blogging this whole duration of blog-a-llectual slumber. Its just that I had to switch between a couple of jobs to better my financial stand in order to find a bride and get married (the way it is in this geo-social-space ). Now having done that, feel a bit relieved.

Nevertheless the sense of accomplishment that was always a part of for having done nothing that add path to anything worth having, is being efferently evasive. That again to say that I have it but I don’t quite have it altogether as opposed to the saying earlier that I have it, but not quite yet.

I need to definitely clean up stuff, start from scratch, root & reboot.

Afraid? Try faith!

First came friendship, life found a way to keep itself by having a friend always around in need, in face of danger, to ward of a threat, as a means of rescue or to better affect preemption.

Then came the clan-ism, a higher order social construct with rigid rules enforcing efficiency and planning.

Present day society lies somewhere in between, where the clan-ism has faded into a backdrop that’s diluted to what stands as ‘governing body’ in civilizations. And the rules are malleable and fluid, perhaps to allow expansion than survival as if the former has been guaranteed.

Except, its not the individual’s but rather the society’s that’s granted. Yes, society does perceive individualism as it’s greatest threat. And hence an individual is granted everything the society offers, as long has he remains a part of and progresses it’s ideals, and nothing when he goes against its norm’s.

Individualism occurs in society for 2 reasons as best as I can comprehend. Individual’s vested interest. Another, is evolution.

Evolution is the tendency of anything living, organism or an idea that is society. But why this resistance to anything that’s good. Well, it’s evolution again at play. Evolution occurred by survival of the fittest. Hence, domination of the fittest change needs to be resisted, that’s the objective.

To pass on a good and that advocation is individuality. To be dominated and extinguished by a germ that is a better change is society’s fear. That’s everyone’s fear.

Religion, was it one of society’s response to preserve itself. Make it immune to individualism by granting it hypothetically for it’s subjugation in the present. Or to make established norms more difficult to be unseated, hence demand better individualism, or continuation of the best yet. Those are 2 deliberate line of thought surrounding religion, but one thing religion itself did not expect to come along, evolution.

Currently it’s the later line of thought that’s evanescent in its proceedings. Demand better individuals. Allow for personal growth. Encourage change but with test. Rather suppression of development.

Enter Faith.

Everyone’s afraid

Fear, one of the primal perceptions granted by nature. Is it a bane or really a boon, or does it really matter in being a human.

Place a finger on an ant line and they scatter to avoid the imminent threat of being crushed or eaten by the bigger ones. Switch on the lights and you see roaches run for cover even in the most seemingly sane environment. Felines do a back flip at your sudden gestures. Given the ultimate goal of a creature is survival and sustenance, fear be interpreted as part of perception to an immideate threat, one so powerfull as to cause a sentient response to up the odds to survival. And sentient as I see fit is any creature with a behavioral pattern to respond logically to a set of stimuli and with the ability to better the response with experience, as being the definition.

So is it suffice to say if there is an elephant on my road to work, we humans will scatter, scam, find a cave to hide away in. This brings me to ask, are there different responses to fear? Even among the same of the species, and even perhaps the same individual , i.e. not being a better response on the lines of sentence, but more in being completely unrelated by experience. Is fear perceived differently by different creatures, is this also situational?

At this juncture let me add a bit to my definition of sentence, ie to be able to perceive the inputs better or differently with experience.

Ant lines will now go around your finger, since you haven’t killed or eaten away many, and the neighbours cat may get bored of sporting the back flip for you eventually.

But elephants do attack sometimes. Enter preemption.

The big ones feel fear too, this not being so obvious, but preemption is a natural response to fear. One that allows you to eliminate the threat than escape it.

But they don’t always, and tigers may not always stalk and hunt you.

Most wildlife will tend to ignore or better avoid you, this from the numerous Nat Geo docs I’ve passed time with. But there is no identifiable patterned pathway to when they attack or behave differently. The best I’ve seen Nat Geo / others narrates is ‘this time he wasn’t so lucky.’

Thread perception hence fear and response is complicated. With primates, its understandable that we may never come to understand the dynamics of perception and response to fear.

Evolution hence gave us numerous weapons: scales, claws, clans.

Then came the threat from ourselves …..

Empowerment is about balance that’s timed right

Just yesterday, returned home and reluctantly was going about the mails, sorting through mostly yet again, credit card and personal loan offers to get to some proposal mails that I should have got a couple of days back.

Boring stuff mostly, but just then I got hit by a unexpected forward of a mail from a friend. She was bitter about or at least supportive of the embitterment one would surround the way the movie ‘Cocktail’ turned out to be in its portrayal of ‘women being subdue by society and sacrificing greatness inorder to be accepted.

I was a nice read indeed …. but then got me thinking about what would I do, had I been the protagonist in the movie. Who would I choose, had I a choice, given I’d be there myself pretty soon.

Sure, a woman can do all that great deeds rather than make hot phulkas, but it’s exaggerating and undermining her traditional role in some aspects for whatever reason. However, lets see a logical discourse to it.

Rather than being a COO at some million dollar company(MDC), or making hot phulkas, I would like to see a woman spend more time bringing up and caring for her children. Forget the husband and the inlaws. It’s for a reason that mom’s care is the best.Reason why in America, we had the highest incidences of junk food related child disorders like obesity, diabetes and cancers; yes by denying hot phulkas and outsourcing to pizza’s and pepsi’s. Indian children are still the healthiest even among-stthe underprivileged. Dad’s role needed, yep, but it comes in a lot later, and I’m not trying to hush that up.

A man and a woman play a complementary role in life, NOT supplementary, nature intended it that way. Current speak goes against the very fabric of nature, motivations are … sad. Take any proper man / woman and he/she’ll say ‘supportive’ rather than ‘competitive’. Women apart from faring as COOs or Hot phulka makers whichever they choose to be, are really good at organizing homes, multitasking activities, things that can keep disarray from HOME, while men would be the foot soldier who protect, guard and gather. These roles by science of are not swappable.

Tradition doesn’t say that a woman cannot be a CEO / Scientist if she can, but both, men and women have social responsibilities. And recent trend in woman empowerment, not always, but does tend to undo this sense of responsibility among women. That the greatest concern for modern guys to choose a traditional girl over the former. It’s not to enslave or undermine, just a bigger ideal at play.

Agreed that a woman should not be forced, should not be denied and be conquered, but rather be won over as an equal, but at the same time not forget the responsibilities of being a woman.

And when you say that a working woman can do great deeds towards her family, it the supportive and not the competitive aspect of her that one encourages. And then again if its for the nation, what difference does it make if the contribution came from a man or a woman, either ways, there are directly evident contributions and the subtle ones, but none the less.

Lastly, a woman does need to take care of herself well, In most cases i’m sure the woman will choose family over all others. And it is not easy. Yet to hold on to being competitive on the career front is just not as healthy. In the end sacrifice is a way, and Men do appreciate that and are ever grateful mostly. Women are articulate and cannot endure modern corrosion as a guy, that not being a bad thing and I’m not trying to down play her truer abilities.  It’s not said in vain that the health of a family depends on the health of the women in it.

So judging by all the above, I give the movie does lend some credence to the modern man.What say?

Ironic yet assuring, that the plot was situated in London. The west tried all this modernization of woman a 100 yrs back, now they are limping back to the traditional way even more. Among Indian women we now find the most morbid aspirations for pseudo modernism.

PS: It’s neither being a COO or a Hot phulka maker that’s bad. Whilst striking a balance is what is important. I’ll remember that for sure, rest is luck.

vyjayanthy

Just another WordPress.com site

Follow

Get every new post delivered to your Inbox.