railsware / newrelic_platform_plugins

MIT License
42 stars 66 forks source link

Logwatcher #34

Open andreapernici opened 10 years ago

andreapernici commented 10 years ago

Is possible to run the logwatcher as a daemon or to make it run continuosly?

How the logwatcher graph should be read? You show the occurence on a per minute base?

MarynaIS commented 10 years ago

Yep, I've written simple init.d, and take it on /etc/init.d:

!/bin/bash

DAEMON_PATH="YOUR/PATH/TO/newrelic_logwatcher_agent.rb" DAEMON=newrelic_logwatcher_agent.rb NAME=newrelic_logwatcher_agent PIDFILE=/var/run/$NAME.pid

case "$1" in start) printf "%-50s" "Starting $NAME..." cd $DAEMON_PATH PID=/bin/ps -fu $USER| grep "logwatcher" | grep -v "grep" | awk '{print $2}' if [ -z $PID ]; then printf "%s\n" "Fail" else echo $PID > $PIDFILE printf "%s\n" "Ok" fi ;; status) printf "%-50s" "Checking $NAME..." if [ -f $PIDFILE ]; then PID=cat $PIDFILE if [ -z "ps axf | grep ${PID} | grep -v grep" ]; then printf "%s\n" "Process dead but pidfile exists" else echo "Running" fi else printf "%s\n" "Service not running" fi ;; stop) printf "%-50s" "Stopping $NAME" PID=cat $PIDFILE if [ -f $PIDFILE ]; then kill -HUP $PID printf "%s\n" "Ok" rm -f $PIDFILE else printf "%s\n" "pidfile not found" fi ;; restart) $0 stop $0 start ;; *) echo "Usage: $0 {status|start|stop|restart}" exit 1 esac

P.S.Don't forget make it executable(chmod 775 [this_file_name])

andreapernici commented 10 years ago

I get this error ./newrelic-logwatcher.sh: line 13: -fu: command not found

Il 13/05/2014 09:03, MarynaIS ha scritto:

Yep, I've written simple init.d, and take it on /etc/init.d:

!/bin/bash

description: newrelic logwatcher daemon

processname: newrelic logwatcher

DAEMON_PATH="YOUR/PATH/TO/newrelic_logwatcher_agent.rb" DAEMON=newrelic_logwatcher_agent.rb NAME=newrelic_logwatcher_agent PIDFILE=/var/run/$NAME.pid

case "$1" in start) printf "%-50s" "Starting $NAME..." cd $DAEMON_PATH PID=|/bin/ps -fu $USER| grep "logwatcher" | grep -v "grep" | awk '{print $2}'| if [ -z $PID ]; then printf "%s\n" "Fail" else echo $PID > $PIDFILE printf "%s\n" "Ok" fi ;; status) printf "%-50s" "Checking $NAME..." if [ -f $PIDFILE ]; then PID=|cat $PIDFILE| if [ -z "|ps axf | grep ${PID} | grep -v grep|" ]; then printf "%s\n" "Process dead but pidfile exists" else echo "Running" fi else printf "%s\n" "Service not running" fi ;; stop) printf "%-50s" "Stopping $NAME" PID=|cat $PIDFILE| if [ -f $PIDFILE ]; then kill -HUP $PID printf "%s\n" "Ok" rm -f $PIDFILE else printf "%s\n" "pidfile not found" fi ;; restart) $0 stop $0 start ;; *) echo "Usage: $0 {status|start|stop|restart}" exit 1 esac

P.S.Don't forget make it executable(chmod 775 [this_file_name])

— Reply to this email directly or view it on GitHub https://github.com/railsware/newrelic_platform_plugins/issues/34#issuecomment-42923491.

-- Z-Light e Z-Pro: servizi zimbra per caselle con dominio email.it, per tutti i dettagli Clicca qui http://posta.email.it/caselle-di-posta-email-it/?utm_campaign=email_Zlight_Pro&utm_source=footer/f

Sponsor: Registra i domini che desideri ed inizia a creare il tuo sito web Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=13323&d=15-5

andreapernici commented 10 years ago

Solved doing this

PID=/bin/ps -fu $USER| grep "logwatcher" | grep -v "grep" | awk '{print $2}' if [[ -z $PID ]]; then

Il 13/05/2014 09:03, MarynaIS ha scritto:

Yep, I've written simple init.d, and take it on /etc/init.d:

!/bin/bash

description: newrelic logwatcher daemon

processname: newrelic logwatcher

DAEMON_PATH="YOUR/PATH/TO/newrelic_logwatcher_agent.rb" DAEMON=newrelic_logwatcher_agent.rb NAME=newrelic_logwatcher_agent PIDFILE=/var/run/$NAME.pid

case "$1" in start) printf "%-50s" "Starting $NAME..." cd $DAEMON_PATH PID=|/bin/ps -fu $USER| grep "logwatcher" | grep -v "grep" | awk '{print $2}'| if [ -z $PID ]; then printf "%s\n" "Fail" else echo $PID > $PIDFILE printf "%s\n" "Ok" fi ;; status) printf "%-50s" "Checking $NAME..." if [ -f $PIDFILE ]; then PID=|cat $PIDFILE| if [ -z "|ps axf | grep ${PID} | grep -v grep|" ]; then printf "%s\n" "Process dead but pidfile exists" else echo "Running" fi else printf "%s\n" "Service not running" fi ;; stop) printf "%-50s" "Stopping $NAME" PID=|cat $PIDFILE| if [ -f $PIDFILE ]; then kill -HUP $PID printf "%s\n" "Ok" rm -f $PIDFILE else printf "%s\n" "pidfile not found" fi ;; restart) $0 stop $0 start ;; *) echo "Usage: $0 {status|start|stop|restart}" exit 1 esac

