Last active
November 23, 2017 14:56
-
-
Save bborysenko/c4c83702ccaae285135c8ed2617203f2 to your computer and use it in GitHub Desktop.
Install node_exporter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # curl -fsSL https://gist.githubusercontent.com/bborysenko/c4c83702ccaae285135c8ed2617203f2/raw/node_exporter_install_el6.sh -o node_exporter_install_el6.sh | |
| # bash node_exporter_install_el6.sh | |
| wget https://github.com/prometheus/node_exporter/releases/download/v0.15.0/node_exporter-0.15.0.linux-amd64.tar.gz | |
| tar -xzvf node_exporter-0.15.0.linux-amd64.tar.gz | |
| mv node_exporter-0.15.0.linux-amd64/node_exporter /usr/bin/node_exporter | |
| rm -rf node_exporter-0.15.0.linux-amd64 node_exporter-0.15.0.linux-amd64.tar.gz | |
| mkdir /var/log/prometheus/ /var/run/prometheus | |
| yum install -y daemonize | |
| cat > /etc/init.d/node_exporter << EOL | |
| #!/bin/bash | |
| # | |
| # /etc/rc.d/init.d/node_exporter | |
| # | |
| # chkconfig: 2345 80 80 | |
| # | |
| # config: /etc/prometheus/node_exporter.conf | |
| # pidfile: /var/run/prometheus/node_exporter.pid | |
| # Source function library. | |
| . /etc/init.d/functions | |
| RETVAL=0 | |
| PROG="node_exporter" | |
| DAEMON_SYSCONFIG=/etc/sysconfig/\${PROG} | |
| DAEMON=/usr/bin/\${PROG} | |
| PID_FILE=/var/run/prometheus/\${PROG}.pid | |
| LOCK_FILE=/var/lock/subsys/\${PROG} | |
| LOG_FILE=/var/log/prometheus/node_exporter.log | |
| DAEMON_USER="prometheus" | |
| DAEMON_USER="root" | |
| FQDN=\$(hostname --long) | |
| GOMAXPROCS=\$(grep -c ^processor /proc/cpuinfo) | |
| . \${DAEMON_SYSCONFIG} | |
| start() { | |
| if check_status > /dev/null; then | |
| echo "node_exporter is already running" | |
| exit 0 | |
| fi | |
| echo -n $"Starting node_exporter: " | |
| daemonize -u \${DAEMON_USER} -p \${PID_FILE} -l \${LOCK_FILE} -a -e \${LOG_FILE} -o \${LOG_FILE} \${DAEMON} \${ARGS} | |
| RETVAL=\$? | |
| echo "" | |
| return \$RETVAL | |
| } | |
| stop() { | |
| echo -n $"Stopping node_exporter: " | |
| killproc -p \${PID_FILE} -d 10 \${DAEMON} | |
| RETVAL=\$? | |
| echo | |
| [ \$RETVAL = 0 ] && rm -f \${LOCK_FILE} \${PID_FILE} | |
| return \$RETVAL | |
| } | |
| check_status() { | |
| status -p \${PID_FILE} \${DAEMON} | |
| RETVAL=\$? | |
| return \$RETVAL | |
| } | |
| case "\$1" in | |
| start) | |
| start | |
| ;; | |
| stop) | |
| stop | |
| ;; | |
| status) | |
| check_status | |
| ;; | |
| reload|force-reload) | |
| reload | |
| ;; | |
| restart) | |
| stop | |
| start | |
| ;; | |
| *) | |
| N=/etc/init.d/\${NAME} | |
| echo "Usage: \$N {start|stop|status|restart|force-reload}" >&2 | |
| RETVAL=2 | |
| ;; | |
| esac | |
| exit \${RETVAL} | |
| EOL | |
| chmod +x /etc/init.d/node_exporter | |
| chkconfig --add node_exporter | |
| chkconfig node_exporter on | |
| cat > /etc/sysconfig/node_exporter << EOL | |
| ARGS="" | |
| EOL | |
| service node_exporter start | |
| sleep 5 | |
| curl -sS -f -o /dev/null 127.0.0.1:9100/metrics |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment