monitor apache performance statistics

the Apache module mod_status is very useful for inspecting your running webserver, but it gives you only realtime informations about workers, connections, and so on. I wanted a way to keep this data and then be able to do comparison, charts and more useful reports. The first step was configuring mod_status in order to be only accessible from localhost: andrea@myserver:~$ cat /etc/apache2/mods-enabled/status.conf <IfModule mod_status.c> # # Allow server status reports generated by mod_status, # with the URL of http://servername/server-status # Uncomment and change the "192.0.2.0/24" to allow access from other hosts. # <Location /server-status> SetHandler server-status Order deny,allow Deny from all Allow from 127.0.0.1 ::1 # Allow from 192.0.2.0/24 </Location> # Keep track of extended status information for each request ExtendedStatus On # Determine if mod_status displays the first 63 characters of a request or # the last 63, assuming the request itself is greater than 63 chars. # Default: Off #SeeRequestTail On <IfModule mod_proxy.c> # Show Proxy LoadBalancer status in mod_status ProxyStatus On </IfModule> </IfModule> now a little shell script to grab the status page together with other useful informations… ...

November 5, 2014 · Andrea Manzini

Linux: get simple I/O statistics per process

I had a trouble with a long process running and wish to know how much I/O this process is doing, so I wrote this quick and dirty python 2.x script: import time,sys,datetime def read_stat(pid): f=open("/proc/%s/io" % pid ,"r") for line in f: if line.startswith('rchar'): rchar=line.split(':')[1] continue if line.startswith('wchar'): wchar=line.split(':')[1] continue f.close() return int(rchar),int(wchar) pid=sys.argv[1] r0,w0 = read_stat(pid) while 1: time.sleep(1) r1,w1 = read_stat(pid) print "%s\t\tr=%s\t\tw=%s" % (datetime.datetime.now().time(),r1-r0,w1-w0) r0,w0=r1,w1 You must give the process PID number as input to the script. In the output you get the read/write throughput of the process in bytes per second, for instance: ...

August 22, 2014 · Andrea Manzini

how to setup disk redundancy with BTRFS filesystem

Starting with a plain old one-disk configuration… # df -h Filesystem Size Used Avail Use% Mounted on /dev/sda2 5.8G 590M 5.0G 11% /data thanks to the power of btrfs, let’s add a second hard disk, with mirrored data AND without unmounting/reformatting! :) also note the different size…. # fdisk -l Disk /dev/sda: 6 GiB, 6442450944 bytes, 12582912 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0xea97ecdc Device Boot Start End Blocks Id System /dev/sda1 2048 526335 262144 82 Linux swap / Solaris /dev/sda2 * 526336 12582911 6028288 83 Linux Disk /dev/sdb: 4 GiB, 4294967296 bytes, 8388608 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes … state of the filesystem before the change… ...

July 9, 2014 · Andrea Manzini

Compress and encrypt your backups

It’s always recommended to backup your data for safety, but for safety AND security let’s encrypt your backups! to compress and encrypt with ‘mypassword’: tar -Jcf - directory | openssl aes-256-cbc -salt -k mypassword -out backup.tar.xz.aes to decrypt and decompress: openssl aes-256-cbc -d -salt -k mypassword -in backup.tar.xz.aes | tar -xJ -f - Another trick with the tar command is useful for remote backups: tar -zcvfp - /wwwdata | ssh root@remote.server.com "cat > /backup/wwwdata.tar.gz" ...

June 11, 2014 · Andrea Manzini