[root@bogon opt]# cd /opt
[root@bogon opt]# wget https://github.com/prometheus/node_exporter/releases/download/v1.1.2/node_exporter-1.1.2.linux-amd64.tar.gz
[root@bogon opt]# tar xvf node_exporter-1.1.2.linux-amd64.tar.gz
[root@bogon opt]# ln -s node_exporter-1.1.2.linux-amd64 node_exporter
cat > /usr/lib/systemd/system/node_exporter.service <<EOF
[Unit]
Description=node_exporter
Documentation=
After=network.target
[Service]
Type=simple
WorkingDirectory=/opt/node_exporter
ExecStart=/opt/node_exporter/node_exporter --collector.textfile.directory=/opt/node_exporter/key
ExecStop=/bin/kill -KILL \$MAINPID
ExecReload=/bin/kill -HUP \$MAINPID
KillMode=control-group
Restart=on-failure
RestartSec=3s
[Install]
WantedBy=multi-user.target
EOF
cat /opt/exporter/node_exporter/key/key_runner
#! /bin/bash
echo Logical_CPU_core_total `cat /proc/cpuinfo| grep "processor"| wc -l`
echo logined_users_total `who | wc -l`;
echo procs_total `ps aux|wc -l`
echo procs_zombie `ps axo pid=,stat=|grep Z|wc -l`
bash key_runner
Logical_CPU_core_total 2
logined_users_total 1
procs_total 148
procs_zombie 0
* * * * * bash /opt/node_exporter/key/key_runner > /opt/node_exporter/key/key.prom
#验证
curl 127.0.0.1:9100/metrics|grep -E logined_users_total
可以在指标前面加上备注以及指标的基本类型
echo "# HELP Logical_CPU_core_total 查看当前cpu的核"
echo "# TYPE Logical_CPU_core_total gauge"