运维监控系统之Prometheus redis监控

运维 系统运维 Redis
redis_exporter就是为了收集redis服务指标的应用。

 简介

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


下载运行

  1. wget -c -t 100 https://github.com/oliver006/redis_exporter/releases/download/v1.15.0/redis_exporter-v1.15.0.linux-amd64.tar.gz 
  2.  
  3. tar zxvf   redis_exporter-v1.15.0.linux-amd64.tar.gz 
  4.  
  5. cd redis_exporter-v1.15.0.linux-amd64 
  6.  
  7. ./redis_exporter 

  1. INFO[0000] Redis Metrics Exporter v1.15.0    build date: 2020-12-27-18:57:05    sha1: 43ec65f7a22041e64ec557291c36500d04c6f6b0    Go: go1.15.6    GOOS: linux    GOARCH: amd64  
  2. INFO[0000] Providing metrics at :9121/metrics   

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


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

  1. ./redis_exporter -redis.addr 'redis://localhost:6379'   -redis.password  redispassword 

查看更多参数

  1. ./redis_exporter -h 

  1. Usage of ./redis_exporter: 
  2.   -check-key-groups string 
  3.         Comma separated list of lua regex for grouping keys 
  4.   -check-key-groups-batch-size int 
  5.         Check key groups batch size hint for the underlying SCAN (default 10000) 
  6.   -check-keys string 
  7.         Comma separated list of key-patterns to export value and length/size, searched for with SCAN 
  8.   -check-single-keys string 
  9.         Comma separated list of single keys to export value and length/size 
  10.   -check-single-streams string 
  11.         Comma separated list of single streams to export info about streams, groups and consumers 
  12.   -check-streams string 
  13.         Comma separated list of stream-patterns to export info about streams, groups and consumers, searched for with SCAN 
  14.   -config-command string 
  15.         What to use for the CONFIG command (default "CONFIG"
  16.   -connection-timeout string 
  17.         Timeout for connection to Redis instance (default "15s"
  18.   -count-keys string 
  19.         Comma separated list of patterns to count, eg: 'db3=sessions:*'. Warning: The exporter runs SCAN to count the keys. 
  20.   -debug 
  21.         Output verbose debug information 
  22.   -export-client-list 
  23.         Whether to scrape Client List specific metrics 
  24.   -export-client-port 
  25.         Whether to include the client's port when exporting the client list. Warning: including the port increases the number of metrics generated and will make your Prometheus server take up more memory 
  26.   -include-system-metrics 
  27.         Whether to include system metrics like e.g. redis_total_system_memory_bytes 
  28.   -is-tile38 
  29.         Whether to scrape Tile38 specific metrics 
  30.   -log-format string 
  31.         Log format, valid options are txt and json (default "txt"
  32.   -max-distinct-key-groups int 
  33.         The maximum number of distinct key groups with the most memory utilization to present as distinct metrics per database, the leftover key groups will be aggregated in the 'overflow' bucket (default 100) 
  34.   -namespace string 
  35.         Namespace for metrics (default "redis"
  36.   -ping-on-connect 
  37.         Whether to ping the redis instance after connecting 
  38.   -redis-only-metrics 
  39.         Whether to also export go runtime metrics 
  40.   -redis.addr string 
  41.         Address of the Redis instance to scrape (default "redis://localhost:6379"
  42.   -redis.password string 
  43.         Password of the Redis instance to scrape 
  44.   -redis.user string 
  45.         User name to use for authentication (Redis ACL for Redis 6.0 and newer) 
  46.   -script string 
  47.         Path to Lua Redis script for collecting extra metrics 
  48.   -set-client-name 
  49.         Whether to set client name to redis_exporter (default true
  50.   -skip-tls-verification 
  51.         Whether to to skip TLS verification 
  52.   -tls-ca-cert-file string 
  53.         Name of the CA certificate file (including full path) if the server requires TLS client authentication 
  54.   -tls-client-cert-file string 
  55.         Name of the client certificate file (including full path) if the server requires TLS client authentication 
  56.   -tls-client-key-file string 
  57.         Name of the client key file (including full path) if the server requires TLS client authentication 
  58.   -tls-server-cert-file string 
  59.         Name of the server certificate file (including full path) if the web interface and telemetry should use TLS 
  60.   -tls-server-key-file string 
  61.         Name of the server key file (including full path) if the web interface and telemetry should use TLS 
  62.   -version 
  63.         Show version information and exit 
  64.   -web.listen-address string 
  65.         Address to listen on for web interface and telemetry. (default ":9121"
  66.   -web.telemetry-path string 
  67.         Path under which to expose metrics. (default "/metrics"

 部署脚本


  1. #!/bin/bash 
  2.  
  3. VERSION="1.15.0" 
  4.  
  5. wget  -t 100  -c  https://github.com/oliver006/redis_exporter/releases/download/v${VERSION}/redis_exporter-${VERSION}.linux-amd64.tar.gz 
  6.  
  7. if [ ! -e redis_exporter-${VERSION}.linux-amd64.tar.gz ] 
  8. then 
  9.     echo "安装包下载失败" 
  10.     exit 1 
  11. fi 
  12. tar xvfz redis_exporter-${VERSION}.linux-amd64.tar.gz -C /opt/ 
  13. cd /opt 
  14. ln -s redis_exporter-${VERSION}.linux-amd64  redis_exporter 
  15. cat > /etc/systemd/system/redis_exporter.service <<EOF 
  16.  
  17. [Unit] 
  18. Description=redis_exporter 
  19. After=network.target 
  20.  
  21. [Service] 
  22. Type=simple 
  23. WorkingDirectory=/opt/redis_exporter 
  24. ExecStart=/opt/redis_exporter/redis_exporter -redis.addr redis://localhost:6379   -redis.password  redispassword 
  25. LimitNOFILE=65536 
  26. PrivateTmp=true 
  27. RestartSec=2 
  28. StartLimitInterval=0 
  29. Restart=always 
  30.  
  31. [Install] 
  32. WantedBy=multi-user.target 
  33. EOF 
  34.  
  35.  
  36. systemctl daemon-reload 
  37.  
  38. systemctl enable redis_exporter 
  39. systemctl start redis_exporter 

 prometheus配置

添加下面的job

  1. - job_name: 'redis' 
  2.  
  3.    # metrics_path defaults to '/metrics' 
  4.    # scheme defaults to 'http'
  5.  
  6.    static_configs: 
  7.    - targets: ['localhost:9121'

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

  1. kill -HUP [promethues_pid] 

指标展示

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

  1. http://[promethe server ip]:9090 

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


 

责任编辑:姜华 来源: 今日头条
相关推荐

2020-12-29 10:45:22

运维Prometheus-监控

2020-12-28 10:13:32

运维Prometheus监控

2021-07-07 05:46:46

运维监控Prometheus

2020-12-17 09:25:46

运维Prometheus监控

2020-12-30 05:34:25

监控PrometheusGrafana

2022-07-11 13:43:51

Prometheus监控

2011-03-21 14:43:42

2023-10-11 09:58:07

2013-04-12 13:30:47

2016-04-06 10:02:23

手机微博运维监控

2014-07-22 10:06:43

运维监控虚拟化

2018-09-27 08:59:29

2010-07-09 12:09:34

IT运维Mocha BSM摩卡软件

2011-03-25 13:54:00

Nagios

2011-01-05 15:39:44

2022-02-08 10:21:17

运维应用监控

2015-09-23 16:46:54

架构监控运维自动化

2022-11-08 00:00:00

监控系统Prometheus

2009-03-09 21:25:11

Linuxnagios开源

2020-11-26 09:10:36

Prometheus
点赞
收藏

51CTO技术栈公众号