getting startet with graph
Moderators: Developers, Moderators
getting startet with graph
hi to all,
can please anybody explain it for dumies , howto create graph with own scripts? or is anywhere a setp by setp howto ?
all included graphs work fine, but i´am not getting any own graphs runnig.
thnx for advance !
regards
Getting Started
(preamble: I'm still a newbie... Don't look to me for advanced graphing or troubleshooting, but I can help with simple steps. However, if anybody is managing a FAQ or the documentation, I recommend that this be edited/corrected and added, as it seems this question is asked frequently.)
(Additional pre-addendums: This is intended for folks who are successfully seeing [at least most of] the graphs that were included with Cacti.)
Are you asking how to write scripts? Or how to add graphs once the script is created?
Assuming you have some skill with a scripting language, the only important piece of information I found is that a trailing \n after the data output is not handled well by cacti. There's a way to fix that in source somewhere around here, but I just edit my scripts.
As a simple example, one of my favorite graphs watches how many spam messages my mailserver blocks. The software places every spam message into a special directory, and for this example let's call it "/tmp/spam".
Step 1: Create the script.
I created a simple script to count the number of files in this directory, as follows:
Test this, and make sure it can run as the user in the crontab, and that it outputs the proper number. (I find it convenient to run './dircount /tmp/spam; echo ""', so that I'll get the carriage return that the script removes.
Step 2: Create the data input
Go to console/data input, and click "Add". For the name, pick something descriptive. For this example, I'd enter something like, "Get directory count", or whatever will help me remember.
The input string in this example would be: <path_cacti>/scripts/dircount <countdir>
The output string would be: <numfiles>
Click save, and a new bar will come up asking for Data Input Source Fields. In this example, there are two of them: "countdir" and "numfiles" (path_cacti is built-in)
Click add, and set up the input source.
For the name, put something descriptive like "Directory", and for the Data Name put "countdir" (to match the above). Field type is Input, and is not used to update the RRA, meaning that the system won't record this information.
Click "Save" and add another.
For this one, put the name as "Number of Files", the Data name as "numfiles", and change the type to "Output" and check "Field Used to Update RRA". Click "Save" to exit the data input source field, and (I'm not sure this is necessary) "Save" one more time to save the data input source itself.
Step 3: Create the Data Source
Now it's time to get specific. The data input source told the system how to get the file count of some directory, now we're going to tell the software how to get the count of a specific directory.
Click on "Data Sources" and click "Add".
For "Name" type something like, "server_spamcount". NOTE: This name cannot contain any "unusual" characters. No spaces, semicolons, apostrophes, colons, slashes, etc. I suggest sticking to letters, numbers, and underscores. I also seem to run into problems if this is too long, but that may be my imagination. I try to keep it short (< 30 characters).
Some additional suggestions on naming:
(a) Group similar things together by a common prefix. For instance, all of my server data sources start with the name of the server, like "banya_load_avg" and "banya_dns_queries". This will put them together on some dropdown boxes you'll see later.
(b) ... Can't think of anything right now.
For "Data Source Type", the two most important choices are "Gauge" and "Count". Select "Gauge" if you're reading something that will reset every time it's read, such as "number of users", or "ping time". Select "Count" if it's a number that continues to increment. Such as "Packets Transmitted" or "Number of DNS Queries".
For this example, it is a "Count", since the files aren't cleared out of that directory until the nightly cronjob. (Don't worry about the fact that the files are cleared out, though, if a 'Count' type drops (significantly?), it is assumed to have restarted or rolled over).
In "Data Input Type", select the new data input source you created in Step 2, such as "Get Directory Count".
Highlight all the Associated RRA's you wish to track, probably all of them.
Make minimum and maximum values reasonable for this graph. In our case, our server might not block any emails, so minimum is 0, and if it blocks over 1,000,000 emails (in a 5 minute period), I would be terribly impressed, and probably need a new server, so that's the maximum. You want to set the maximum to a value that is higher than anything your server may process, but low enough that errors would be detected. In fact, I could probably drop this value by a factor of 10 or 100 and not screw up my data, but I'm not real concerned about false reads for this script.
I always check the box that says, "Update Changes in .RRA", and I recommend you do, too. There are reasons not to, but you'll have to wait until you're more experienced before you discover them.
All other fields you should leave at their defaults, and then click "Save".
Now, we need to tell the system what directory this data source counts. So, find your "server_spamcount" in the list, and click "Edit Data". In the field that is probably labeled "Directory", enter "/tmp/spam", and click "Save".
Step 4: Wait
This is the hardest step for me. I'm very impatient. I feel like I've done my part, let's keep going. But the fact is, this cronjob only runs every 5 minutes, and running it by hand isn't going to help anything (and can, in fact, create doubts on whether it's working).
So, go create a new data source, or a new data input source, or go get a cup of coffee, a cigarette, or a beer. If the data type is "count", then you should probably have two.
That is to say, for a "Gauge" data type, the first plot point won't enter the system until the first time the cronjob runs, which is usually in 5-10 minutes. If it's a "Count" data type, the first plot point doesn't show up until it's run twice, which can be 10-15 minutes. For you to see anything decent on the graph (which we're about to create), you'll want multiple plot points. So patience is key.
Step 5: Make the graph
Click on "Graphs" and then "Add".
In "Name", enter something descriptive. Again, I recommend starting with something that will order similar graphs together, but you can use spaces and such in this one. For this example, use "Server Spam Blocked".
In "Vertical Label", again enter something descriptive. For this example, I suggest "Messages".
Leave other fields at their defaults. You can experiment with their effects later, but for now, let's get a working graph.
Click "Save", find your new graph in the list, and click "Edit Graph Items".
Right away, click on "Turn Graph Preview ON" and "Turn Graph Output Preview ON". You will still have a missing graphic icon showing, but that's expected at this point.
Click the "Add" button.
In "Data Source", find your "server_spamcount" entry.
In "Color", pick your favorite non-white color.
Leave other options at their defaults. (Play with them later, let's get a working graph).
Click "Save".
If all goes well, and you followed my instructions correctly (and I didn't make a mistake typing them), you should see a graph with at least a colored dot at the right hand side.
I'll deal with "troubleshooting" in after this next step.
Step 6: Add the graph to the hierarchy
This is easy. Click on "Graph Hierarchy" and "Edit current graph hierarchy" and add your new graph somewhere. Congratulations, you have your own graph.
... troubleshooting in a moment, after I post this.
(Additional pre-addendums: This is intended for folks who are successfully seeing [at least most of] the graphs that were included with Cacti.)
Are you asking how to write scripts? Or how to add graphs once the script is created?
Assuming you have some skill with a scripting language, the only important piece of information I found is that a trailing \n after the data output is not handled well by cacti. There's a way to fix that in source somewhere around here, but I just edit my scripts.
As a simple example, one of my favorite graphs watches how many spam messages my mailserver blocks. The software places every spam message into a special directory, and for this example let's call it "/tmp/spam".
Step 1: Create the script.
I created a simple script to count the number of files in this directory, as follows:
Make this a script called something like 'dircount' and put it in the <path_cacti>/scripts/ directory, and make it executable.#! /bin/bash
COUNT=`ls -1 $1 | wc -l`
echo -n $COUNT
Test this, and make sure it can run as the user in the crontab, and that it outputs the proper number. (I find it convenient to run './dircount /tmp/spam; echo ""', so that I'll get the carriage return that the script removes.
Step 2: Create the data input
Go to console/data input, and click "Add". For the name, pick something descriptive. For this example, I'd enter something like, "Get directory count", or whatever will help me remember.
The input string in this example would be: <path_cacti>/scripts/dircount <countdir>
The output string would be: <numfiles>
Click save, and a new bar will come up asking for Data Input Source Fields. In this example, there are two of them: "countdir" and "numfiles" (path_cacti is built-in)
Click add, and set up the input source.
For the name, put something descriptive like "Directory", and for the Data Name put "countdir" (to match the above). Field type is Input, and is not used to update the RRA, meaning that the system won't record this information.
Click "Save" and add another.
For this one, put the name as "Number of Files", the Data name as "numfiles", and change the type to "Output" and check "Field Used to Update RRA". Click "Save" to exit the data input source field, and (I'm not sure this is necessary) "Save" one more time to save the data input source itself.
Step 3: Create the Data Source
Now it's time to get specific. The data input source told the system how to get the file count of some directory, now we're going to tell the software how to get the count of a specific directory.
Click on "Data Sources" and click "Add".
For "Name" type something like, "server_spamcount". NOTE: This name cannot contain any "unusual" characters. No spaces, semicolons, apostrophes, colons, slashes, etc. I suggest sticking to letters, numbers, and underscores. I also seem to run into problems if this is too long, but that may be my imagination. I try to keep it short (< 30 characters).
Some additional suggestions on naming:
(a) Group similar things together by a common prefix. For instance, all of my server data sources start with the name of the server, like "banya_load_avg" and "banya_dns_queries". This will put them together on some dropdown boxes you'll see later.
(b) ... Can't think of anything right now.
For "Data Source Type", the two most important choices are "Gauge" and "Count". Select "Gauge" if you're reading something that will reset every time it's read, such as "number of users", or "ping time". Select "Count" if it's a number that continues to increment. Such as "Packets Transmitted" or "Number of DNS Queries".
For this example, it is a "Count", since the files aren't cleared out of that directory until the nightly cronjob. (Don't worry about the fact that the files are cleared out, though, if a 'Count' type drops (significantly?), it is assumed to have restarted or rolled over).
In "Data Input Type", select the new data input source you created in Step 2, such as "Get Directory Count".
Highlight all the Associated RRA's you wish to track, probably all of them.
Make minimum and maximum values reasonable for this graph. In our case, our server might not block any emails, so minimum is 0, and if it blocks over 1,000,000 emails (in a 5 minute period), I would be terribly impressed, and probably need a new server, so that's the maximum. You want to set the maximum to a value that is higher than anything your server may process, but low enough that errors would be detected. In fact, I could probably drop this value by a factor of 10 or 100 and not screw up my data, but I'm not real concerned about false reads for this script.
I always check the box that says, "Update Changes in .RRA", and I recommend you do, too. There are reasons not to, but you'll have to wait until you're more experienced before you discover them.
All other fields you should leave at their defaults, and then click "Save".
Now, we need to tell the system what directory this data source counts. So, find your "server_spamcount" in the list, and click "Edit Data". In the field that is probably labeled "Directory", enter "/tmp/spam", and click "Save".
Step 4: Wait
This is the hardest step for me. I'm very impatient. I feel like I've done my part, let's keep going. But the fact is, this cronjob only runs every 5 minutes, and running it by hand isn't going to help anything (and can, in fact, create doubts on whether it's working).
So, go create a new data source, or a new data input source, or go get a cup of coffee, a cigarette, or a beer. If the data type is "count", then you should probably have two.
That is to say, for a "Gauge" data type, the first plot point won't enter the system until the first time the cronjob runs, which is usually in 5-10 minutes. If it's a "Count" data type, the first plot point doesn't show up until it's run twice, which can be 10-15 minutes. For you to see anything decent on the graph (which we're about to create), you'll want multiple plot points. So patience is key.
Step 5: Make the graph
Click on "Graphs" and then "Add".
In "Name", enter something descriptive. Again, I recommend starting with something that will order similar graphs together, but you can use spaces and such in this one. For this example, use "Server Spam Blocked".
In "Vertical Label", again enter something descriptive. For this example, I suggest "Messages".
Leave other fields at their defaults. You can experiment with their effects later, but for now, let's get a working graph.
Click "Save", find your new graph in the list, and click "Edit Graph Items".
Right away, click on "Turn Graph Preview ON" and "Turn Graph Output Preview ON". You will still have a missing graphic icon showing, but that's expected at this point.
Click the "Add" button.
In "Data Source", find your "server_spamcount" entry.
In "Color", pick your favorite non-white color.
Leave other options at their defaults. (Play with them later, let's get a working graph).
Click "Save".
If all goes well, and you followed my instructions correctly (and I didn't make a mistake typing them), you should see a graph with at least a colored dot at the right hand side.
I'll deal with "troubleshooting" in after this next step.
Step 6: Add the graph to the hierarchy
This is easy. Click on "Graph Hierarchy" and "Edit current graph hierarchy" and add your new graph somewhere. Congratulations, you have your own graph.
... troubleshooting in a moment, after I post this.
Last edited by Fred on Mon Jan 20, 2003 6:32 pm, edited 1 time in total.
Troubleshooting
Troubleshooting aka "What to do when nothings working."
So, you followed the steps above, and you're still getting a missing graphic in the graph preview.
First thing to do? Walk away. Now, this isn't some parenting skill like you go in the other room and count down from 100, but you need to let Cacti gather some data before your graph will come out. If you have an autoscaling graph, and there's only a single data point, you're not going to see anything. So go, grab yourself a beer, check your email, and read slashdot. A watched graph never renders, so distract yourself for awhile.
So, you've consumed a sixpack, realized that the only email you get advertises adult websites, and your graph still isn't rendering. What do we do now?
Step 1: Is cacti gathering data?
Click on "Data Sources", find your data source, and click "Edit Data". At the top, there will be two lines. If you've followed my example, it should read something similar to:
If it's a "U":
Look at the top line. This shows what cacti is executing in order to gather the number.
Run that from the command line. Does it print a number, no carriage return, and nothing else? If you followed my example, that script should be executable.
Check permissions. Can the user that's running the cronjob read the directory it's supposed to count? Can that user write to the <path_cacti>/rrd/ directory?
Double check all entries in the Data Input and Data Sources to make sure you didn't mispell anything.
Still doesn't work? Start over! Run through the steps in the tutorial again with new names and descriptions. Make sure you didn't miss anything, and give it time to gather data.
If it still doesn't work, post to the forums and ask specific questions. Let the forum readers know that the system is not collecting data and cut and paste the two lines in the "Edit Data" screen of your data source, and also the line from the top of the data source itself.
To increase the likelihood of a response, include the file and directory permissions of the relevant places. (for this example, /tmp/spam/, <path_cacti>/scripts/dircount, and <path_cacti>/rrd/) (We don't need to see every file, just the particular permissions). Also, check <path_cacti>/log/rrd.log for any relevant information.
Okay, it's collecting data, but my graph still doesn't render.
I'm not really qualified to write this section.
Information to include:
The output from "Turn Graph Output Preview ON" in the 'Edit Graph Items' screen.
The relevant graph and data source settings.
So, you followed the steps above, and you're still getting a missing graphic in the graph preview.
First thing to do? Walk away. Now, this isn't some parenting skill like you go in the other room and count down from 100, but you need to let Cacti gather some data before your graph will come out. If you have an autoscaling graph, and there's only a single data point, you're not going to see anything. So go, grab yourself a beer, check your email, and read slashdot. A watched graph never renders, so distract yourself for awhile.
So, you've consumed a sixpack, realized that the only email you get advertises adult websites, and your graph still isn't rendering. What do we do now?
Step 1: Is cacti gathering data?
Click on "Data Sources", find your data source, and click "Edit Data". At the top, there will be two lines. If you've followed my example, it should read something similar to:
The most important part is the second line, toward the end where it says: "N:1234", where 1234 should be the number of files in that directory. If that is a number, cacti is collecting data, and you can skip ahead. If that is a "U", that means it's "Unknown", and cacti isn't getting information from your script./var/www/html/cacti/scripts/dircount /tmp/spam
/usr/local/rrdtool-1.0.40/bin/rrdtool update /var/www/html/cacti/rra/cgate_blocked_email.rrd --template spam N:1234
If it's a "U":
Look at the top line. This shows what cacti is executing in order to gather the number.
Run that from the command line. Does it print a number, no carriage return, and nothing else? If you followed my example, that script should be executable.
Check permissions. Can the user that's running the cronjob read the directory it's supposed to count? Can that user write to the <path_cacti>/rrd/ directory?
Double check all entries in the Data Input and Data Sources to make sure you didn't mispell anything.
Still doesn't work? Start over! Run through the steps in the tutorial again with new names and descriptions. Make sure you didn't miss anything, and give it time to gather data.
If it still doesn't work, post to the forums and ask specific questions. Let the forum readers know that the system is not collecting data and cut and paste the two lines in the "Edit Data" screen of your data source, and also the line from the top of the data source itself.
To increase the likelihood of a response, include the file and directory permissions of the relevant places. (for this example, /tmp/spam/, <path_cacti>/scripts/dircount, and <path_cacti>/rrd/) (We don't need to see every file, just the particular permissions). Also, check <path_cacti>/log/rrd.log for any relevant information.
Okay, it's collecting data, but my graph still doesn't render.
I'm not really qualified to write this section.
Information to include:
The output from "Turn Graph Output Preview ON" in the 'Edit Graph Items' screen.
The relevant graph and data source settings.
thnx !
hi fred,
this sounds great, i´ll try that and give a feddback as soon as possible!..
regards !
this sounds great, i´ll try that and give a feddback as soon as possible!..
regards !
Who is online
Users browsing this forum: No registered users and 1 guest