Collecting OS X metrics with Glances and Influxdb

By   07-17-2016 · 2 minute read · 399 words


Mac OS X CPU usage

I spent some time playing with Influxdb and Grafana and found out that the OS metrics tool Glances can directly import stats directly into Influxdb. This is cool because it will save us a ton of time in writing our own metric collection agents.

As a test, I decided to send all my Macbook metrics to Influxdb and see Grafana would display.

To do this I had to make sure that Glances was installed. I couldn’t install it directly from brew so I had to ensure python was installed and installed via pip.

brew install python
pip install glances

From there you need to locate the glances.conf file and edit the Influxdb configuration section.

On my system I located it under:

/usr/local/share/doc/glances/glances.conf

But this might differ from system to system. Edit the influxdb configuration block that looks like this:

[influxdb]
# Configuration for the --export-influxdb option
# https://influxdb.com/
host=localhost
port=8086
user=root
password=root
db=glances
prefix=localhost
#tags=foo:bar,spam:eggs

to point to your Influxdb server.

[influxdb]
# Configuration for the --export-influxdb option
# https://influxdb.com/
host=influx.local
port=8086
user=
password=
db=glances
prefix=macbook
#tags=foo:bar,spam:eggs

On the Influxdb server ensure that the glances database exists. You can use the influx cli tool to create the database or a curl post.

Then attempt to start it with:

Glances --export-influxdb

Of course it wouldn’t work on the first try…

$ Glances --export-influxdb
Traceback (most recent call last):
  File "/usr/local/bin/Glances", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/site-packages/glances/__init__.py", line 130, in main
    args=core.get_args())
  File "/usr/local/lib/python2.7/site-packages/glances/standalone.py", line 41, in __init__
    self.stats = GlancesStats(config=config, args=args)
  File "/usr/local/lib/python2.7/site-packages/glances/stats.py", line 43, in __init__
    self.load_plugins_and_exports(self.args)
  File "/usr/local/lib/python2.7/site-packages/glances/stats.py", line 80, in load_plugins_and_exports
    self.load_exports(args=args)
  File "/usr/local/lib/python2.7/site-packages/glances/stats.py", line 123, in load_exports
    export_module = __import__(os.path.basename(item)[:-3])
  File "/usr/local/lib/python2.7/site-packages/glances/exports/glances_influxdb.py", line 28, in <module>
    from influxdb import InfluxDBClient
ImportError: No module named influxdb:

Well then we need to install the influxdb module right?

pip install influxdb

Worked, but now I got this new error:

[email protected] ~ $ Glances --export-influxdb
No InfluxDB configuration found

Why? So difficult!

Turns out you’ll need to copy /usr/local/share/doc/glances/glances.conf into /usr/local/etc/glances/glances.conf… The glances directory does not exist by default, so you’ll also need to create that.

I just created a glances.conf with the Influxdb configuration block and it started working. You can validate on the influx side by listing the series.

Once you get everything configured, give glances some time to feed some stats to Influxdb and you should be able to get some useful stats graphed through Grafana.

influxdb   metrics  

comments powered by Disqus