Molet

运维监控系统之Prometheus redis监控

Molet 运维技术 2022-11-20 494浏览 0

简介

redis_exporter就是为了收集redis服务指标的应用。

运维监控系统之Prometheus redis监控

下载运行

wget-c-t100https://github.com/oliver006/redis_exporter/releases/download/v1.15.0/redis_exporter-v1.15.0.linux-amd64.tar.gz

tarzxvfredis_exporter-v1.15.0.linux-amd64.tar.gz

cdredis_exporter-v1.15.0.linux-amd64

./redis_exporter

INFO[0000]RedisMetricsExporterv1.15.0builddate:2020-12-27-18:57:05sha1:43ec65f7a22041e64ec557291c36500d04c6f6b0Go:go1.15.6GOOS:linuxGOARCH:amd64
INFO[0000]Providingmetricsat:9121/metrics

默认端口是9121,默认链接是redis://localhost:6379

运维监控系统之Prometheus redis监控

如果设置了密码,就需要在执行的时候,指定密码

./redis_exporter-redis.addr'redis://localhost:6379'-redis.passwordredispassword

查看更多参数

./redis_exporter-h

Usageof./redis_exporter:
-check-key-groupsstring
Commaseparatedlistofluaregexforgroupingkeys
-check-key-groups-batch-sizeint
CheckkeygroupsbatchsizehintfortheunderlyingSCAN(default10000)
-check-keysstring
Commaseparatedlistofkey-patternstoexportvalueandlength/size,searchedforwithSCAN
-check-single-keysstring
Commaseparatedlistofsinglekeystoexportvalueandlength/size
-check-single-streamsstring
Commaseparatedlistofsinglestreamstoexportinfoaboutstreams,groupsandconsumers
-check-streamsstring
Commaseparatedlistofstream-patternstoexportinfoaboutstreams,groupsandconsumers,searchedforwithSCAN
-config-commandstring
WhattousefortheCONFIGcommand(default"CONFIG")
-connection-timeoutstring
TimeoutforconnectiontoRedisinstance(default"15s")
-count-keysstring
Commaseparatedlistofpatternstocount,eg:'db3=sessions:*'.Warning:TheexporterrunsSCANtocountthekeys.
-debug
Outputverbosedebuginformation
-export-client-list
WhethertoscrapeClientListspecificmetrics
-export-client-port
Whethertoincludetheclient'sportwhenexportingtheclientlist.Warning:includingtheportincreasesthenumberofmetricsgeneratedandwillmakeyourPrometheusservertakeupmorememory
-include-system-metrics
Whethertoincludesystemmetricslikee.g.redis_total_system_memory_bytes
-is-tile38
WhethertoscrapeTile38specificmetrics
-log-formatstring
Logformat,validoptionsaretxtandjson(default"txt")
-max-distinct-key-groupsint
Themaximumnumberofdistinctkeygroupswiththemostmemoryutilizationtopresentasdistinctmetricsperdatabase,theleftoverkeygroupswillbeaggregatedinthe'overflow'bucket(default100)
-namespacestring
Namespaceformetrics(default"redis")
-ping-on-connect
Whethertopingtheredisinstanceafterconnecting
-redis-only-metrics
Whethertoalsoexportgoruntimemetrics
-redis.addrstring
AddressoftheRedisinstancetoscrape(default"redis://localhost:6379")
-redis.passwordstring
PasswordoftheRedisinstancetoscrape
-redis.userstring
Usernametouseforauthentication(RedisACLforRedis6.0andnewer)
-scriptstring
PathtoLuaRedisscriptforcollectingextrametrics
-set-client-name
Whethertosetclientnametoredis_exporter(defaulttrue)
-skip-tls-verification
WhethertotoskipTLSverification
-tls-ca-cert-filestring
NameoftheCAcertificatefile(includingfullpath)iftheserverrequiresTLSclientauthentication
-tls-client-cert-filestring
Nameoftheclientcertificatefile(includingfullpath)iftheserverrequiresTLSclientauthentication
-tls-client-key-filestring
Nameoftheclientkeyfile(includingfullpath)iftheserverrequiresTLSclientauthentication
-tls-server-cert-filestring
Nameoftheservercertificatefile(includingfullpath)ifthewebinterfaceandtelemetryshoulduseTLS
-tls-server-key-filestring
Nameoftheserverkeyfile(includingfullpath)ifthewebinterfaceandtelemetryshoulduseTLS
-version
Showversioninformationandexit
-web.listen-addressstring
Addresstolistenonforwebinterfaceandtelemetry.(default":9121")
-web.telemetry-pathstring
Pathunderwhichtoexposemetrics.(default"/metrics")

部署脚本

运维监控系统之Prometheus redis监控

#!/bin/bash

VERSION="1.15.0"

wget-t100-chttps://github.com/oliver006/redis_exporter/releases/download/v${VERSION}/redis_exporter-${VERSION}.linux-amd64.tar.gz

if[!-eredis_exporter-${VERSION}.linux-amd64.tar.gz]
then
echo"安装包下载失败"
exit1
fi
tarxvfzredis_exporter-${VERSION}.linux-amd64.tar.gz-C/opt/
cd/opt
ln-sredis_exporter-${VERSION}.linux-amd64redis_exporter
cat>/etc/systemd/system/redis_exporter.service<<EOF

[Unit]
Description=redis_exporter
After=network.target

[Service]
Type=simple
WorkingDirectory=/opt/redis_exporter
ExecStart=/opt/redis_exporter/redis_exporter-redis.addrredis://localhost:6379-redis.passwordredispassword
LimitNOFILE=65536
PrivateTmp=true
RestartSec=2
StartLimitInterval=0
Restart=always

[Install]
WantedBy=multi-user.target
EOF


systemctldaemon-reload

systemctlenableredis_exporter
systemctlstartredis_exporter

prometheus配置

添加下面的job

-job_name:'redis'

#metrics_pathdefaultsto'/metrics'
#schemedefaultsto'http'.

static_configs:
-targets:['localhost:9121']

配置好以后,reload一下prometheus就可以加载

kill-HUP[promethues_pid]

指标展示

指标可以通过prometheus的WebUI进行查看

http://[prometheserverip]:9090

如果需要画图,可以直接使用grafana,有人已经配置好了图形可以通过grafana官方下的dashboard搜索redis_exporter,配置好prometheus数据源,直接导入grafana就可以直接展示了。

运维监控系统之Prometheus redis监控

继续浏览有关 Redis 的文章
发表评论