2012
12.05

so i needed to setup 2 mysql servers in a HA setup on CentOS 6, i decided to use keepalived (yum search keepalive).

here were the requirements:

– 1 virtual ip
– both servers had to still replicate from each other but only one can take traffic from the vip
– quick failover incase machine went down or was pulled

in this setup:
192.168.168.249 = virtual ip address (where all mysql traffic should come to)
192.168.168.251 = mysql server 1 / lb1
192.168.168.252 = mysql server 2 / lb2

here is my keepalived.conf :

global_defs {
  notification_email {
    me@pissedoffadmins.com
  }
  notification_email_from loadbalancer1
  smtp_server smtp server
  smtp_connect_timeout 5
  router_id lb1
}

vrrp_instance mysql_pool {
  interface eth0
  state MASTER
  virtual_router_id 1
  priority 101
  track_interface {
    eth0
  }

  authentication {
    auth_type PASS
    auth_pass set a password here
  }

  virtual_ipaddress {
    192.168.168.249 dev eth0
  }
}

virtual_server 192.168.168.249 3306 {
  delay_loop 2
  lb_algo rr
  lb_kind DR
  protocol TCP

  sorry_server 192.168.168.251 3306

  real_server 192.168.168.251 3306 {
    weight 10
    TCP_CHECK {
      connect_port    3306
      connect_timeout 1
    }
  }

  real_server 192.168.168.252 3306 {
    weight 10
    TCP_CHECK {
      connect_port    3306
      connect_timeout 1
    }
  }
}

this was the conf file that was installed on balancer one – make sure you make the right changes for it to work on balancer two like setting state to slave and changing router_id.

you can also add a second TCP_CHECK under the 3306 check with a port that you can keep open with netcat. in that case, you can stop netcat and then mysql would be automagically be pulled out of the balancer while still up (in case you needed to do some work on it), but this would require netcat to remain up and running, while keeping that port open at all times.

for the network configuration, we bound the vip to LO:1 :

lo:1      Link encap:Local Loopback  
          inet addr:192.168.168.249  Mask:255.255.255.255
          UP LOOPBACK RUNNING  MTU:16436  Metric:1

here is the ifcfg-lo:1 :

DEVICE=lo:1
IPADDR=192.168.168.249
NETMASK=255.255.255.255
ONBOOT=yes

once keepalive is up and running, we can check the balancers and pools by using ipvsadm (yum search ipvsadm):

# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  192.168.168.249:3306 rr
  -> 192.168.168.251:3306         Local   10     13         8         
  -> 192.168.168.252:3306         Route   10     8          93

and for mysql replication, you can google that one since your replications needs may be different.

once all of this is configured, you can ensure that mysql is up and running and being seen by keepalived by running ipvsadm -Ln

YMMV

2012
11.13

this happened

sandy

SSMI/SSMIS/TMI-derived Total Precipitable Water – North Atlantic

from : http://tropic.ssec.wisc.edu/real-time/mimic-tpw/natl/main.html

2012
10.18

so for a long time i was wondering what console-kit-daemon was and why were there so many of them running on my machine.

example:

ono-sendai ~ % ps -eLf | grep console-kit | grep -v grep        
root       1981      1   1981  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   1983  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   1985  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   1986  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   1987  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   1988  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   1989  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   1991  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   1992  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   1993  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   1994  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   1995  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   1996  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   1997  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   1998  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   1999  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2000  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2001  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2002  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2003  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2004  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2005  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2006  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2007  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2008  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2009  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2010  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2011  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2012  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2013  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2014  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2015  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2016  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2017  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2018  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2019  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2020  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2021  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2022  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2023  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2024  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2025  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2026  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2027  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2028  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2029  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2030  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2031  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2032  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2033  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2034  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2035  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2036  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2037  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2038  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2039  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2040  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2041  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2042  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2043  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2044  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2045  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2047  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2049  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1981      1   2105  0   65 Oct15 ?        00:00:00 /usr/sbin/console-kit-daemon
ono-sendai ~ % ps -eLf | grep console-kit | grep -v grep | wc -l
65

65.

65 running daemons, which granted, are not taking up a dumb amount of memory but are annoying since in a “ps -eLf” or htop tree view take up many lines.

