Thursday, January 29, 2009

Application memory footprint logging

I needed to figure out an nginx memory footprint and it is inconvenient given it is one master and 64 children processes. So, here is the shell script (runs on Centos), which collects the data based on the pid file:

#!/bin/bash

if [ -f "$1" ]
then
  export THE_FILE=$1
  export THE_PID=`cat $1`
else
  read -ep "pid: "
  export THE_PID=$REPLY
fi

ps o rss,vsz p ${THE_PID} --ppid ${THE_PID} h |
awk -v OFS=', ' '{
  rss += $1;
  vsz +=$2;
} END {
  print strftime( "%Y.%m.%d %H:%M:%S %z", systime()), ENVIRON["THE_PID"], rss, vsz, ENVIRON["THE_FILE"];
}'

One can run multiple of those adding output to the same log file for late processing. For example, my crontab looks lile this:

1,16,31,46 * * * * /usr/local/bin/pm /serv1/logs/nginx.pid >> /var/log/mem_usage
6,21,36,51 * * * * /usr/local/bin/pm /serv2/logs/nginx.pid >> /var/log/mem_usage

The pm is the script from above. It produces output similar to this:

2009.01.29 14:31:01 -0600, 27354, 10068, 150716, /serv1/logs/nginx.pid
2009.01.29 14:36:01 -0600, 27296, 96708, 821224, /serv2/logs/nginx.pid
2009.01.29 14:46:01 -0600, 27354, 10068, 150716, /serv1/logs/nginx.pid
2009.01.29 14:51:01 -0600, 27296, 96708, 821224, /serv2/logs/nginx.pid
2009.01.29 15:01:01 -0600, 27354, 10068, 150716, /serv1/logs/nginx.pid
2009.01.29 15:06:01 -0600, 27296, 96708, 821224, /serv2/logs/nginx.pid

The fields are: timestamp, process ID, resident memory, virtual memory, pid source file (if any). I think there should be a better way to do it. Please, comment, if you find one.

read more ...

Monday, January 12, 2009

Corellating happiness with..

... the use of entertainment industry.

From my completely unscientific observations it seems, that the happier a person is, then (s)he is less reliant on an entertainment industry. Either happier people:

  1. do not need entertainment,
  2. entertain themselves without an external help, or
  3. entertainment industries target the less happy part of the population and so miss the mark with happier people.

What kind of metric could prove or break the hypothesis?