Nginx + PHP-FPM status page

I was working on collecting metrics from PHP FPM via Nginx and found following post on how to set this up: however this was producing empty documents for me until I found on some forum that

fastcgi_param PATH_TRANSLATED $document_root$fastcgi_script_name;

needs to be added to the config. After adding this my config looks like this:

location ~ ^/(status|ping)$ {
    access_log off;
    deny all;
    include fastcgi_params;
    fastcgi_param PATH_TRANSLATED $document_root$fastcgi_script_name;

end I can see all the PHP-FPM stats I need.

Posted in Linux, Sysadmin | Leave a comment

Apache2 + WSGI auto restart

The one thing I loved about Passenger and Ruby (from a time when I was working on it) was how easy it was to reload your code. I still had to touch a file to do it but that gave me an idea how to solve my problem when working on Python code that runs via Apache2 and mod WSGI.

I use Coda 2 to develop web projects and when I have something to publish I just hit Ctrl+Shift+P, my files are uploaded and I have to reload Apache to see my changes (if changes were in Python code).

Aint Nobody Got Time for That

There is a proper way to do this which is described here (I should re-use ^^^ here). I come up with a bit quicker solution that fits my needs.

Here comes the monit. The idea is to monitor the WSGI Script and restart Apache on change. On Debian/Ubuntu it can be installed with APT:

user@computer:$ sudo apt-get install monit

Enable it:

user@computer:$ sudo vim /etc/default/monit

Just change startup=0 to startup=1:

 Defaults for monit initscript
# sourced by /etc/init.d/monit
# installed at /etc/default/monit by maintainer scripts
# Stefan Alfredsson <>

# You must set this variable to for monit to start

# You can change the location of the state file here
# It can also be set in monitrc
# STATEFILE="/var/lib/monit/monit.state"

# To change the intervals which monit should run,
# edit the configuration file /etc/monit/monitrc
# It can no longer be configured here.

Next thing I needed was some basic config for monit:

user@computer:$ sudo vim /etc/monit/conf.d/monit.conf

Something like this works for me:

set daemon 60
set logfile syslog facility log_daemon

set alert

set httpd port 2812 and
use address
allow admin:monit

check process apache2 with pidfile /var/run/
    start program "/etc/init.d/apache2 start"
    stop program "/etc/init.d/apache2 stop"
    depends on app

check file app
    with path /home/artur/app/
    if changed timestamp then restart

Restarted monit and Apache was restarted on my next change:

user@computer:$ sudo /etc/init.d/monit restart

From /var/log/daemon.log I can see it worked:

Aug 27 07:10:46 server monit[24126]: Starting monit daemon with http interface at [localhost:2812]
Aug 27 07:10:46 server monit[24128]: Starting monit HTTP server at [localhost:2812]
Aug 27 07:10:46 server monit[24128]: monit HTTP server started
Aug 27 07:10:46 server monit[24128]: 'localhost' Monit started
Aug 27 07:10:46 server monit[24128]: No mail servers are defined -- see manual for 'set mailserver' statement
Aug 27 07:10:46 server monit[24128]: Aborting event
Aug 27 07:12:46 server monit[24128]: 'app' timestamp was changed for /home/artur/app/
Aug 27 07:12:46 server monit[24128]: No mail servers are defined -- see manual for 'set mailserver' statement
Aug 27 07:12:46 server monit[24128]: Aborting event
Aug 27 07:12:46 server monit[24128]: 'app' trying to restart
Aug 27 07:12:46 server monit[24128]: 'apache2' stop: /etc/init.d/apache2
Aug 27 07:12:48 server monit[24128]: 'apache2' start: /etc/init.d/apache2
Aug 27 07:13:50 server monit[24128]: 'app' timestamp was not changed for /home/artur/app/

I changed the config to lower down interval to 5 seconds and disabled logs.

Posted in Linux, Sysadmin, Webdev | Tagged , , , | Leave a comment

Plotting power usage with Current Cost and Graphite

I’ve recently upgraded my free power meter to something more hack friendly. Current Cost EnviR power meter outputs current power usage in Watts + current temperature (where the base station is) every 6 seconds in XML format over serial connection. I could get a Current Cost bridge that will post this data to Current Cost website but I though Graphite is much better for this. Here is a quick post on how to get this date into Graphite.
Continue reading

Posted in Home, Linux | Leave a comment

Alfred Workflows

If you ever thought why I should buy a Mac the answer is simple, Alfred ! Can’t think of my work day without it. Soon to be release V2 of Alfred will include a new feature called “Workflows” and as a Mega Supporter I have access to beta version of the app and let me tell you this, if you’re a Power Pack user, prepare for your mind to be blown !
Continue reading

Posted in All, Mac | Tagged , | 4 Comments