Tuesday, September 26, 2006

cacti and friends


The last days I spent some time installing digitemp sensors on my watercooling system and setting up cacti to graph the temperatures.
For reading the sensors I use this little python script:

from subprocess import Popen, PIPE, STDOUT
from string import *
from sys import *

process = Popen("digitemp_DS9097 -q -c /etc/digitemp.conf -r2000 -a", shell=True, stdout=PIPE, stderr=STDOUT)

identifiers = argv[1:]
identifiers = map(lambda x: x+":",identifiers)


n = len(identifiers)
values = [.0]*n
valuecount = 0

for line in process.stdout:
line = line.split()
values[valuecount] = line[6]
valuecount += 1

output = ""
for i,j in zip(identifiers,values):
j = str(j)
output += (i+j+" ")
print output

It is called by cacti using

python /scripts/check_digitemp.py cool air hot out

The parameters given to the script are simply labels of your choice. Just make shure they fit the number of sensors installed.
Also make sure /etc/digitemp.conf exists and the cacti user (in my case www-data) has access to the serial port that connects the sensors. For me it also has been necessary to change the owner of /var/lockLCK..ttyS0 to www-data, otherwise digitemp was not able to lock the serial port.

This might not be the best sollution but for me it works.


I'm also using lm-sensors by cacti. There for I made another script:

from subprocess import Popen, PIPE, STDOUT
from string import *
from sys import *

process = Popen("sensors", stdout=PIPE, stderr=STDOUT)

identifiers = argv[1:]
identifiers = map(lambda x: x+":",identifiers)


n = len(identifiers)
values = [.0]*n


for line in process.stdout:
line = line.split()
if line != []:
#print line
if line[0] == "VCore":
line = line[1:]
for i in range(n):
if line[0] == identifiers[i]:
values[i] = line[1]
if values[i].endswith("\xc2\xb0C"):
values[i
] = values[i][:-3]
if values[i].startswith("+"):
values[i] = values[i][1:]
output = ""
for i,j in zip(identifiers,values):
j = str(j)
output += (i+j+" ")
print output


This is called from cacti by using:
python /scripts/check_sensors.py 1 2 +3.3V +5V +12V -12V -5V V5SB VBat fan1 fan2 temp1 temp2 temp3

In this case the parameters equal the name of the lm-sensors. Note that "VCore 1:" gets translated to "1" due some restriction I had to make when using blank spaces for splitting the output strings.

For some strange reason not all values read make it into the Round Robin Database, but the script itself seems to work.

Starting from theses scripts it should not be to hard to get the actual graphs. Just follow the guide in the cacti documentation.

Friday, September 15, 2006

proftpd and xinetd

The aim of xinetd is providing services that don't consume ressource if they are not used. So this is perfect for my ftp server because most time the server isn't used. xinetd listens on port 21 and it someone connects to this port it starts an instance of proftpd and passes an connection to the instance:

sonium@raumstation:~$ cat /etc/xinetd.d/proftpd
service ftp
{
disable = no
flags = REUSE
socket_type = stream
wait = no
user = root
server = /usr/sbin/proftpd
log_type = FILE /var/log/xinetd.log
log_on_success += DURATION USERID
log_on_failure += USERID
nice = 10
#bind = [IP to bind to]
}

even proftpd must be configured to work with xinetd:

sonium@raumstation:~$ cat /etc/proftpd.conf

ServerName "Debian"
ServerType inetd

# I'm behind a firewall, port 21 and 60000-60200 are forwared to my ip
# myserver.dyndns.org points to my external IP
MasqueradeAddress myserver.dyndns.org
PassivePorts 60000 60200


# Set the user and group that the server normally runs at.
User ftp
Group ftp

ScoreboardFile /var/run/proftpd.score
# ensure write access to this file

dyndns is updated by ddclient.

sonium@raumstation:~$ cat /etc/ddclient.conf
pid=/var/run/ddclient.pid
protocol=dyndns2
use=web, web=www.whatismyip.com
server=myserver.dyndns.org
login=mylogin
password=mypwd
myserver.dyndns.org

set order of alsa devices

Again this is primarly a note to myself.
I have a onboard PCI and an USB soundcard. This is how I set the order of the devices:

sonium@raumstation:~$ cat /etc/modprobe.d/alsa-base
alias snd-card-0 snd-usb-audio
alias snd-card-1 snd-intel8x0
options snd cards_limit=2
options snd-usb-audio index=0 vid=0x0763 pid=0x200f
# change v(endro)id und p(roduct)id according to the output of lsusb
options snd-intel8x0 index=1
# --snip--

sonium@raumstation:~$ cat /etc/modules
snd-usb-audio
#--snip--

Now hw(0,0) points to the usb card and hw(1,0) to the PCI card.