here is what freedesktop.org had to say about ConsoleKit:

ConsoleKit is a framework for keeping track of the various users, sessions, and seats present on a system. It provides a mechanism for software to react to changes of any of these items or of any of the metadata associated with them.

definition of Session, Session Leader, & Seat as per freedesktop.org:
Session

A session is a collection of all processes that share knowledge of a secret. In the typical (or ideal) case, these processes all originate from a single common ancestor.

As an implementation detail, for now, this secret should be stored in the process environment by the session leader under the name XDG_SESSION_COOKIE. When and if we are able to take advantage of a mechanism in the underlying system to store session registration information - we will. However, such a mechanism is not known at the present time.

Using an environment variable does have certain advantages. For one, it is quite easy for a process to opt-out of a Session by simply unsetting the XDG_SESSION_COOKIE variable.

Limitations of using an environment variable implementation include not being able to strictly limit visibility of the secret to a particular process ancestry. So, it is not possible to enforce session boundaries other than on a per-user basis. For example, we don't yet have a way to prevent a process from moving between sessions owned by the same user.

Session leader

The session leader is the process that requests that a new session be opened. It does this by connecting to the D-Bus system bus and using either org.freedesktop.ConsoleKit.Manager.OpenSession() or org.freedesktop.ConsoleKit.Manager.OpenSessionWithParameters(). The session that it registers will remain open until the connection to the system bus is lost or it calls org.freedesktop.ConsoleKit.Manager.CloseSession().

The session leader is the only process for which CloseSession() will be allowed.

Seat

A seat is a collection of sessions and a set of hardware (usually at least a keyboard and mouse). Only one session may be active on a seat at a time.

At the present time, all Sessions that are considered "local" to a system will be added the the first Seat and every other Session will be added to its own Seat.

True, hardware, multi-seat capabilities will be added in a later release.

So what i am gathering from this is that on my personal laptop that will have at most 3 actual people logged in at any given moment the usage fo 65 console-kit-daemon’s is a bit excessive. lets fix that.

after some digging around and much googling, i found two values which were originally housed in /usr/src/KERNEL VERSION/include/linux/tty.h and have now been moved to /usr/src/KERNEL VERSION/include/linux/vt.h
which are :
MAX_NR_CONSOLES & MAX_NR_USER_CONSOLES

these two defines explained here:

 * Console (vt and kd) routines, as defined by USL SVR4 manual, and by
 * experimentation and study of X386 SYSV handling.
 *
 * One point of difference: SYSV vt's are /dev/vtX, which X >= 0, and
 * /dev/console is a separate ttyp. Under Linux, /dev/tty0 is /dev/console,
 * and the vc start at /dev/ttyX, X >= 1. We maintain that here, so we will
 * always treat our set of vt as numbered 1..MAX_NR_CONSOLES (corresponding to
 * ttys 0..MAX_NR_CONSOLES-1). Explicitly naming VT 0 is illegal, but using
 * /dev/tty0 (fg_console) as a target is legal, since an implicit aliasing
 * to the current console is done by the main ioctl code.

so if i am reading this correctly, then this means that this is for numbering vt’s and vc’s. so why have so many of them. lets change these values, recompile our kernel and test.

values changed :
#define MAX_NR_CONSOLES 63 /* serial lines start at 64 */
#define MAX_NR_USER_CONSOLES 63 /* must be root to allocate above this */

to:
#define MAX_NR_CONSOLES 15 /* serial lines start at 64 */
#define MAX_NR_USER_CONSOLES 15 /* must be root to allocate above this */

results:

