8

(See bottom for updates...)

I've written a data input method script for Cacti (in Ruby, to collects stats from beanstalkd) and it works from the command line (returning a single simple integer, as documented here) when run as the cacti user account but the Cacti tool itself isn't harvesting any data and there's nothing in the logs.

Here's the Data Input Methods set-up: Cacti Data Input Method http://img.skitch.com/20091009-gh7g1kukn9yradj6y2iqrd5qm1.jpg

And here's the resulting Graph (after it's been added to a host's chart template and left to run long enough to gather data): Cacti Graph http://img.skitch.com/20091009-xq1kn3qxkteb5hb11wtx6tbs8m.jpg

Update #1: Looks like Cacti might be stripping the environment:

sudo su - cacti -c 'env -i /script/beanstat --host 10.11.12.13 --port 11300 --stat current-waiting'
/script/beanstat:4:in `require': no such file to load -- rubygems (LoadError)
    from /script/beanstat:4

If that's the case, how might I work around it?

Update #2: This response on stackoverflow.com seems to have resolved the environment issue, but still no data in the chart.

Update #3: Thanks to @Heath's suggestion I bumped up the poller logging level and caught this:

WARNING: Result from CMD not valid.  Partial Result: U

Haven't had any luck Googling up what "Partial Result: U" means. The script just prints a single integer value.

Update #4: I did finally get this working. The core issue was the lack of environment when the shell script runs. I had to resolve that by prefixing my Ruby script with the following lines:

#!/bin/sh
PATH=/usr/local/bin:$PATH
exec ruby -x"/full/path/to/script/directory" $0 "$@"
#!/usr/bin/env ruby

And the secondary issue was the proper configuration of the Data Input Methods (one for each separate metric I wanted to collect, even though they all used the same script) which feeds the Data Sources which feeds the Data Templates (or vice versa, I'm still not clear on that) which feeds the Graph Templates which need to be assigned to the Devices then added to the Graph Trees. In summary, it's a major debacle with crap for documentation and I hope to never have to do it again.

Update #5: I've shared my script on GitHub http://github.com/trak3r/cacti-beanstalkd-script

Teflon Ted
  • 500
  • 2
  • 7
  • 18

1 Answers1

4

When I was trying to debug a custom script, I found it helpful to have the script append some information to a temp file every time it was run; that way I could make sure it was being called the way I expected. Things like the cmd line args, environment, and what value(s) it was going to return. You also might want to redirect stderr to a log file to catch error output from the script.

I see you made a Data Input Method and a Graph Template; did you also make a Data Template?

Heath
  • 1,240
  • 9
  • 4