I'm having difficulty configuring collectd.conf
using the interface
plugin through salt
. The collectd.conf
expects a list of network interfaces to monitor like:
<Plugin interface>
Interface "em1"
Interface "em2"
</Plugin>
I've worked out that I need to use a salt mine
to pull the grains into the master - which is achieved through a pillar sls like the following:
mine_functions:
network.interfaces: []
and in my collectd.conf
I have:
<Plugin interface>
{% for host, info in salt['mine.get']('*','network.interfaces').items() %}
{% if host == grains['id'] %}
{% for interface in info %}
Interface "{{ interface }}"
{% endfor %}
{% endif %}
{% endif %}
{% endfor %}
</Plugin>
However, it doesn't appear to work for me :(
If you're looking for interfaces on the local host (which I gather you are since you're filtering on grains['id']) then you don't need mine for this. You can get the interface names on the local host from grains:
If you want a list of the local machine's addresses instead of interface names, you can loop over grains['ipv4'] instead. No
.keys()
; that grain is a simple list.If you need interface information for other hosts, then you use mine. Note that network.interfaces returns a nested dictionary, which may be why it's not working for you -- you are looping over it as if it were a list, which (at least when I tested it just now) produces an unreadable mess.
To get interface names from other servers, you would actually use something more like:
Which should output:
This is sort of what you asked but doesn't seem like what you're actually trying to do.