cbodden@ono-sendai ~ % ps -eLf | grep console-kit | grep -v grep        
root       1877      1   1877  0   18 14:50 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1877      1   1879  0   18 14:50 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1877      1   1881  0   18 14:50 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1877      1   1882  0   18 14:50 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1877      1   1883  0   18 14:50 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1877      1   1884  0   18 14:50 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1877      1   1885  0   18 14:50 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1877      1   1887  0   18 14:50 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1877      1   1888  0   18 14:50 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1877      1   1889  0   18 14:50 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1877      1   1890  0   18 14:50 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1877      1   1891  0   18 14:50 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1877      1   1892  0   18 14:50 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1877      1   1893  0   18 14:50 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1877      1   1894  0   18 14:50 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1877      1   1943  0   18 14:50 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1877      1   1948  0   18 14:50 ?        00:00:00 /usr/sbin/console-kit-daemon
root       1877      1   1999  0   18 14:50 ?        00:00:00 /usr/sbin/console-kit-daemon
cbodden@ono-sendai ~ % ps -eLf | grep console-kit | grep -v grep | wc -l
18

18.

that is a bit better.

this was tested using kernel version 3.6.2 (gentoo-sources):

ono-sendai ~ % uname -a 
Linux ono-sendai 3.6.2-gentoo-poa #1 SMP PREEMPT Thu Oct 18 14:47:38 EDT 2012 x86_64 Intel(R) Core(TM)2 Duo CPU L9600 @ 2.13GHz GenuineIntel GNU/Linux
ono-sendai ~ % eix gentoo-sources
[D] sys-kernel/gentoo-sources
     Available versions:  
        (3.0.17-r2)     3.0.17-r2^bs
        (3.0.35)        3.0.35^bs
        (3.0.45)        (~)3.0.45^bs
        (3.0.46)        (~)3.0.46^bs
        (3.3.8) 3.3.8^bs
        (3.3.8-r1)      (~)3.3.8-r1^bs
        (3.4.9) 3.4.9^bs
        (3.4.10)        (~)3.4.10^bs
        (3.4.11)        (~)3.4.11^bs
        (3.5.6) (~)3.5.6^bs
        (3.5.7) (~)3.5.7^bs
        (3.6.1) (~)3.6.1^bs
        (3.6.2) (~)3.6.2^bs
        {{build deblob symlink}}
     Installed versions:  3.6.0(3.6.0)^bs(10:36:25 AM 10/03/2012)(-build -deblob -symlink) 3.6.1(3.6.1)^bs(10:27:15 AM 10/08/2012)(-build -deblob -symlink) 3.6.2(3.6.2)^bs(12:26:57 PM 10/15/2012)(-build -deblob -symlink)
     Homepage:            http://dev.gentoo.org/~mpagano/genpatches
     Description:         Full sources including the Gentoo patchset for the 3.6 kernel tree

YMMV.

2012
10.05

new phone screen shot

new phone == screen shots

i just recently upgraded my nexus s for a galaxy s3. first thing to do was root the phone, then install cyanogenmod 10 nightly , then upgrade the radio.

here is the screenshot:

click to enlarge

i am liking this phone so far. all good.

2012
10.05

i sit in multiple terminal sessions all day on my personal and work machine with my headphones on listening to pianobar (cli client for pandora : get it here or in gentoo emerge pianobar) and i realized that it was becoming a pain to send controls to the pipe for pianobar.

so i wrote a script that has a rudimentary level of control but shortens the stuff that has to be typed to send to the pipe to control pianobar

here it is:

#!/bin/bash

#### pianobar fifo control script

# lets check if fifo file exists, if not create it
PIPE=`cat ${HOME}/.config/pianobar/config | grep -v "#" | grep fifo | tr -d "\ " | cut -d"=" -f2`
if [[ ! -p ${PIPE} ]]; then
    if [[ -z ${PIPE} ]]; then
        printf "\npianobar fifo not specified in config\nexiting\n"
        exit 1
    fi
    printf "\npianobar fifo does not exist\n"
    read -p "should i create it ? (y/n): " YN
    case $YN in
        [Yy]* ) mkfifo ${PIPE} ; printf -- "\npianobar fifo created\n" ;;
        [Nn]* ) exit 1 ;;
    esac
fi

# lets make sure pianobar is running, if not ask to run
if [[ ! `pgrep -u $(id -u) pianobar$` ]]; then
    printf "\npianobar is not running\n"
    read -p "should i start pianobar ? (y/n): " YN
    case $YN in
        [Yy]* ) pianobar && exit ;;
        [Nn]* ) exit 1 ;;
    esac
fi

