$ wget https://github.com/wrouesnel/postgres_exporter/releases/download/v0.5.1/postgres_exporter_v0.5.1_linux-amd64.tar.gz
$ tar -xvf postgres_exporter_v0.5.1_linux-amd64.tar.gz
$ mv postgres_exporter_v0.5.1_linux-amd64 /usr/local/postgres_exporter
$ cd /usr/local/postgres_exporter
$ ./postgres_exporter --version
postgres_exporter v0.5.1 (built with go1.11)
$ export DATA_SOURCE_NAME="postgresql://DB_USER_NAME:PASSWORD@DB_HOST:DB_PORT/DB_NAME?sslmode=disable"
将上面的DB_USER_NAME:PASSWORD,DB_HOST:DB_PORT改成自己的用户、密码、主机ip及端口,DB_NAME可以用postgresql,也可以写到/etc/profile中,永久生效。
例:
$ export DATA_SOURCE_NAME="postgresql://test:[email protected]:5432/test?sslmode=disable"
$ vim /lib/systemd/system/postgres_exporter.service
[Unit]
Description=postgres_exporter
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/postgres_exporter/postgres_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
$ systemctl daemon-reload
$ systemctl start postgres_exporter
$ systemctl status postgres_exporter
$ netstat -lnpt|grep 9187
用二进制文件安装时需要在每个被监控主机上声明变量,会暴露数据库的用户名及密码,不是很安全,所以还可以通过docker在监控端进行安装。
$ docker run -itd --name postgres_exporter -p 9187:9187 -e DATA_SOURCE_NAME="postgresql://test:test@localhost:5432/test?sslmode=disable" wrouesnel/postgres_exporter
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cca60b0eb684 wrouesnel/postgres_exporter "/postgres_exporter" 6 seconds ago Up 5 seconds 0.0.0.0:9187->9187/tcp postgres_exporter
或
$ netstat -lnpt|grep 9187
$ vim /usr/local/prometheus/prometheus.yml
- job_name: postgres:5432
static_configs:
- targets: ['127.0.0.1:9187']
labels:
instance: 'postgres:5432'
group: 'test'
$ cd /usr/local/prometheus
$ ./promtool check config prometheus.yml
$ systemctl reload prometheus
或
$ curl -X POST http://127.0.0.1:9090/-/reload (启用了--web.enable-lifecycle选项)
$ wget https://github.com/oliver006/redis_exporter/releases/download/v1.0.4/redis_exporter-v1.0.4.linux-amd64.tar.gz
$ tar -xvf redis_exporter-v1.0.4.linux-amd64.tar.gz
$ mv redis_exporter-v1.0.4.linux-amd64 /usr/local/redis_exporter
$ cd /usr/local/redis_exporter
$ ./redis_exporter --version
INFO[0000] Redis Metrics Exporter v1.0.4 build date: 2019-08-08-00:05:43 sha1: 863ddc928ba c938d3da5bbe32a59b479ca53837b Go: go1.12.7
$ vim /lib/systemd/system/redis_exporter.service
[Unit]
Description=redis_exporter
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/redis_exporter/redis_exporter -redis.addr redis://127.0.0.1:6379
Restart=on-failure
[Install]
WantedBy=multi-user.target
$ systemctl daemon-reload
$ systemctl start redis_exporter
$ systemctl status redis_exporter
$ netstat -lnpt|grep 9121
$ vim /usr/local/prometheus/prometheus.yml
- job_name: redis:6379
static_configs:
- targets: ['127.0.0.1:9121']
labels:
instance: 'redis:6379'
group: 'test'
$ cd /usr/local/prometheus
$ ./promtool check config prometheus.yml
$ systemctl reload prometheus
或
$ curl -X POST http://127.0.0.1:9090/-/reload (启用了--web.enable-lifecycle选项)
$ apt-get install golang
设置go环境变量
$ export GOROOT=/usr/lib/go
$ export GOBIN=$GOROOT/bin
$ export PATH=$PATH:$GOBIN
$ export GOPATH=$HOME/gopath
安装pika_exporter
$ go get github.com/pourer/pika_expoter
$ cd $GOPATH/src/github.com/pourer/pika_expoter
$ make
下载失败可以用git clone
$ git clone https://github.com/pourer/pika_exporter.git
编译完安装包在/root/gopath/src/github.com/pourer/pika_exporter/bin下
$ mkdir /usr/local/pika_exporter
$ mv /root/gopath/src/github.com/pourer/pika_exporter/bin/pika_exporter /usr/local/pika_exporter
$ cd /usr/local/pika_exporter
$ ./pika_exporter --version
INFO[0000] Pika Metrics Exporter master build date: 2019-08-21 10:32:55 UTC sha: f14ea39 go version: go1.10.4 linux/amd64
$ vim pika_hosts_file
127.0.0.1:9221
$ vim metrics_file.ini 将要监控的指标写在文件中
$ vim /lib/systemd/system/pika_exporter.service
[Unit]
Description=pika_exporter
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/pika_exporter/pika_exporter -pika.host-file /usr/local/pika_exporter/pika_hosts_file -web.listen-address 0.0.0.0:9121 -metrics-file /usr/local/pika_exporter/metrics_file.ini
Restart=on-failure
[Install]
WantedBy=multi-user.target
$ systemctl daemon-reload
$ systemctl start pika_exporter
$ systemctl status pika_exporter
$ netstat -lnpt|grep 9121
$ vim /usr/local/prometheus/prometheus.yml
- job_name: pika:9221
static_configs:
- targets: ['127.0.0.1:9121']
labels:
instance: 'pika:9221'
group: 'test'
$ cd /usr/local/prometheus
$ ./promtool check config prometheus.yml
$ systemctl reload prometheus
或
$ curl -X POST http://127.0.0.1:9090/-/reload (启用了--web.enable-lifecycle选项)
https://tpu.thinkpower.com.tw/tpu/articleDetails/1201
https://github.com/oliver006/redis_exporter
https://github.com/pourer/pika_exporter