安装prometheus+grafana监控mysql redis kubernetes等

https://www.cnblogs.com/sfnz/p/6566951.html

plug 的模式进行处理.

1.prometheus安装

wget https://github.com/prometheus/prometheus/releases/download/v1.5.2/prometheus-1.5.2.linux-amd64.tar.gz

tar -zxvf prometheus-1.5.2.linux-amd64.tar.gz -C /opt/prometheus --strip-components=1

cd /opt/prometheus

mv prometheus.yml prometheus.yml-bak

# vi prometheus.yml
global:
scrape_interval: 10s
evaluation_interval: 10s

scrape_configs:
- job_name: linux
static_configs:
- targets: ['192.168.0.8:9100']
labels:
instance: db-0.8

- job_name: mysql
static_configs:
- targets: ['192.168.0.8:9104']
labels:
instance: db-0.8

启动 nohup /opt/prometheus/prometheus &

web界面 http://192.168.0.15:9090/graph

2.grafana安装

wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-4.0.1-1480694114.x86_64.rpm
yum localinstall grafana-4.0.1-1480694114.x86_64.rpm

service grafana-server start

至此安装完成。

浏览器打开 http://192.168.0.15:3000 ,输入默认用户名密码 (admin/admin) 可以进入 Grafana 。

然后配置数据源:

Prometheus: URL: http://192.168.0.15:9090/

即可完成 Prometheus 和 Grafana 的对接。

3.替换grafana的dashboards

Grafana 并没有太多的配置好的图表模板,除了 Percona 开源的一些外,很多需要自行配置。

