Graphing % Uptime from database
Moderators: Developers, Moderators
Graphing % Uptime from database
Hi All,
this is my first attempt at a template and script. I wanted to graph the % availability from the database so i wrote a script to rip out the % from the db with the ip address as the input. I modelled it on the ping latency at this stage. Next I am going to try to build a second and third trend line and graph the current and average ms from the db as well.
i've attached my graph template. I hope I have exported properly. if you need to, change the uname/pw etc for access to the cacti database.
Note: manually put in the IP address like you do for a ping latency script. I've tried to put in |host_ip| which should get it from that hosts database record? doesn't seem to work tho. works fine if you put in the ip address
script:
#!/usr/bin/php -q
<?php
/* percent_uptime.php Grabs the uptime from the database so it can be graphed.
Gets on argumets (ip address to lookup);
Returns uptime as a number.
Matthew Western
*/
$ip = $argv[1];
$server = "localhost";
$db = mysql_connect($server, "root", "");
mysql_select_db("cacti", $db);
$sql="SELECT * FROM host WHERE hostname = '$ip'";
$result=mysql_query($sql, $db);
while ($row = mysql_fetch_array($result)) {
$avail = $row['availability'];
}
print trim($avail);
exit(0);
?>
this is my first attempt at a template and script. I wanted to graph the % availability from the database so i wrote a script to rip out the % from the db with the ip address as the input. I modelled it on the ping latency at this stage. Next I am going to try to build a second and third trend line and graph the current and average ms from the db as well.
i've attached my graph template. I hope I have exported properly. if you need to, change the uname/pw etc for access to the cacti database.
Note: manually put in the IP address like you do for a ping latency script. I've tried to put in |host_ip| which should get it from that hosts database record? doesn't seem to work tho. works fine if you put in the ip address
script:
#!/usr/bin/php -q
<?php
/* percent_uptime.php Grabs the uptime from the database so it can be graphed.
Gets on argumets (ip address to lookup);
Returns uptime as a number.
Matthew Western
*/
$ip = $argv[1];
$server = "localhost";
$db = mysql_connect($server, "root", "");
mysql_select_db("cacti", $db);
$sql="SELECT * FROM host WHERE hostname = '$ip'";
$result=mysql_query($sql, $db);
while ($row = mysql_fetch_array($result)) {
$avail = $row['availability'];
}
print trim($avail);
exit(0);
?>
- Attachments
-
- cacti_graph_template_script_db_uptime.xml
- v3. Graph Template for script
- (8 KiB) Downloaded 834 times
-
- Posts: 6
- Joined: Mon Jul 25, 2005 10:43 am
- Location: Red Lion, PA
- Contact:
RE: Graphing % Uptime from database
hey Mathew,
I have been looking for exactly this type of graphing function.... to simply graph availability that is already in the database.....
Thanks for the great effort!!
In testing, when I manually connect to the db using mysql and perform the SELECT * FROM host WHERE hostname = ipaddress, I get all the rows and the data associated with them.... When I run the php script against the IP in question (script was modified for the db username and password) I only get the header output:
Content-type: text/html
X-Powered-By: PHP/4.3.11
!/usr/bin/php -q
and then get dumped out....
I would love to be able to graph this.... and being a mysql newbie, I feel a bit lost here...
Any ideas?
I'm running mysql version 3.23.58-16, cacti ver 86f with THold ver 2.1a using cmd.php as the poller. It's cool I can see the output when I manually query the database from within mysql's cli client - so close I can taste it! I feel kind of foolish when I can graph BGP States and Flaps but can't even query the availabilities of all my devices.... yeesh...
Thanks for any and all assistance.....
Denny Snyder
I have been looking for exactly this type of graphing function.... to simply graph availability that is already in the database.....
Thanks for the great effort!!
In testing, when I manually connect to the db using mysql and perform the SELECT * FROM host WHERE hostname = ipaddress, I get all the rows and the data associated with them.... When I run the php script against the IP in question (script was modified for the db username and password) I only get the header output:
Content-type: text/html
X-Powered-By: PHP/4.3.11
!/usr/bin/php -q
and then get dumped out....
I would love to be able to graph this.... and being a mysql newbie, I feel a bit lost here...
Any ideas?
I'm running mysql version 3.23.58-16, cacti ver 86f with THold ver 2.1a using cmd.php as the poller. It's cool I can see the output when I manually query the database from within mysql's cli client - so close I can taste it! I feel kind of foolish when I can graph BGP States and Flaps but can't even query the availabilities of all my devices.... yeesh...
Thanks for any and all assistance.....
Denny Snyder
Denny Snyder
NOC Systems Engineer
wolverine(nine-eight-two-seven) at gmail dot com
NOC Systems Engineer
wolverine(nine-eight-two-seven) at gmail dot com
-
- Posts: 6
- Joined: Mon Jul 25, 2005 10:43 am
- Location: Red Lion, PA
- Contact:
DUH!
Oh christ... nevermind....
heaven forbid I actually learn how to cut and paste properly....
PHP scripts generally enjoy having the first '#' character present.... duh....
(slapping forehead with palm)
Thanks man.... I should start to see data now since it worked manually for me....
heaven forbid I actually learn how to cut and paste properly....
PHP scripts generally enjoy having the first '#' character present.... duh....
(slapping forehead with palm)
Thanks man.... I should start to see data now since it worked manually for me....
Denny Snyder
NOC Systems Engineer
wolverine(nine-eight-two-seven) at gmail dot com
NOC Systems Engineer
wolverine(nine-eight-two-seven) at gmail dot com
:) Glad to help
I'm glad you got it all working nicely.
I like it as well. I use it in conjuction with the hrSystemuptime posted by so i get uptime in percentage and uptime in days.
http://forums.cacti.net/viewtopic.php?t ... stemuptime
the first one works well with my unix and cisco stuff and the other one works well with my winblows boxes...
I like it as well. I use it in conjuction with the hrSystemuptime posted by so i get uptime in percentage and uptime in days.
http://forums.cacti.net/viewtopic.php?t ... stemuptime
the first one works well with my unix and cisco stuff and the other one works well with my winblows boxes...
-
- Posts: 6
- Joined: Mon Jul 25, 2005 10:43 am
- Location: Red Lion, PA
- Contact:
You da Man!
Thanks a boatload!
I think I'm having entirely too much fun with this.... will have to take a downer and get to work...
Thanks again!
I think I'm having entirely too much fun with this.... will have to take a downer and get to work...
Thanks again!
Denny Snyder
NOC Systems Engineer
wolverine(nine-eight-two-seven) at gmail dot com
NOC Systems Engineer
wolverine(nine-eight-two-seven) at gmail dot com
mwestern... cool idea! I'm trying to get both yours and the hrSystemUptime one going. Today just isn't my day b/c I'm striking out on both. Yours works great if I run it from a command prompt. All of the hosts I've added yield an error like this though when done through Cacti
Have you run across that one before?
On the hrSystemUptime that you're doing, I tried importing the script from the link you provided, but it wouldn't import so I'm trying to build it manually.
I'm getting "U" in the log files when I do the SNMP query... I popped the OID he provided into GetIF and I'm getting back values like "184:5:55:05.15"... doesn't look very Cacti-friendly. Any idea what I'm missing here??
Thanks,
Jason
Code: Select all
07/28/2005 02:10:38 PM - CACTID: Poller[0] Host[47] ERROR: Empty result [10.80.100.4]: 'C:\apachefriends\xampp\cacti/scripts/percent_uptime.php 10.80.100.4'
On the hrSystemUptime that you're doing, I tried importing the script from the link you provided, but it wouldn't import so I'm trying to build it manually.
I'm getting "U" in the log files when I do the SNMP query... I popped the OID he provided into GetIF and I'm getting back values like "184:5:55:05.15"... doesn't look very Cacti-friendly. Any idea what I'm missing here??
Thanks,
Jason
Hmm
I don't know about that. mine didn't work very well when i was writing the script if the php script output a line feed.
I've not tried it on windows cacti.
have you got any other scripts working on your windows cacti like the default ping.pl and others?
I've not tried it on windows cacti.
have you got any other scripts working on your windows cacti like the default ping.pl and others?
Yes, do have a ping script up and running. And yes, it's a Windows install too.
For your script, I know I've got to be doing something stupid since it works from the command line. For the SNMP one... Who knows. I think I may just need to back-burner it for a day or two and take a fresh start on it again. I tried combination after combination of settings today, but success kept eluding me.
If I find a fix, I'll update.
Thanks,
Jason
For your script, I know I've got to be doing something stupid since it works from the command line. For the SNMP one... Who knows. I think I may just need to back-burner it for a day or two and take a fresh start on it again. I tried combination after combination of settings today, but success kept eluding me.
If I find a fix, I'll update.
Thanks,
Jason
Hum doesn't seem to be working for me either. I get the "U" retruned vaule even thoguh when i specify the address from the command line it works.
I think its the Custom Data that is in teh Data Template. The template included in this thread has it as "|host_ip|" I tried |query_host_ip|, |host_hostname| and other variations (unfortunatly I can't seem to find the document that states what are the potential |host_*| variables)
What do you have in that field?
I think its the Custom Data that is in teh Data Template. The template included in this thread has it as "|host_ip|" I tried |query_host_ip|, |host_hostname| and other variations (unfortunatly I can't seem to find the document that states what are the potential |host_*| variables)
What do you have in that field?
- Aaron Jeskey
- TheWitness
- Developer
- Posts: 17007
- Joined: Tue May 14, 2002 5:08 pm
- Location: MI, USA
- Contact:
Could be a cactid issue. Make sure you have cygwin installed if you are in Windows. Also, I suggest that you move PHP scripts to script server implmentataion if you plan on polling several hosts.
TheWtness
TheWtness
True understanding begins only when we realize how little we truly understand...
Life is an adventure, let yours begin with Cacti!
Author of dozens of Cacti plugins and customization's. Advocate of LAMP, MariaDB, IBM Spectrum LSF and the world of batch. Creator of IBM Spectrum RTM, author of quite a bit of unpublished work and most of Cacti's bugs.
_________________
Official Cacti Documentation
GitHub Repository with Supported Plugins
Percona Device Packages (no support)
Interesting Device Packages
For those wondering, I'm still here, but lost in the shadows. Yearning for less bugs. Who want's a Cacti 1.3/2.0? Streams anyone?
Life is an adventure, let yours begin with Cacti!
Author of dozens of Cacti plugins and customization's. Advocate of LAMP, MariaDB, IBM Spectrum LSF and the world of batch. Creator of IBM Spectrum RTM, author of quite a bit of unpublished work and most of Cacti's bugs.
_________________
Official Cacti Documentation
GitHub Repository with Supported Plugins
Percona Device Packages (no support)
Interesting Device Packages
For those wondering, I'm still here, but lost in the shadows. Yearning for less bugs. Who want's a Cacti 1.3/2.0? Streams anyone?
Re: Graphing % Uptime from database
OK... Not sure what is required here. Do I need to create a script file with the contents the same as in the first post, then import the xml, or JUST import the XML... Usually when someone posts this sort of thing they post the script as a file....
Witness - if I can get this to work on 0.8.8a (CactiEZ implementation) how would I go about getting it to work in script server....
Or is there a better way to do what this script is trying to do now?
Witness - if I can get this to work on 0.8.8a (CactiEZ implementation) how would I go about getting it to work in script server....
Or is there a better way to do what this script is trying to do now?
No longer a n00by, probably, by now an 0ldby
Now Head of Technology at RSCH, back to the prickly subject of Monitorring....
Now Head of Technology at RSCH, back to the prickly subject of Monitorring....
Who is online
Users browsing this forum: No registered users and 4 guests