Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
mrtg scripts [solved]
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
jonfr
Veteran
Veteran


Joined: 20 Jul 2003
Posts: 1008
Location: Denmark

PostPosted: Tue Feb 12, 2008 11:01 pm    Post subject: mrtg scripts [solved] Reply with quote

Where can I find mrtg scripts ? But I want to do more then just basic things like check on lan traffic and so on.
I am a poor at writing scripts.

I am also intrested in knowing if somebody knows how to get traffic statics from speedtouch 585 router.

Thanks in advance.


Last edited by jonfr on Tue Mar 24, 2009 2:38 am; edited 4 times in total
Back to top
View user's profile Send private message
di1bert
l33t
l33t


Joined: 16 May 2002
Posts: 963
Location: Oslo, Norway

PostPosted: Wed Feb 13, 2008 6:43 am    Post subject: Reply with quote

There's a bunch of scripts and stuff
on the MRTG home page...

When in doubt, Google it :wink:


-m
Back to top
View user's profile Send private message
jonfr
Veteran
Veteran


Joined: 20 Jul 2003
Posts: 1008
Location: Denmark

PostPosted: Thu Feb 14, 2008 12:04 am    Post subject: Reply with quote

I did check that site. But many links are dead. I am also looking into scripts that can help me count the earthquakes on few web pages, EMSC and USGS for instance. But I also want to count the earthquakes on the Icelandic Physics Department web page.

But I don't have the know how to write an script. :(
Back to top
View user's profile Send private message
oliver
Apprentice
Apprentice


Joined: 25 Jun 2003
Posts: 170

PostPosted: Thu Feb 14, 2008 8:15 pm    Post subject: Reply with quote

you'll need to do something like this (in pseudo code)

COUNT=`curl http://www.whatever.com | grep "number of earthquakes" | awk -F' ' '{print $2}'`
echo ${COUNT}
echo ${COUNT}
echo "uptime"
echo "name"

This is because MRTG requires four lines of output when evaluating data... the first is the "in" bytes, the second is the "out" bytes, third is uptime (in human readable form) and the last is the hostname. Since the last two aren't really relevent they don't have to be accurate or even valid

Then create a earthquate.cfg file and point the target line to your script (in backticks)

Target=`/path/to/your/script`

Also, make sure you include "noinfo" and "gauge" in the options. Noinfo will ignore the last two lines of your script and gauge treats each reading like a new count and not a deviation from the last.

If you search the forum for "power under control" you'll find a nice mrtg guide
Back to top
View user's profile Send private message
jonfr
Veteran
Veteran


Joined: 20 Jul 2003
Posts: 1008
Location: Denmark

PostPosted: Sat Feb 16, 2008 2:52 pm    Post subject: Reply with quote

Thanks. Is this shell script (bash) or something else ?
Back to top
View user's profile Send private message
oliver
Apprentice
Apprentice


Joined: 25 Jun 2003
Posts: 170

PostPosted: Sat Feb 16, 2008 9:29 pm    Post subject: Reply with quote

yes, bash is fine... all you need is something that can grab the basic data that you want to graph and output it in a way that mrtg can understand.
Back to top
View user's profile Send private message
jonfr
Veteran
Veteran


Joined: 20 Jul 2003
Posts: 1008
Location: Denmark

PostPosted: Sat Mar 01, 2008 2:22 am    Post subject: Reply with quote

I finally had time to looka at this. But it isn't working.

Here are the scripts that I am using.

Code:
#earthquake count shell V0.2

#!/bin/sh

