baxic-command-exporter.0.1.0.linux-noarch/0000755002342000234200000000000014043323064017420 5ustar baxicbaxicbaxic-command-exporter.0.1.0.linux-noarch/RELEASE-NOTES0000644002342000234200000000004414043074016021307 0ustar baxicbaxic0.1.0 - Initial version released. baxic-command-exporter.0.1.0.linux-noarch/AUTHOR0000644002342000234200000000005114043074016020341 0ustar baxicbaxicLukas Baxa alias Baxic baxic-command-exporter.0.1.0.linux-noarch/baxic-command-exporter.conf0000644002342000234200000000024214043074016024635 0ustar baxicbaxic COMMAND[0]='users:who | wc -l' COMMAND[1]='total_processes:ps -e --no-headers | wc -l' COMMAND[2]='zombie_processes:ps -eo stat --no-headers | grep ^Z | wc -l' baxic-command-exporter.0.1.0.linux-noarch/baxic-command-exporter.sh0000755002342000234200000000245714043074016024337 0ustar baxicbaxic#!/bin/bash PROGNAME='baxic-command-exporter.sh' CONFFILE="/opt/prometheus-apps/${PROGNAME%.sh}/${PROGNAME%.sh}.conf" export PROGNAME CONFFILE # read_config_file # read configuration file read_config_file() { unset COMMAND if [[ ! -f "$CONFFILE" || ! -r "$CONFFILE" ]]; then echo "$PROGNAME: configuration file '$CONFFILE' not found" exit 2 fi . "$CONFFILE" } read_config_file # get_metrics # get all metrics, i.e. run all commands get_metrics() { local httpget local commconf metric comm value local metrics metrics_len read httpget metrics="$(for commconf in "${COMMAND[@]}"; do metric="$(echo "$commconf" | cut -d: -f1)" comm="$(echo "$commconf" | cut -d: -f2-)" value="$(bash -c "$comm" | head -1)" echo "$value" | grep -Eq '^[[:digit:]]+$' || continue [[ "${value:0:1}" = '0' && "$value" != '0' ]] && continue echo "$metric" "$value" done)" metrics_len="$(echo "$metrics" | wc -c)" echo 'HTTP/1.1 200 OK' echo "Content-Length: $metrics_len" echo 'Content-Type: text/plain' echo "Date: $(date -R -u | sed -r 's#\+0000$#GMT#')" echo echo "$metrics" return 0 } export -f get_metrics export -f read_config_file # periodically return metrics when requested ncat -k -l 9088 -c 'read_config_file && get_metrics' # exit exit 0 baxic-command-exporter.0.1.0.linux-noarch/baxic-command-exporter.service0000644002342000234200000000050414043074016025351 0ustar baxicbaxic[Unit] Description=Baxic Command Exporter Service After=network.target iptables.service firewalld.service ip6tables.service ipset.service [Service] Type=simple ExecStart=/opt/prometheus-apps/baxic-command-exporter/baxic-command-exporter.sh User=nobody Group=nogroup Restart=on-failure [Install] WantedBy=multi-user.target baxic-command-exporter.0.1.0.linux-noarch/LICENSE0000644002342000234200000000033114043074016020422 0ustar baxicbaxicThis is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version. baxic-command-exporter.0.1.0.linux-noarch/README0000644002342000234200000000500314043321631020274 0ustar baxicbaxic ---- Introduction Baxic Command Exporter is a Prometheus Exporter used to collect metrics from a monitored host using any commands configured in the configuration file, e.g. in a similar way like the NRPE agent for Nagios or Icinga. It's written in Bash and uses the ncat command to listen on TCP port 9088. See online Wiki for more information: https://baxic.org/index.php/wikipedia/article/linux/monitoring/prometheus/exporters/baxic-command-exporter ---- Prerequisities The ncat tool must be present on the system. Moreover, /bih/sh must be a symlink to /bin/bash otherwise the function export doesn't work properly (note the export -f ... commands in the script). ---- Installation # switch to root user mkdir -p /opt/prometheus-apps cd /opt/prometheus-apps # either clone a git repository git clone git://github.com/baxic-cz/baxic-command-exporter.git # or extract the tgz archive tar -xzf baxic-command-exporter*.tgz ln -s baxic-command-exporter.*.linux-noarch baxic-command-exporter cd baxic-command-exporter # check file permissions chmod a+x *.sh ls -l # configure metrics in baxic-command-exporter.conf, an example configuration follows, # each entry in the COMMAND array consists of two fields separated by a colon, # the metric name and the command with optional arguments cat baxic-command-exporter.conf COMMAND[0]='users:who | wc -l' COMMAND[1]='total_processes:ps -e --no-headers | wc -l' COMMAND[2]='zombie_processes:ps -eo stat --no-headers | grep ^Z | wc -l' # define the exporter as a systemd service if required cp baxic-command-expoter.service /etc/systemd/system systemctl daemon-reload systemctl enable baxic-command-exporter.service ---- Running The script should be run under the user with appropriate permissions to invoke the configured commands. However, it's strongly recommended to run it under non-privileged user. If you need to elevate permissions, consider using sudo, for instance. To start the service under the pre-configured nobody:nogroup user:group, run: systemctl start baxic-command-exporter.service Or if you want to run/test it just as a CLI command, run under the required user account: /opt/prometheus-apps/baxic-command-exporter/baxic-command-exporter.sh ---- Test functionality The returned metrics can be checked from a web-browser or from a command-line, e.g. using curl: curl -i http://localhost:9088 ---- Summary The exporter is up and running now. You should consider protecting access to it on your firewall. You can now collect its metrics in a standard way using Prometheus.