# help stuffs
help_section() {
    printf "\n$(basename $0)\n"
    printf -- "Usage: $(basename $0) [OPTION]\n\n"
    printf -- "Usage Example : \"$(basename $0) n\"  \"$(basename $0) --next\"  \"$(basename $0) next\"\n"
    printf -- "This will jump to the next track\n\n"
    printf -- "Options:\n"
    printf -- "+,  --love,     love        --  Love this song\n"
    printf -- "-,  --ban,      ban         --  Ban this song\n"
    printf -- "b,  --bookmark, bookmark    --  Bookmark song \ artist\n"
    printf -- "e,  --explain,  explain     --  Explain why this song is playing\n"
    printf -- "h,  --history,  history     --  History of whats played\n"
    printf -- "i,  --info,     info        --  Info for whats playing\n"
    printf -- "n,  --next,     next        --  Next song\n"
    printf -- "p,  --pause,    pause       --  Pause \ Play song\n"
    printf -- "q,  --quit,     quit        --  Quit Pianobar\n"
    printf -- "t,  --tired,    tired       --  Tired (ban song for 1 month)\n"
    printf -- "u,  --upcoming, upcoming    --  Upcoming songs\n"
    printf -- "vd, --voldown,  voldown     --  Volume Down\n"
    printf -- "vu, --volup,    volup       --  Volume Up\n"
    printf -- "\nvolume up and down can also have a value added:\n"
    printf -- "\n$(basename $0) [volume option] [1-25]\n\n\n"
    printf "pianobar pid (euid=$(id -u)): "
    pgrep -u $(id -u) pianobar$
    printf -- "\n"
}

# menu stuffs
case $1 in
    +|--love|love           ) printf "+" > ${PIPE} ;;
    -|--ban|ban             ) printf "-" > ${PIPE} ;;
    b|--bookmark|bookmark   ) printf "b" > ${PIPE} ;;
    e|--explain|explain     ) printf "e" > ${PIPE} ;;
    h|--history|history     ) printf "h" > ${PIPE} ;;
    i|--info|info           ) printf "i" > ${PIPE} ;;
    n|--next|next           ) printf "n" > ${PIPE} ;;
    p|--pause|pause         ) printf "p" > ${PIPE} ;;
    q|--quit|quit           ) printf "q" > ${PIPE} ;;
    t|--tired|tired         ) printf "t" > ${PIPE} ;;
    u|--upcoming|upcoming   ) printf "u" > ${PIPE} ;;
    vd|--voldown|voldown    ) printf "(" > ${PIPE}
        count=1
        while [[ $count -lt $2 ]]; do
            printf "(" > ${PIPE}
            count=`expr $count + 1`
        done
        ;;
    vu|--volup|volup        ) printf ")" > ${PIPE}
        count=1
        while [[ $count -lt $2 ]]; do
            printf ")" > ${PIPE}
            count=`expr $count + 1`
        done
        ;;
    *                       ) help_section ;;
esac

here it is in github.

all it does is give you a simple way to check that the fifo exists, starts pianobar, and then lets you send commands to the respective pipe from any terminal.

make sure to place this script somewhere in your path.

2012
09.25

so on the command line, i have been looking for a brain dead simple way of syncing my photographs to s3 every x amount of hours.

i wrote a small script to handle that and can be placed in cron to automatically copy new folders to s3. i am working on making this script also sync the files in each folder but that will be a later post.

the script uses s3cmd from http://s3tools.org/s3cmd or in gentoo net-misc/s3cmd.

here is the script :

#!/bin/bash


######
# this script uses s3cmd from http://s3tools.org/s3cmd to sync a folder in linux to s3
#
# make sure that you have configured s3cmd by running s3cmd --configure
#
# this script is usally kept in a cron to be run every x amount of hours
######

S3CMD=`which s3cmd`
S3CMD_OPTIONS="--recursive put"
BKUP_PATH=CHANGE THIS TO PATH WHERE FOLDERS ARE LOCATED
BUCKET=s3://CHANGE THIS TO S3 BUCKET NAME FROM "s3cmd ls"/
LIST=/tmp/S3CMD.$$
DIR=/tmp/DIR.$$
touch $LIST $DIR

#### you should not have to change anything below this line ####