COUNT=`curl http://hraun.vedur.is/ja/englishweb/eqlist.html | grep "Ml" | awk -F' ' '{pr$
echo ${COUNT}
echo ${COUNT}
echo "Ml"
echo "Ml"


Code:
#---------Apache hits-----------------------
WorkDir: /var/www/localhost/htdocs/mrtg
Target[localhost_eq]: `/etc/mrtg/eq.imo.sh`
Options[localhost_eq]: perhour, nopercent, growright, noinfo, nobanner, noi
MaxBytes[localhost_eq]: 1000000
YLegend[localhost_eq]: count
ShortLegend[localhost_eq]: par heure   
LegendO[localhost_eq]: Hits:
Legend2[localhost_eq]: Hits horaires
Legend4[localhost_eq]: Hits Horaires max
Title[localhost_eq]: Hits horaires du serveur Apache
WithPeak[localhost_eq]: wmy
PageTop[localhost_eq]: <h1>Earthquake Count</h1>
#------------End Apache Hits------------------


I am still modifing this scripts, as it can be seen on the name. I also get this from cron job.

Code:
Output from command /usr/bin/mrtg /etc/mrtg/eq.imo.cfg  ..

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

 10 10142   10  1127    0     0   6737      0  0:00:01 --:--:--  0:00:01  6737
100 10142  100 10142    0     0  35746      0 --:--:-- --:--:-- --:--:-- 77715
2008-03-01 02:22:27: WARNING: Problem with External get '/etc/mrtg/eq.imo.sh':
   Expected a Number for 'in' but got 'list align="center"'

2008-03-01 02:22:27: WARNING: Problem with External get '/etc/mrtg/eq.imo.sh':
   Expected a Number for 'out' but got 'list align="center"'

2008-03-01 02:22:28: ERROR: Target[localhost_eq][_IN_] ' $target->[0]{$mode} ' did not eval into defined data
2008-03-01 02:22:28: ERROR: Target[localhost_eq][_OUT_] ' $target->[0]{$mode} ' did not eval into defined data


Thanks in advance for the help.
Back to top
View user's profile Send private message
oliver
Apprentice
Apprentice


Joined: 25 Jun 2003
Posts: 170

PostPosted: Sat Mar 01, 2008 12:58 pm    Post subject: Reply with quote

the problem is that your script is not returning a numeric result... it looks like your script will just be grabbing the actual line in the html page that says "Ml" and not the actual reading.

Code:

Date   Time   Lat.   Lon.   Depth   Ml   Quality       Comments      
2008-03-01   07:35:33,6   63,905   -21,961   1,1   1,7   90,01   5,5 km   ENE   of Krísuvík


If this is the actual page, what readings are you trying to map? Or are you after a count of the number of earthquakes per day?
Back to top
View user's profile Send private message
jonfr
Veteran
Veteran


Joined: 20 Jul 2003
Posts: 1008
Location: Denmark

PostPosted: Sat Mar 01, 2008 2:49 pm    Post subject: Reply with quote

The number below Ml is the earthquake, but it means the size of it (local scale). But the lines there are the earthquakes that I am trying to count. I am trying to count the numbers pr day, so I can see how it changes from time to time.
Back to top
View user's profile Send private message
oliver
Apprentice
Apprentice


Joined: 25 Jun 2003
Posts: 170

PostPosted: Sat Mar 01, 2008 5:53 pm    Post subject: Reply with quote

I love MRTG but I don't think it's the right tool to do this. I don't think you'll ever be able to ensure it's accuracy regarding the time. What I mean is that MRTG will run at 5 or 15 minute intervals (or whatever you set it to in cron) and it's dependant on the web page updating in real time. If the web page is not in real time, MRTG has no way to determine this. (At least I don't know of a way to integrate the timestamps into a reading as MRTG maintains it's own timestamps in the .../<definition>.log file).

For example, if there happened to be earthquakes at 5am/10am/3pm/8pm during the day and they were all posted at 10pm on the site, MRTG would see this as 4 quakes at 10pm as you cannot manipulate the X axis (the time span)

I think something like ploticus would be more suitable... if you changed your script to something like

Code:

#!/bin/bash

URL="http://hraun.vedur.is/ja/englishweb/eqlist.html"
YDATE=`date -d yesterday +%Y-%m-%d`
YQUAKES="quakes.${YDATE}"

lynx -dump ${URL} | grep ${YDATE} | sed 's/ .*\[[0-9][0-9]\]//g' | awk -F' ' '{print $1, $2, $6}' > ${YQUAKES}

exit 0


and then fed that into ploticus I think you'll get what you're after (I haven't used ploticus in a *long* time though)

The script itself could probably be cleaned up a little (the sed / awk part I think) but it seems to work - I didn't really test it thoroughly though

All it's doing is setting yesterdays date (so you get all of yesterdays quakes in one go) and then putting them into a new file called quakes.<yesterdays date>

This file has 3 columns:
date
time
ML reading
Back to top
View user's profile Send private message
jonfr
Veteran
Veteran


Joined: 20 Jul 2003
Posts: 1008
Location: Denmark

PostPosted: Sat Mar 01, 2008 6:06 pm    Post subject: Reply with quote

Thanks for the help. It is much appreciated. I think that the best way in regarding to size is to count it in a special plot on it's own, as not all web pages that display earthquake data use the same size value.

The IMO web page is updated every 5 min or so, near real time.

When testing the script I found that I get this error in cron when I try run it with mrtg.

Code:
Output from command /usr/bin/mrtg /etc/mrtg/eq.imo.cfg  ..

2008-03-01 18:07:10: WARNING: Could not get any data from external command '/etc/mrtg/eq.imo.sh'
Maybe the external command did not even start. (Illegal seek)

2008-03-01 18:07:10: WARNING: Problem with External get '/etc/mrtg/eq.imo.sh':
   Expected a Number for 'in' but nothing'

2008-03-01 18:07:10: WARNING: Problem with External get '/etc/mrtg/eq.imo.sh':
   Expected a Number for 'out' but nothing'

2008-03-01 18:07:12: ERROR: Target[localhost_eq][_IN_] ' $target->[0]{$mode} ' did not eval into defined data
2008-03-01 18:07:12: ERROR: Target[localhost_eq][_OUT_] ' $target->[0]{$mode} ' did not eval into defined data


Going to test ploticus as you suggested. But I have no idea how to run it with cron or how to configure it.
Back to top
View user's profile Send private message
oliver
Apprentice
Apprentice


Joined: 25 Jun 2003
Posts: 170

PostPosted: Sat Mar 01, 2008 6:56 pm    Post subject: Reply with quote

mrtg will always error out unless it receives data like this when you run the script by hand:

./myscript
33
4343
3 days 4 hours 5 minutes 6 seconds
myhostname

(but obviously with real data)

If you really just need a count, something like this should work

Code:

#!/bin/bash

URL="http://hraun.vedur.is/ja/englishweb/eqlist.html"
TODAYSDATE=`date +%Y-%m-%d`

COUNT=`lynx -dump ${URL} | grep ${TODAYSDATE} | grep -vi updated | wc -l`
echo ${COUNT}
echo ${COUNT}
echo "uptime"
echo "hostname"

exit 0


But it will just give you a raw count of the number of earthquakes on the day it's run... no info about size or anything else

And the ploticus web site has lots of examples and info... it's a nice app
Back to top
View user's profile Send private message
jonfr
Veteran
Veteran


Joined: 20 Jul 2003
Posts: 1008
Location: Denmark

PostPosted: Sat Mar 08, 2008 9:22 pm    Post subject: Reply with quote

I do get statics with this script, thanks. :D :D
But the problem is that I get double statics, for one earthquake I get like 7 counts.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum