promeheus监控redis
Posted fatyao
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了promeheus监控redis相关的知识,希望对你有一定的参考价值。
Grafana+Prometheus系统监控之Redis
请先安装go语言环境
(promeheus+grafana环境已经部署好了,具体参考前天的文档)
tar -zxvf go1.12.4.linux-amd64.tar.gz -C /usr/local
然后修改环境
vim /etc/profile.d/go.sh
export GOPATH=/usr/local/go
export PATH=$PATH:$GOPATH/bin
同步刷新环境
source /etc/profile.d/go.sh
下载并解压缩插件
unzip redis_exporter-master.zip
mv redis_exporter-master /usr/local/redis_exporter
cd redis_exporter
go build
然后会产生于一个命令文件:redis_exporter
这个命令使用方式
## 无密码
./redis_exporter redis//192.168.33.131:6379 &
## 有密码
redis_exporter -redis.addr 192.168.33.131:6379 -redis.password 123456
我们把这个命令cp到bin目录中,方便使用
cp redis_exporter /usr/local/bin/
---------------------------为了方便维护,我们写个脚本-------------------------------
先写个脚本,如下
[[email protected] redis_exporter]# cat redis_export.sh
#!/bin/bash
IP=`ip addr | grep -v virbr |grep -o -e ‘inet [0-9]\\1,3\\.[0-9]\\1,3\\.[0-9]\\1,3\\.[0-9]\\1,3\\‘|grep -v "127.0.0"|awk ‘print $2‘`
PORT=6379
COMMAND=/usr/local/bin/redis_exporter
#PIDNUM=`ps -ef | grep redis_exporter | grep -v grep | awk -F ‘ ‘ ‘print $2‘`
# if no password
#redis_exporter redis//$IP:$PORT &
# if have password,don‘t need string<>
#redis_exporter redis//$IP:$PORT & -redis.password <your redis‘s password>
start()
PIDNUM=`ps -ef | grep redis_exporter | grep -v grep | awk -F ‘ ‘ ‘print $2‘`
if [ -z $PIDNUM ];then
$COMMAND -redis.addr $IP:$PORT &
else
echo "$0 is running"
fi
stop()
PIDNUM=`ps -ef | grep redis_exporter | grep -v grep | awk -F ‘ ‘ ‘print $2‘`
if [ -z $PIDNUM ];then
echo "$0 is not running"
else
echo "shutting down $0"
kill -9 "$PIDNUM" && echo "PID $PIDNUM was killed."
fi
status()
PIDNUM=`ps -ef | grep redis_exporter | grep -v grep | awk -F ‘ ‘ ‘print $2‘`
if [ -z $PIDNUM ];then
echo "$0 is not runing"
else
echo "$0 is runing,it‘s PID is $PIDNUM"
fi
case $1 in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
stop
start
;;
*)
echo "Usage:$0 start|stop|status|restart"
;;
esac
------------------------------------------------------------------------------
修改配置文件prometheus.yml
如下:
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global ‘evaluation_interval‘.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it‘s Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: ‘prometheus‘
# metrics_path defaults to ‘/metrics‘
# scheme defaults to ‘http‘.
scrape_interval: 10s
static_configs:
- targets: [‘192.168.2.210:9090‘]
labels:
instance: prometheus
- job_name: ‘centos7-machine1‘
scrape_interval: 10s
static_configs:
- targets: [‘192.168.2.210:9100‘]
labels:
instance: centos7-machine1
- job_name: ‘centos7-machine2‘
scrape_interval: 10s
static_configs:
- targets: [‘192.168.2.211:9100‘]
labels:
instance: centos7-machine2
- job_name: ‘centos7-machine3‘
scrape_interval: 10s
static_configs:
- targets: [‘192.168.2.212:9100‘]
labels:
instance: centos7-machine3
- job_name: ‘centos7-machine4‘
scrape_interval: 10s
static_configs:
- targets: [‘192.168.2.213:9100‘]
labels:
instance: centos7-machine4
- job_name: ‘win2016-machine5‘
scrape_interval: 10s
static_configs:
- targets: [‘192.168.2.214:9182‘]
labels:
instance: win2016-machine5
- job_name: ‘redis_1‘
scrape_interval: 10s
static_configs:
- targets: [‘192.168.2.211:9121‘]
labels:
instance: 192.168.2.211
- job_name: ‘redis_2‘
scrape_interval: 10s
static_configs:
- targets: [‘192.168.2.212:9121‘]
labels:
instance: 192.168.2.212
- job_name: ‘redis_3‘
scrape_interval: 10s
static_configs:
- targets: [‘192.168.2.213:9121‘]
labels:
instance: 192.168.2.213
设置用户(prometheus用户再前面的环境部署中已经添加过了)
chown -R prometheus:prometheus /usr/local/redis_exporter/
cp /usr/local/redis_exporter/redis_export.sh /etc/init.d/redis_exporter
service redis_export start
以上是关于promeheus监控redis的主要内容,如果未能解决你的问题,请参考以下文章