# check if s3cmd exists
if [[ -z ${S3CMD} ]]; then
    printf "\ns3cmd not found.\nInstall s3cmd from http://s3tools.org/s3cmd\n"
    exit 1
fi

# use s3cmd to print a list of existing folders in bucket
${S3CMD} la > $LIST

# check if folders in $BKUP_PATH exist in s3, if not then copy them there
for DIR_CHECK in `ls -al $BKUP_PATH | awk '{print $9}' | tail -n +4 | tr '/' ' ' ` ; do
    if [[ $(grep -c $DIR_CHECK $LIST) -gt 0 ]]; then
        printf "\n${DIR_CHECK} exists in s3."
    else
        printf "\n${DIR_CHECK} does not exist at s3."
        printf "\nadding now:\n"
        ${S3CMD} ${S3CMD_OPTIONS} ${BKUP_PATH}/${DIR_CHECK} ${BUCKET}
    fi
done

# delete temporary files
rm -rf $LIST
rm -rf $DIR

script is located here

i realize that this whole script can be replaced with one command, but for simplicity (depending who is using it) i decided to just make it since it was a 5 minute thing.

2012
09.17

so this script uses bwm-ng (gentoo : gentoo: emerge bwm-ng, or http://www.gropp.org/?id=projects&sub=bwm-ng) and netcat.

pretty straight forward :

#!/bin/bash

#######
# this script uses bwm-ng to gather the bandwidth rx/tx and packet rx/tx on specified interfaces
# it only sends numeric values
# 
# to run this script :
# nohup sh ~/scripts/bandwidth_graphite.sh & >/dev/null 2>&1
#
# to run this script in cron :
# * 3 * * * kill -9 `ps -ef | egrep graphite | grep -v grep | awk '{print $2}'` | sleep 5 && nohup sh ~/scripts/bandwidth_graphite.sh & >/dev/null 2>&1
#
# legend of bwm-ng output formatted for csv :
# unix_timestamp;iface_name;bytes_out;bytes_in;bytes_total;packets_out;packets_in;packets_total;errors_out;errors_in
#######

HOSTNAME=`echo $HOSTNAME | cut -d. -f1`
GRAPH_SERVER=""
GRAPH_PORT=""
INTERFACES='eth0
eth1
eth2
eth3'

#### check to see if bwm-ng is installed ####
if [  ! -f /usr/bin/bwm-ng ]; then
	echo "INSTALL BWM"
	exit 1
fi

#### check to see if netcat is installed ####
if [ ! -f /usr/bin/nc ]; then
	echo "INSTALL NETCAT"
	exit 1
fi

#### you should not have to change anything below this line ####

while (true)
do
	for I in ${INTERFACES}
	do
		#### set BWM_OUT to filtered output of bwm-ng ####
		BWM_OUT=`/usr/bin/bwm-ng --interface ${I} -o plain -t 1000 -o csv -c 1 | grep -v total`
		#### use date in epoch from BWM_OUT ####
		DATE=`echo ${BWM_OUT} | cut -d";" -f1`
		#### use interface name from BWM_OUT ####
		IFACE=`echo ${BWM_OUT} | cut -d";" -f2`
		#### packets in ####
		RXPCK=`echo ${BWM_OUT} | cut -d";" -f7`	
		#### packets out ####
		TXPCK=`echo ${BWM_OUT} | cut -d";" -f6`
		#### bytes in ####
		RXBYT=`echo ${BWM_OUT} | cut -d";" -f4`
		#### bytes out ####
		TXBYT=`echo ${BWM_OUT} | cut -d";" -f3`

		#### begin nc to graph services ####
		echo "${HOSTNAME}.${IFACE}.RxPACKETS ${RXPCK} ${DATE}"  | nc ${GRAPH_SERVER} ${GRAPH_PORT}
		echo "${HOSTNAME}.${IFACE}.TxPACKETS ${TXPCK} ${DATE}"  | nc ${GRAPH_SERVER} ${GRAPH_PORT}
		echo "${HOSTNAME}.${IFACE}.RxBYTES ${RXBYT} ${DATE}"  | nc ${GRAPH_SERVER} ${GRAPH_PORT}
		echo "${HOSTNAME}.${IFACE}.TxBYTES ${TXBYT} ${DATE}"  | nc ${GRAPH_SERVER} ${GRAPH_PORT}
	done
done

sample image from some production servers:

click to enlarge

here it is in github

2012
08.14

so after some more work trying to ensure that my passwords are not easily gotten, i managed to get my passwords encrypted into one file and removed after being read.

here is the snippet from my .muttrc-accounts :

set my_tmp=`gpg -q --no-verbose -o /tmp/.passwords.tmp -d ~/.passwords.gpg`
set my_pass_acct1=`cat /tmp/.passwords.tmp | grep IDENTIFIER1 | awk '{ print $2 }'`
set my_pass_acct2=`cat /tmp/.passwords.tmp | grep IDENTIFIER2 | awk '{ print $2 }'`
set my_del=`rm -f /tmp/.passwords.tmp`

EDIT 03-feb-2014:
reader Kage (thanks btw) posted a way more elegant way of handling the unencryption of passwords:

set my_pass_acct1 = `gpg -q -d ~/.passwords.asc | grep ^acct1 | awk ā€˜{ print $NF }ā€™ | tr -d ā€˜\nā€™`

which is placed under account-hook . 'unset preconnect imap_user imap_authenticators'

the format of the password file:

IDENTIFIER1 password1
IDENTIFIER2 password2

and for all this to work, you just have to change

imap_pass=xxxxxx
smtp_pass=xxxxxx

to

imap_pass = $my_pass_acctx
smtp_pass = $my_pass_acctx

to create the gpg file :

gpg -r EMAIL_ADDRESS_ON_KEY -e PASSWORD_FILE

this all implies that you have gpg installed with your keys already configured.

muttrc-accounts in github

2012
08.08

ok. i lied about the last screenshot being the last one with this phone. i just have not gotten around to grabbing a new phone yet and this one works fine (for now).

in this screenshot, the nexus s (crespo) is running android 4.1.1 (cyanogenmod skank nightly) with a custom kernel (jbn weekly). recovery was upgraded to clockworkmod recovery touch (thanks Koush) and running smooth and pretty stable so far.

click bar to enlarge

grab the source from XDA.

2012
08.07

exactly as the name says. if you are a citrusleaf user, here is an easy (and hacky) way to output your namespace values to graphite with a nohup script every 10 seconds in github or here:

#!/bin/bash

#######
# this script runs through clinfo and grabs all the values for citrusleaf, then parses them out to graphite every 10 seconds.
# it only sends numeric values.
#
# to run this script :
# nohup sh citrusleaf_graphite.sh &
#
#######

NAMESPACE=""
HOSTNAME=`echo $HOSTNAME | cut -d. -f1`
DATE=`date +%s`
NETCAT=`which nc`
CL_SERVER="127.0.0.1"
CL_PORT="3000"
GRAPHITE_SERVER=""
GRAPHITE_PORT="2003"
NUMBER="0"

#### this is to check whether or not netcat is installed ####

if [[ -z ${NETCAT} ]]; then
    printf "\nnc not found.\n"
    exit 1
fi

#### you should not have to change anything below this line ####

while (true)
do
    DATE=`date +%s`
    NUMBER="0"
    for I in $(clinfo -h ${CL_SERVER} -p ${CL_PORT} -v ${NAMESPACE} | grep type | cut -d" " -f4 | tr ";" "\n")
    do
        # NUMBER=`expr ${NUMBER} + 2`
        NAME=`echo ${I} | cut -d"=" -f1`
        VALUE=`echo ${I} | cut -d"=" -f2 | cut -d";" -f1`
        VALUE_CHK=${VALUE//[^0-9]/}
            if [[ ${VALUE} == ${VALUE_CHK} ]]; then
                # echo ${NUMBER} ${I}
                # echo "value to nc:"
                # echo ${HOSTNAME}.${NAME} ${VALUE} ${DATE}
                echo "${HOSTNAME}.${NAME} ${VALUE} ${DATE}" | nc ${GRAPHITE_SERVER} ${GRAPHITE_PORT}
            fi
    done
    sleep 10
done

its pretty self explanatory.