munin alternative
May 28th, 2009just started a new project called ‘monitordatasink’ (im kind of uncreative in such naming things…).
Jut hop over to http://code.google.com/p/monitordatasink/ and have a look yourself. happy monitoring! ![]()
just started a new project called ‘monitordatasink’ (im kind of uncreative in such naming things…).
Jut hop over to http://code.google.com/p/monitordatasink/ and have a look yourself. happy monitoring! ![]()
some time i wrote a post of how to do it the complicated way, so today the easy way:
Sometimes you just need strict variable typing in python. For example if you provide an XML-RPC function, where you have to ensure that the incoming data has the correct type. One solution for this is to write type-checking and converting manually within every function. Since that idea is not very nice and clean, i wrote a function and function decorator that can ensure that the function is always called with the desired types as arguments. To achieve that you need to use a certain naming scheme for the functions arguments: variableType_variableName. So int_a, string_s, list_myList, etc. (see example in code)
code (working example, just run):
the result upon run:
func1 called with: test <type 'str'> 123 <type 'int'> None func1 called with: test <type 'str'> 123 <type 'int'> None (False, "wrong type for function func1, argument int_number (1.) has to be type '<type 'int'>' and not '<type 'str'>'")
this thing makes using XML-RPC much easier ![]()
its easy if you know how:
A is the computer we want to clone, B is the target.
1) download and burn two gentoo installation CDs and boot them on both systems.
2) give the root user a password and start sshd:
passwd
/etc/init.d/sshd start
3) clone discs via dd and ssh: (execute this on A)
dd if=/dev/hda bs=512 | ssh root@<IP of B> "dd of=/dev/hda"
4) thats all. You can view the status of the operation via:
kill -SIGUSR1 `ps | grep dd | awk '{ print $1 }'`
EDIT: better solution (with compression over the network):
on B:
netcat -l -p 11000 | bzip2 -d | dd of=/dev/sda
on A:
bzip2 -c /dev/sda | netcat <IP of B> 11000
since i have to backup some volumes from time to time and i dont want to put this imporant task into the hand of backup scripts, i wrote a LVM backup helper script. The script does not execute anything more then readonly/show commands and instead outputs all steps you have to do:
backupvolume.sh:
#!/bin/bash
# this script should help an administrator to backup his volumes
# the script does NOT execute any dangerous ogerations, instead it
# will print them, so the user can execute them by hand
# if you are totally insane you can also copy-paste the script output into a console
# written by thomas fischer thomas{AT}thomasfischer{DOT}biz
VOL=''
if [ -n "$1" ] ; then
VOL=$1
else
echo "usage: $0 > /dev/null 2>&1
mkdir -p /mnt/backup-target >> /dev/null 2>&1
echo “mount /dev/$VG/$SNAP_VN /mnt/backup-snapshot”
echo “mount /dev/$VG/$TEMP_VN /mnt/backup-target”
echo “# 4) create the actual backup:”
echo “tar pzcvf /mnt/backup-target/backup.tar.gz /mnt/backup-snapshot/”
echo “# 5) backup done, remove mount and snapshot volume:”
echo “umount /mnt/backup-snapshot”
echo “lvremove /dev/$VG/$SNAP_VN”
echo “# 6) now, download your backup: /mnt/backup-target/backup.tar.bz2 and continue then:”
echo “umount /mnt/backup-snapshot”
echo “lvremove /dev/$VG/$TEMP_VN”
echo “# 7) done!”
this outputs such a nice guide:
# SNIP HERE! # 1) create temporary volumes: lvcreate -L107.37G -s -n webserver_snapshot /dev/vg/webserver lvcreate -L107.37G -n webserver_temp vg # 2) format the temporary volume: mke2fs /dev/vg/webserver_temp # 3) mount the temporary volumes: mount /dev/vg/webserver_snapshot /mnt/backup-snapshot mount /dev/vg/webserver_temp /mnt/backup-target # 4) create the actual backup: tar pzcvf /mnt/backup-target/backup.tar.bz2 /mnt/backup-snapshot/ # 5) backup done, remove mount and snapshot volume: umount /mnt/backup-snapshot lvremove /dev/vg/webserver_snapshot # 6) now, download your backup: /mnt/backup-target/backup.tar.bz2 and continue then: umount /mnt/backup-snapshot lvremove /dev/vg/webserver_temp # 7) done
that can be checked by the user and copy-pasted on will ![]()
so you have your fancy application and want to add a protocol to firefox in order to link firefox to it?
Under windows thats easy, under linux now as well: the attached wrapper will call any program you set up in firefox. (this can be a security issue, but i need it for testing only)
step 0:
a) download this script as ~/browser-wrapper.py :
#!/usr/bin/env python
from syslog import syslog
import sys
import commands
def main():
cmdargs = sys.argv[1].split(':')
cmd = cmdargs[0] + ' ' + ':'.join(cmdargs[1:])
syslog("browser wrapper calling: %s" % cmd)
return commands.getstatusoutput(cmd)
if __name__ == "__main__":
main()
b) chmod +x the script
step 1: let firefox know about this:
(please note that we want to add vncviewer links in this example, so the correct YOUR_APPLICATION_NAME is vncviewer)
a) open about:config in firefox
b) Right Click > New > Boolean : enter
network.protocol-handler.external.YOUR_APPLICATION_NAME
and as boolean value true
c) Right Click > New > String : enter
network.protocol-handler.app.YOUR_APPLICATION_NAME
and as string value the
d) open a new tab in firefox and type:
YOUR_APPLICATION_NAME:test
e) in the upcoming dialog, select the wrapper script again and click ok (firefox bug with the preset value …)
your wrapper should work ![]()
so everytime you click on an url
YOUR_APPLICATION_NAME:something
the application YOUR_APPLICATION_NAME will be called with argument “something”
So python has some really nice and easy functions to setup a XMLRPC server.
For me it just lacks a basic function: find out the caller’s IP address. So i took the default implementation and added a function to insert the client IP into the data. Bit hack-ish but works very well. So your client just adds an argument that contains ‘__CLIENT_IP_ADDRESS__’ as string. This receiving function will see the client IP instead this hardcoded sting.
have fun
(side note: they only modification to the original code is marked via XXX)
is really nice
just have a look at this fancy code:
well, i am very busy working in Britain currently, so not much updates currently ![]()
so i found a problem with the struct module in python: it cannot pack or unpack zero terminated strings! This is pretty bad if you want to parse or generate data that must conform that zero termination c-string idea. So i wrote some wrapper functions for pack and unpack that add the format ‘z’. z means zero terminated string.
What it does simply is:
This will enable you to write:
which will result in:
['test1'] ['test1 test2'] ['test1'] [200, 3, 'test1', 34] [200, 3, 'test1', 34, 'test string', 0.23399999737739563]
download the script: struct-zerostrings.py
feel free to use, but please report back if you found problems ![]()
or how to comment a line using the precompiler: http://www.ddj.com/cpp/184401344
the short version for the impatient:
#ifdef _DEBUG
#define DEBUGCLASS myClass::getSingleton()
#else
#define COMMENT SLASH(/)
#define SLASH(s) /##s
#define DEBUGCLASS COMMENT
#endif
DEBUGCLASS.dosomething();
or: how to use geolocation usefully. This solution tries to solve i.e. the problem of calculating the distance between two country by simply comparing the continent of each. So you can simply use a fitting server on the user’s same continent or such.
application example: geolocatephp.txt
the included php file (use it as you like) (the data is based on this)
geotoolsphp.txt
some small notes from myself:
- never use timestamps in queries and use such queries to select them:
this will result in an overused CPU ! :-\
- also how to loop over entries in sql via stored procedures in sql:
Just found the “SPE IDE” = Stani’s Python Editor
Isaac was so kind to tell me that the meaning of the title wont fit with the amount of number (meaning here).
so i updated it to a more correct form ![]()
very useful to see the call Graph and performance of your program:
screenshots: http://kcachegrind.sourceforge.net/cgi-bin/show.cgi/KcacheGrindShot
how to get it (under gentoo):
emerge -av kcachegrind valgrind
How to use:
Collect data program during program execution
valgrind –tool=callgrind –trace-children=yes –num-callers=8 –collect-jumps=yes –instr-atstart=no ./yourprogram
Then open the output file that is created using kcachegrind!
Dissectors in Wireshark will convert the pure data of a packet into a custom protocol with readable data, so you can see values of your protocol instead of just binary data.
How is it done?
First open the file “init.lua” in your wireshark directory and comment out this line:
to
then add to the bottom of the file this line:
(ror is the protocol in my case)
After that you should create a file named “ror.lua” and copy+paste the following content:
i think you should be able to experiment with that now ![]()
have fun! ![]()
i just wrote this little neat python plugin for munin, to be able to track some lighttpd statistics
EDIT: got an error in the first version, fixed that in the above one
EDIT2: now its finally working ![]()