Thursday, October 10, 2013

Simple moving average in RRD

It's quite easy to add simple moving average (SMA) to RRD with rrd PREV function.
PREV allows you to get data from previous time stamp. The magic is that you can run that function on sequences of variables to dig deeper in the past.

Here is SMA from 10 variables, current value and 9 from the past (php template for PNP).

$def[1] .= "DEF:idle=$rrdfile:$DS[3]:AVERAGE " ;

$def[1] .= "CDEF:idle1=PREV(idle), " ;
$def[1] .= "CDEF:idle2=PREV(idle1), " ;
$def[1] .= "CDEF:idle3=PREV(idle2), " ;
$def[1] .= "CDEF:idle4=PREV(idle3), " ;
$def[1] .= "CDEF:idle5=PREV(idle4), " ;
$def[1] .= "CDEF:idle6=PREV(idle5), " ;
$def[1] .= "CDEF:idle7=PREV(idle6), " ;
$def[1] .= "CDEF:idle8=PREV(idle7), " ;
$def[1] .= "CDEF:idle9=PREV(idle8), " ;
$def[1] .= "CDEF:idle_sma=idle,idle1,idle2,idle3,idle4,idle5,idle6,idle7,idle8,idle9,+,+,+,+,+,+,+,+,+,10,/ " ;


Tuesday, July 16, 2013

How to move lv volume from host to host

To move one LVM volume from host A to host B you should create on host B a volume with same size as moving volume from host A.
After creation you can copy data from one volume to another with dd, ssh commands and gzip for speeding it up:

dd bs=1M if=LVM_HOST_A | gzip --fast -c | ssh HOST_B "gzip -d -c | dd bs=1M of=LVM_HOST_B"

To speed it up little more you can turn off compression in ssh (we already have compressed data with gzip) and choose fast cipher by adding -c arcfour -o Compression=no to ssh:

dd bs=1M if=LVM_HOST_A | gzip --fast -c | ssh -c arcfour -o Compression=no HOST_B "gzip -d -c | dd bs=1M of=LVM_HOST_B"

You can install pv utility to see file transfer progress, rate and etc. Like this:

dd bs=1M if=LVM_HOST_A | pv -brtp | gzip --fast -c | ssh -c arcfour -o Compression=no HOST_B "gzip -d -c | dd bs=1M of=LVM_HOST_B"

And look at lvmsync - it allows you to sync only changes made since LVM snapshot was made.

Saturday, May 4, 2013

PostgreSQL PL speed test

I tested four procedure languages for PostgreSQL 9.2: plpgsql, plperl, plpython2u, plperl and plv8 with Fibonacci numbers function. And V8 was the best!


Wednesday, April 10, 2013

HOWTO install phpDaemon on CentOS 6.X


The problem is that I can't find PECL modules and some libs for them in repos (standard + remi) or packages versions was to old for phpdaemon. No yum, no easy updates, only source codes =(

Step 1: Install all necessary for building from source. Remember if you don't use remi as a php repo, remove  --enablerepo=remi from yum command below.
yum --enablerepo=remi install php-devel openssl-devel gcc make git

Step 2: Get libevent2 and install it (in my case in /opt/libevent2)
wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
tar -xzf libevent-2.0.21-stable.tar.gz
cd libevent-2.0.21-stable/
./configure --prefix=/opt/libevent2
make && make install

Step 3: Install PECL modules
pecl install event
Don't forget to set libevent installation prefix [/usr] : /opt/libevent2

pecl install eio
pecl install proctitle-alpha

git clone git://github.com/zenovich/runkit.git
cd runkit/
phpize
./configure --prefix=/opt/runkit
make && make install


Step 4: Install phpdaemon
cd /opt
git clone git://github.com/kakserpom/phpdaemon.git
ln -s /opt/phpdaemon/bin/phpd /usr/bin/phpd

Step 5: Configure phpdaemon for your needs =)

Saturday, April 6, 2013

SSH config makes your life easier

How to simplify your day-to-day ssh usage with config file!

As you know there is a rule called '90/10'. 90 percent of users use only 10 percent of software capabilities. And it works not only for huge programs as MS Office but even for small utilities like ps, ls or ssh.
I used ssh for many years as some kind of barbarian who found microscope and uses it for chopping nuts!

Why am I writing all this? Because only one file can save a lot of keyboard clicks!
Ssh client looks for ~/.ssh/config file to apply configuration for new session. Simple example:

Host home
  Hostname 192.168.0.100
  User root
  Port 222

To ssh to your home you can only type ssh home instead of
ssh -p 222 root@192.168.0.100            

You can use Host as a mask for several hosts:

Host webfe* *.company.com db*.hosting.com
  User root
  IdentityFile ~/.ssh/key

And Host * can be set as a default settings for all sessions:

Host *
  Compression yes
  CompressionLevel 7
  Cipher blowfish

See man ssh_conf for more sugar!