[转帖]安装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 ‘[email protected]#*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

原文地址:https://www.cnblogs.com/jinanxiaolaohu/p/11294515.html

时间: 2024-12-10 07:19:41

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

使用Prometheus+Grafana监控MySQL实践

Grafana+Prometheus打造全方位立体监控系统 一.介绍Prometheus Prometheus(普罗米修斯)是一套开源的监控&报警&时间序列数据库的组合,起始是由SoundCloud公司开发的.随着发展,越来越多公司和组织接受采用Prometheus,社会也十分活跃,他们便将它独立成开源项目,并且有公司来运作.Google SRE的书内也曾提到跟他们BorgMon监控系统相似的实现是Prometheus.现在最常见的Kubernetes容器管理系统中,通常会搭配Promet

prometheus+grafana监控redis

prometheus+grafana监控redis redis安装配置 https://www.cnblogs.com/autohome7390/p/6433956.html redis_exporter 安装 cd /usr/src wget https://github.com/oliver006/redis_exporter/releases/download/v0.21.2/redis_exporter-v0.21.2.linux-amd64.tar.gz tar xf redis_ex

Prometheus + Grafana 监控系统搭

本文主要介绍基于Prometheus + Grafana 监控Linux服务器. 一.Prometheus 概述(略) 与其他监控系统对比 1 Prometheus vs. Zabbix Zabbix 使用的是 C 和 PHP, Prometheus 使用 Golang, 整体而言 Prometheus 运行速度更快一点. Zabbix 属于传统主机监控,主要用于物理主机.交换机.网络等监控,Prometheus 不仅适用主机监控,还适用于 Cloud.SaaS.Openstack.Contai

cAdvisor+Prometheus+Grafana监控docker

cAdvisor+Prometheus+Grafana监控docker 一.cAdvisor(需要监控的主机都要安装) 官方地址:https://github.com/google/cadvisor CAdvisor是谷歌开发的用于分析运行中容器的资源占用和性能指标的开源工具.CAdvisor是一个运行时的守护进程,负责收集.聚合.处理和输出运行中容器的信息.注意在查找相关资料后发现这是最新版cAdvisor的bug,换成版本为google/cadvisor:v0.24.1 就ok了,映射主机端

利用Prometheus和Grafana监控MySQL

一. Prometheus 是一个开源的服务监控系统和时间序列数据库.: 官方GitHub地址为:https://github.com/prometheus/prometheus 官方地址:https://prometheus.io/ 官方拓扑图如下 特性: 高维度数据模型 自定义查询语言 可视化数据展示 高效的存储策略 易于运维 提供各种客户端开发库 警告和报警 数据导出 二.安装Prometheus(服务器环境为Centos7.2,本实验服务端跟被监控MySQL在同一台服务器) 前提条件请关

Rancher2.x 一键式部署 Prometheus + Grafana 监控 Kubernetes 集群

目录 1.Prometheus & Grafana 介绍 2.环境.软件准备 3.Rancher 2.x 应用商店 4.一键式部署 Prometheus 5.验证 Prometheus + Grafana 1.Prometheus & Grafana 介绍 Prometheus 是一套开源的系统监控.报警.时间序列数据库的组合,Prometheus 基本原理是通过 Http 协议周期性抓取被监控组件的状态,而通过 Exporter Http 接口输出这些被监控的组件信息,而且已经有很多 E

Prometheus+Grafana监控

什么是Prometheus? Prometheus是由SoundCloud开发的开源监控报警系统和时序列数据库(TSDB).Prometheus使用Go语言开发,是Google BorgMon监控系统的开源版本.2016年由Google发起Linux基金会旗下的原生云基金会(Cloud Native Computing Foundation), 将Prometheus纳入其下第二大开源项目.Prometheus目前在开源社区相当活跃.Prometheus和Heapster(Heapster是K8

Prometheus+Grafana监控部署实践

参考文档: Prometheus github:https://github.com/prometheus grafana github:https://github.com/grafana/grafana Prometheus getting_started:https://prometheus.io/docs/prometheus/latest/getting_started/ Prometheus node_exporter:https://github.com/prometheus/no

基于prometheus+grafana 搭建监控mysql redis mongodb等

先把题目定好,具体待这几天整理我的笔记补充进来. 官方网站 https://prometheus.io/ 参考文档: http://www.cnblogs.com/sfnz/p/6566951.html http://www.jb51.net/article/107386.htm https://www.iamle.com/archives/2130.html