0

We have multiple severs behind loadbalncer and we want access log of each machines in way that it access prefix as hosname with accesslog in lighttpd.

For example :

192.168.1.1-access.log 192.168.1.2-access.log

I tried to use include_shell parameter and have a script with hostname.sh, but its not serving my purpose.

Jyotir Bhandari
  • 109
  • 1
  • 10

1 Answers1

1

I think you could be trying to over complicate this problem, could you not just do the following?

$SERVER["socket"] == “192.168.1.1:80″ {
    accesslog.filename = "/var/log/lighttpd/192.168.1.1-access.log"
}

You also mentioned you were having trouble with include_shell try the following

lighttpd.conf

include_shell "/etc/lighttpd/scripts/servername.sh"
accesslog.filename = "/var/log/lighttpd/" + var.servername  + "-access.log"

scripts/servername.sh - for hostname

#!/bin/bash
echo 'var.servername="'$(uname -n)'"'

OR

scripts/servername.sh - for ip address

#!/bin/bash
echo 'var.servername="'$(/sbin/ifconfig | sed -n '2 p' | awk '{print $2}' | sed s/addr://g)'"'

(change the sed and awk param to get the right IP for your on more than one interface)

This will give you what you are looking for.

Alternatively just cat accesslog.filename = "/var/log/lighttpd/" +uname -n+ "-access.log" to the end of the config file for a cheap and dirty solution.

Kinetic
  • 1,714
  • 1
  • 13
  • 38
  • I have 200 machine behind load balancer, with n number of virtual hosts. – Jyotir Bhandari Nov 01 '12 at 13:38
  • I've added a more complete answer to the question. If this still isn't fit for purpose you could write a script to rename the files as they are downloaded/collected from the respective server. – Kinetic Nov 05 '12 at 17:36