P.S.Don't forget make it executable(chmod 775 [this_file_name])

— Reply to this email directly or view it on GitHub https://github.com/railsware/newrelic_platform_plugins/issues/34#issuecomment-42923491.

-- Z-Light e Z-Pro: servizi zimbra per caselle con dominio email.it, per tutti i dettagli Clicca qui http://posta.email.it/caselle-di-posta-email-it/?utm_campaign=email_Zlight_Pro&utm_source=footer/f

Sponsor: Scopri il nuovo HTC One M8, progettato per eccellere sotto ogni punto di vista Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=13321&d=15-5

andreapernici commented 10 years ago

But unfortunatly now I get

/./newrelic-logwatcher.sh: line 34: /var/run/newrelic_logwatcher_agent.pid: Permission denied

when doing logwatcher stop

/Il 13/05/2014 09:03, MarynaIS ha scritto:

Yep, I've written simple init.d, and take it on /etc/init.d:

!/bin/bash

description: newrelic logwatcher daemon

processname: newrelic logwatcher

DAEMON_PATH="YOUR/PATH/TO/newrelic_logwatcher_agent.rb" DAEMON=newrelic_logwatcher_agent.rb NAME=newrelic_logwatcher_agent PIDFILE=/var/run/$NAME.pid

case "$1" in start) printf "%-50s" "Starting $NAME..." cd $DAEMON_PATH PID=|/bin/ps -fu $USER| grep "logwatcher" | grep -v "grep" | awk '{print $2}'| if [ -z $PID ]; then printf "%s\n" "Fail" else echo $PID > $PIDFILE printf "%s\n" "Ok" fi ;; status) printf "%-50s" "Checking $NAME..." if [ -f $PIDFILE ]; then PID=|cat $PIDFILE| if [ -z "|ps axf | grep ${PID} | grep -v grep|" ]; then printf "%s\n" "Process dead but pidfile exists" else echo "Running" fi else printf "%s\n" "Service not running" fi ;; stop) printf "%-50s" "Stopping $NAME" PID=|cat $PIDFILE| if [ -f $PIDFILE ]; then kill -HUP $PID printf "%s\n" "Ok" rm -f $PIDFILE else printf "%s\n" "pidfile not found" fi ;; restart) $0 stop $0 start ;; *) echo "Usage: $0 {status|start|stop|restart}" exit 1 esac

P.S.Don't forget make it executable(chmod 775 [this_file_name])

— Reply to this email directly or view it on GitHub https://github.com/railsware/newrelic_platform_plugins/issues/34#issuecomment-42923491.

-- Z-Light e Z-Pro: servizi zimbra per caselle con dominio email.it, per tutti i dettagli Clicca qui http://posta.email.it/caselle-di-posta-email-it/?utm_campaign=email_Zlight_Pro&utm_source=footer/f

Sponsor: Pasticceri in poche mosse e' possibile con la splendida biscottiera elettrica, scoprila Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=13300&d=15-5

MarynaIS commented 10 years ago

check owner of file /var/run/newrelic_logwatcher_agent.pid (chown [user]:[user] var/run/newrelic_logwatcher_agent.pid) or change mod (chmod +755 var/run/newrelic_logwatcher_agent.pid)

or run /etc/init.d/newrelic_logwatcher as root(with sudo)

andreapernici commented 10 years ago

When chmod 755 I get Stopping newrelic_logwatcher_agent /var/run/newrelic_logwatcher_agent.pid: line 1: 16350: command not found and when I start /etc/init.d with root privileges leaving 644 I get Stopping newrelic_logwatcher_agent /etc/init.d/newrelic-logwatcher: line 34: /var/run/newrelic_logwatcher_agent.pid: Permission denied

In any case nothing came up in the NewRelic dashboard.

Il 15/05/2014 12:43, MarynaIS ha scritto:

check owner of file /var/run/newrelic_logwatcher_agent.pid (chown [user]:[user] var/run/newrelic_logwatcher_agent.pid) or change mod (chmod +755 var/run/newrelic_logwatcher_agent.pid)

— Reply to this email directly or view it on GitHub https://github.com/railsware/newrelic_platform_plugins/issues/34#issuecomment-43195006.

-- Z-Light e Z-Pro: servizi zimbra per caselle con dominio email.it, per tutti i dettagli Clicca qui http://posta.email.it/caselle-di-posta-email-it/?utm_campaign=email_Zlight_Pro&utm_source=footer/f

Sponsor: Scegli il programma Partner di Email.it e offri ai tuoi clienti una valida alternativa a Office 365 incrementando i tuoi margini Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=13189&d=15-5

MarynaIS commented 10 years ago

Just in case, have you installed logwatcher? and could you make ls -la /var/run | grep "newrelic_logwatcher_agent.pid"

andreapernici commented 10 years ago

Il 15/05/2014 15:54, MarynaIS ha scritto:

Just in case, have you installed logwatcher? and could you make ls -la /var/run | grep "newrelic_logwatcher_agent.pid"

— Reply to this email directly or view it on GitHub https://github.com/railsware/newrelic_platform_plugins/issues/34#issuecomment-43211860.

Yes is installed.

-- Z-Light e Z-Pro: servizi zimbra per caselle con dominio email.it, per tutti i dettagli Clicca qui http://posta.email.it/caselle-di-posta-email-it/?utm_campaign=email_Zlight_Pro&utm_source=footer/f

Sponsor: OFFERTA 3x2 Blu-Ray, tantissimi film e serie tv. Scopri tutto Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=13322&d=15-5

esobczak1970 commented 8 years ago

Any plans to make this an npi compatible plugin?