下载dashboards
(https://github.com/percona/grafana-dashboards)

git clone https://github.com/percona/grafana-dashboards.git
cp -r grafana-dashboards/dashboards /var/lib/grafana/

编辑 Grafana config

vi /etc/grafana/grafana.ini

[dashboards.json]
enabled = true
path = /var/lib/grafana/dashboards

systemctl restart grafana-server

4.客户端安装

(1)mysql:在需要监控的mysql上安装 node_exporter和 mysqld_exporter

wget https://github.com/prometheus/node_exporter/releases/download/0.13.0/node_exporter-0.13.0.linux-amd64.tar.gz
wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.9.0/mysqld_exporter-0.9.0.linux-amd64.tar.gz

tar -zxvf node_exporter-0.13.0.linux-amd64.tar.gz -C /opt/prometheus_exporters  --strip-components=1
tar -zxvf mysqld_exporter-0.9.0.linux-amd64.tar.gz -C /opt/prometheus_exporters  --strip-components=1

运行node_exporter :
nohup /opt/prometheus_exporters/node_exporter & 

mysqld_exporter需要连接到Mysql,所以需要Mysql的权限,我们先为它创建用户并赋予所需的权限:

mysql> GRANT REPLICATION CLIENT, PROCESS ON *.* TO 'prom'@'localhost' identified by 'amnt@#*IK<1qaz';
mysql> GRANT SELECT ON performance_schema.* TO 'prom'@'localhost';
mysql> flush privileges;

创建.my.cnf文件并运行mysqld_exporter:

$ cd /usr/local/services/prometheus_exporters
$ cat << EOF > .my.cnf
[client]
user=prom
password=abc123
EOF
$ nohup /opt/prometheus_exporters/mysqld_exporter -config.my-cnf=".my.cnf" &

(2).redis 在redis服务器安装node_exporter和redis_exporter

wget https://github.com/oliver006/redis_exporter/releases/download/v0.10.8/redis_exporter-v0.10.8.linux-amd64.tar.gz
wget https://github.com/prometheus/node_exporter/releases/download/0.13.0/node_exporter-0.13.0.linux-amd64.tar.gz

tar -zxvf node_exporter-0.13.0.linux-amd64.tar.gz -C /opt/prometheus_exporters --strip-components=1
tar -zxvf redis_exporter-v0.10.8.linux-amd64.tar.gz -C /opt/prometheus_exporters --strip-components=1

启动

nohup /opt/prometheus_exporters/node_exporter &

nohup /opt/prometheus_exporters/redis_exporter redis//192.168.0.17:6379 &

配置prometheus.yml 加入

- job_name: redis_exporter
  static_configs:
  - targets: ['192.168.0.17:9121']

下载grafana的redis的prometheus-redis_rev1.json模板

wget  https://grafana.com/api/dashboards/763/revisions/1/download

在grafana中导入json模板

过一段时间就能看到图形了

(3).

kubernetes 模板配置

因为prometheus和kubernetes是结合的,所以导入模板后,直接配置prometheus.yml即可

模板下载:https://grafana.com/dashboards/315

prometheus.yml 加入以下配置

- job_name: kubernetes-nodes-cadvisor
static_configs:
- targets: ['192.168.0.19:4194','192.168.0.21:4194']
labels:
instance: kubernetes-nodes-cadvisor
kubernetes_sd_configs:
- role: node
relabel_configs:
- action: labelmap
regex: __meta_kubernetes_node_label_(.+)
metric_relabel_configs:
- action: replace
source_labels: [id]
regex: '^/machine\.slice/machine-rkt\\x2d([^\\]+)\\.+/([^/]+)\.service$'
target_label: rkt_container_name
replacement: '${2}-${1}'
- action: replace
source_labels: [id]
regex: '^/system\.slice/(.+)\.service$'
target_label: systemd_service_name
replacement: '${1}'

等待片刻可见图形:

最终prometheus配置:

# cat prometheus.yml
global:
  scrape_interval:     10s
  evaluation_interval: 10s

scrape_configs:
  - job_name: node
    static_configs:
      - targets: ['192.168.0.8:9100','192.168.0.19:9100','192.168.0.21:9100','192.168.0.17:9100']
        labels:
          instance: node

  - job_name: mysql
    static_configs:
      - targets: ['192.168.0.8:9104']
        labels:
          instance: db-0.8

  - job_name: redis_exporter
    static_configs:
      - targets: ['192.168.0.17:9121']

  - job_name: kubernetes-nodes-cadvisor
    static_configs:
      - targets: ['192.168.0.19:4194','192.168.0.21:4194']
        labels:
          instance: kubernetes-nodes-cadvisor
    kubernetes_sd_configs:
      - role: node
    relabel_configs:
      - action: labelmap
        regex: __meta_kubernetes_node_label_(.+)
    metric_relabel_configs:
      - action: replace
        source_labels: [id]
        regex: '^/machine\.slice/machine-rkt\\x2d([^\\]+)\\.+/([^/]+)\.service$'
        target_label: rkt_container_name
        replacement: '${2}-${1}'
      - action: replace
        source_labels: [id]
        regex: '^/system\.slice/(.+)\.service$'
        target_label: systemd_service_name
        replacement: '${1}'

参考文档:

https://segmentfault.com/a/1190000007040144

http://www.tuicool.com/articles/vEVjai

https://github.com/prometheus

dashboards模板下载:https://grafana.com/dashboards

redis模板:https://github.com/oliver006/redis_exporter

启动 nohup /opt/prometheus_exporters/redis_exporter redis//192.168.0.17:6379 &

Prometheus监控 - Alertmanager报警模块:http://blog.csdn.net/y_xiao_/article/details/50818451

欢迎加入python/Django群:480058958 喜欢读书的人可加生活.读书.新知群:475749546

[转帖]安装prometheus+grafana监控mysql redis kubernetes等的更多相关文章

  1. 安装prometheus+grafana监控mysql redis kubernetes等

    1.prometheus安装 wget https://github.com/prometheus/prometheus/releases/download/v1.5.2/prometheus-1.5 ...

  2. prometheus+grafana监控mysql

    prometheus+grafana监控mysql 1.安装配置MySQL官方的 Yum Repository(有mysql只需设置监控账号即可) [root@localhost ~]# wget - ...

  3. Prometheus+Grafana监控MySQL、Redis数据库

    俗话说,没有监控的系统就是在裸奔,好的监控就是运维人员的第三只手,第三只眼.本文将使用prometheus及Grafana搭建一套监控系统来监控主机及数据库(MySQL.Redis). 1.  安装G ...

  4. Prometheus + Grafana 监控(mysql 和redis)

    1.监控MySQL(mysqld-exporter) https://github.com/prometheus/mysqld_exporter/releases/download/v0.11.0/m ...

  5. 使用Prometheus+Grafana监控MySQL实践

    一.介绍Prometheus Prometheus(普罗米修斯)是一套开源的监控&报警&时间序列数据库的组合,起始是由SoundCloud公司开发的.随着发展,越来越多公司和组织接受采 ...

  6. prometheus+grafana监控mysql最佳实践

    导航 前言 环境准备 安装Docker 安装prometheus 安装mysqld_exporter prometheus采集数据 安装grafana grafana配置数据源 感谢您的阅读,预计阅读 ...

  7. 技术分享 | Prometheus+Grafana监控MySQL浅析

    GreatSQL社区原创内容未经授权不得随意使用,转载请联系小编并注明来源. 简介 Prometheus 一套开源的监控&报警&时间序列数据库的组合,通常 Kubernetes 中都会 ...

  8. prometheus+grafana监控Linux和kubernetes的例子

    1.安装和配置prometheus tar zxvf prometheus-.linux-amd64.tar.gz -C /usr/local/ ln -sv /usr/local/prometheu ...

  9. prometheus+grafana监控redis

    prometheus+grafana监控redis redis安装配置 https://www.cnblogs.com/autohome7390/p/6433956.html redis_export ...

随机推荐

  1. Postman请求运行顺序及Workflow

    作为一款接口调试利器, Postman的更新迭代速度很快, 不断加入了很多新的功能.使的api设计,测试,监控, Mock,以及团队协作更加方便. 修改执行顺序 在遇到有接口依赖的情况, 我们往往需要 ...

  2. 决策树算法的Python实现—基于金融场景实操

    决策树是最经常使用的数据挖掘算法,本次分享jacky带你深入浅出,走进决策树的世界 基本概念 决策树(Decision Tree) 它通过对训练样本的学习,并建立分类规则,然后依据分类规则,对新样本数 ...

  3. 用matlab脚本语言写M文件函数时用三种方法简单实现实现DFT(离散傅里叶变换)

    %用二重循环实现DFT: function xk=dt_0(xn); %define a function N=length(xn); %caculate the length of the vari ...

  4. 秒的换算:ms(毫秒),μs(微秒),ns(纳秒),ps(皮秒)

    皮秒 皮秒,符号ps(英语:picosecond ).1皮秒等于一万亿分之一秒(10-12秒) 1,000 皮秒 = 1纳秒 1,000,000 皮秒 = 1微秒 1,000,000,000 皮秒 = ...

  5. Web安全(白帽子讲)之第二篇

    第二章:浏览器安全 2.1.同源策略 是一种约定,它是浏览器最核心也是最基本的安全功能. web是构建在同源策略的基础之上,浏览器只是针对同源策略的一种实现 影响“源” 的因素有:host(域名或IP ...

  6. gradle添加阿里云maven库

    用gradle构建spring项目,才发现gradle要添加阿里云maven库和maven不太一样 链接:https://www.cnblogs.com/SiriYang/p/10638365.htm ...

  7. ubuntu进行apt-get时候出现Package ssh is not available, but is referred to by another package 错误

    今天在ubuntu进行ssh安装的时候,出现如下错误. Reading package lists... Done Building dependency tree... Done Package s ...

  8. 1.4 Go语言基础之流程控制

    流程控制是每种编程语言控制逻辑走向和执行次序的重要部分,流程控制可以说是一门语言的"经脉". Go语言中最常用的流程控制有if和for,而switch和goto主要是为了简化代码. ...

  9. LC 957. Prison Cells After N Days

    There are 8 prison cells in a row, and each cell is either occupied or vacant. Each day, whether the ...

  10. java常用的正则表达式的工具类

    import com.google.common.base.Strings; import java.util.regex.Matcher;import java.util.regex.Pattern ...