Salt Formula for monitoring USBs
This salt formula uses Grok Exporter (https://github.com/fstab/grok_exporter) and the Linux command usb-devices to export connected USBs devices as metrics to be monitored using Prometheus and Grafana. Beyond that, the formula is implemented to be used with SUSE Manager to be applied directly into the salt-minions through the web interface.
-
First you need to download the latest release of Grok Exporter, extract it, and create the following config file, config_usb_devices.yml, (inside the /examples directory):
global: config_version: 3 input: type: file #stdin not working yet path: /etc/grok-exporter/grok_exporter-1.0.0.RC3.linux-amd64/example/usb_devices.log #path to the log file to be monitored readall: true grok_patterns: - 'DEVICE [^=]*$' metrics: - type: counter name: dispositivos_usb_conectados help: Exibe se um dispositivo USB está conectado ou não match: '%{DEVICE:device}' cumulative: false labels: dispositivo: '{{.device}}' server: protocol: http port: 9144
-
Then, create an .tar of the grok exporter directory
tar cfv grok_exporter-1.0.0.tar grok_exporter-1.0.0.RC3.linux-amd64/
and export it to the Salt master (in my case it's a SUSE Manager server). -
In the salt master server:
cd /srv/salt
-
mkdir grok-exporter
andcd grok-exporter/
-
Create the salt formula:
vim init.sls
with the following content from init.sls. -
mkdir /files
inside the grok-exporter directory andmv {grok-exporter}.tar
created in step 2 to this directory. -
This step contains the needed metadata for using the graphical web interface of SUSE Manager, so if you are just using a common salt-master you don´t need to repeat these next steps.
cd /srv/formula_metada mkdir grok-exporter
mv
the files from here to the created directory. -
spacewalk-service restart
and you should be able to apply the created formula to any minion. After the formula is applied the minion should be exposing metrics about the connected USB-devices in the default port :9144/metrics. -
After this you should configure your Prometheus instance do scrape those metrics and your Grafana instance to plot them.