Graph Any Data with Cacti!

Once there, look along the left-hand side of the "console" page (Figure 3), which should load by default. The confusing part is that names like "devices", "data sources", "data queries" and such all sound like what you want to configure to get data. I'm listing the definitions below, so hopefully it's less confusing:

  • Data Queries: this generally refers to SNMP queries used to get data. I'm not using this here, even though it sounds like something I'd need to configure for doing data queries to a bash script.

  • Data Input Methods: this is where you'll configure your bash script if you're following along. Cacti sees the script as a way to get data, not the data itself. This means you can use the script (or Data Input Method) for multiple data sources. In my case, I use the same Data Input Method for both Petoskey temps and Houston temps.

  • Devices: Cacti allows you to categorize data by device. This makes sense if you're going to monitor server data from a bunch of different servers. In this case, I'm not graphing different devices, so I won't use the device categorization at all (I'll use "none" as the device).

  • Data Sources: a data source uses a "Data Input Method" to create a graphable piece of data. For this example, I have two data sources: the Petoskey temp and the Houston temp.

  • Data Templates: this is a template that instructs Cacti on how to use a Data Input Method to create a Data Source. Basically, you set up a Data Template so Cacti knows what questions to ask when creating a Data Source. It's possible to do without a Data Template, but if you don't set one up, Cacti will give errors when creating a Data Source that you'll need to go back and fix later. It's a real pain, but the step to create a Data Template makes the process far less painful.

Figure 3. Don't be overwhelmed; it's not nearly as scary as it looks.

Hopefully, that clears up some of the strange terminology. Graphing is actually separate, so first you need to get your Data Sources configured. (You'll make the graphs from your data sources, once they're storing periodic data.)

Part I: Data Input Method

For this example, even though I have two data sources, I have only one Data Input Method. That means I need to configure the script in Cacti so that it will accept an argument (the weather station code) for each data source. So to do this, first click on "Data Input Methods" on the left, and then click "add" on the upper-right corner of the Data Input Methods page. Look at Figure 4 to see where the "add" link is, because it took me a long time to find it at first!

Figure 4. It took me forever to figure out how to add something. I felt very silly.

This is where you create the criteria for Cacti to "call" your script. Figure 5 shows how to set up the information. Note that you must use the "Script/Command" Input Type and that the placeholder for the argument goes in < > brackets. The name of the Data Input Method is just a friendly name, and the command-line argument in brackets gets a friendly name too. (Also note that Cacti refers to the command-line argument as an "input source", which isn't terribly descriptive in the case of a bash script.) Once filled in, click Create at the bottom.

Figure 5. Be sure to select Script/Command!

The next page (Figure 6) looks similar, but you'll see that there are now two more sections you need to complete. The first is the Input Fields section. Click Add in the upper-right corner of that section, and then tell the system what the script expects as input. In Figure 7, you can see the Input Field from the last step is already selected. My example script has only one argument, so it's the only option to choose. (Notice the name is the same that I put in <brackets> in the last step.)

Figure 6. You need to configure an Input Field and an Output Field.

Figure 7. These error-checking features will come in handy for some scripts.

______________________

Shawn Powers is a Linux Journal Associate Editor. You might find him on IRC, Twitter, or training IT pros at CBT Nuggets.