参考文档:

  1. Prometheus github:https://github.com/prometheus
  2. grafana github:https://github.com/grafana/grafana
  3. Prometheus getting_started:https://prometheus.io/docs/prometheus/latest/getting_started/
  4. Prometheus node_exporter:https://github.com/prometheus/node_exporter
  5. Prometheus部署(docker,optional):https://prometheus.io/docs/prometheus/latest/installation/
  6. Prometheus配置文件详解:https://prometheus.io/docs/prometheus/latest/configuration/configuration/

一.环境

1. 拓扑

2. 节点

Node

OS

Hostname

IP

Remark

prometheus& grafana server

centos 7.4

prometheus

172.20.1.211

 

prometheus node

centos 7.4

node1

172.20.1.212

 

3. 版本(截止20171130)

二.部署prometheus

在prometheus& grafana server节点部署prometheus服务。

1. 下载&部署

  1. # 下载
  2. [root@prometheus src]# cd /usr/local/src/
  3. [root@prometheus src]# wget https://github.com/prometheus/prometheus/releases/download/v2.0.0/prometheus-2.0.0.linux-amd64.tar.gz
  4.  
  5. # 部署到/usr/local/目录
  6. # promethus不用编译安装,解压目录中有配置文件与启动文件
  7. [root@prometheus src]# tar -zxvf prometheus-2.0.0.linux-amd64.tar.gz -C /usr/local/
  8. [root@prometheus src]# cd /usr/local/
  9. [root@prometheus local]# mv prometheus-2.0.0.linux-amd64/ prometheus/
  10.  
  11. # 验证
  12. [root@prometheus local]# cd prometheus/
  13. [root@prometheus prometheus]# ./prometheus --version

2. 配置文件

  1. # 解压目录中的prometheus.yml
  2. # 简单验证,主要配置采用默认文件配置,有修改/新增处用红色标示
  3. [root@prometheus prometheus]# vim prometheus.yml
  4. # 全局配置
  5. global:
  6. scrape_interval: 15s # 设置抓取(pull)时间间隔,默认是1m
  7. evaluation_interval: 15s # 设置rules评估时间间隔,默认是1m
  8. # scrape_timeout is set to the global default (10s).
  9.  
  10. # 告警管理配置,暂未使用,默认配置
  11. alerting:
  12. alertmanagers:
  13. - static_configs:
  14. - targets:
  15. # - alertmanager:9093
  16.  
  17. # 加载rules,并根据设置的时间间隔定期评估,暂未使用,默认配置
  18. rule_files:
  19. # - "first_rules.yml"
  20. # - "second_rules.yml"
  21.  
  22. # 抓取(pull),即监控目标配置
  23. # 默认只有主机本身的监控配置
  24. scrape_configs:
  25. # 监控目标的label(这里的监控目标只是一个metric,而不是指某特定主机,可以在特定主机取多个监控目标),在抓取的每条时间序列表中都会添加此label
  26. - job_name: 'prometheus'
  27.  
  28. # metrics_path defaults to '/metrics'
  29. # scheme defaults to 'http'.
  30.  
  31. # 可覆盖全局配置设置的抓取间隔,由15秒重写成5秒。
  32. scrape_interval: 5s
  33.  
  34. # 静态指定监控目标,暂不涉及使用一些服务发现机制发现目标
  35. static_configs:
  36. - targets: ['localhost:9090']
  37. # (opentional)再添加一个label,标识了监控目标的主机
  38. labels:
  39. instance: prometheus
  40.  
  41. - job_name: 'linux'
  42. scrape_interval: 10s
  43. static_configs:
  44. # 采用node_exporter默认开放的端口
  45. - targets: ['172.20.1.212:9100']
  46. labels:
  47. instance: node1

3. 设置用户

  1. # 添加用户,后期用此账号启动服务
  2. [root@prometheus prom etheus]# groupadd prometheus
  3. [root@prometheus prometheus]# useradd -g prometheus -s /sbin/nologin prometheus
  4.  
  5. # 赋权
  6. [root@prometheus prometheus]# cd ~
  7. [root@prometheus ~]# chown -R prometheus:prometheus /usr/local/prometheus/
  8.  
  9. # 创建prometheus运行数据目录
  10. [root@prometheus ~]# mkdir -p /var/lib/prometheus
  11. [root@prometheus ~]# chown -R prometheus:prometheus /var/lib/prometheus/

4. 设置开机启动

  1. [root@prometheus ~]# touch /usr/lib/systemd/system/prometheus.service
  2. [root@prometheus ~]# chown prometheus:prometheus /usr/lib/systemd/system/prometheus.service
  3.  
  4. [root@prometheus ~]# vim /usr/lib/systemd/system/prometheus.service
  5. [Unit]
  6. Description=Prometheus
  7. Documentation=https://prometheus.io/
  8. After=network.target
  9.  
  10. [Service]
  11. # Type设置为notify时,服务会不断重启
  12. Type=simple
  13. User=prometheus
  14. # --storage.tsdb.path是可选项,默认数据目录在运行目录的./dada目录中
  15. ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --storage.tsdb.path=/var/lib/prometheus
  16. Restart=on-failure
  17.  
  18. [Install]
  19. WantedBy=multi-user.target
  20.  
  21. # 设置开机启动
  22. [root@prometheus ~]# systemctl enable Prometheus
  23. [root@prometheus ~]# systemctl start prometheus

5. 设置iptables

  1. [root@prometheus ~]# vim /etc/sysconfig/iptables
  2. -A INPUT -p tcp -m state --state NEW -m tcp --dport 9090 -j ACCEPT
  3.  
  4. [root@prometheus ~]# service iptables restart

6. 启动并验证

1)查看服务状态

  1. [root@prometheus ~]# systemctl status prometheus

  1. [root@prometheus ~]# netstat -tunlp | grep 9090

2)web ui

Prometheus自带有简单的UI,http://172.20.1.211:9090

在Status菜单下,Configuration,Rule,Targets等,

Statu-->Configuration展示prometheus.yml的配置,如下:

Statu-->Targets展示监控具体的监控目标,这里监控目标"linux"暂未设置node_exporter,未scrape数据,如下:

7. 绘图

访问:http://172.20.1.211:9090/metrics,查看从exporter具体能抓到的数据,如下:

访问:http://172.20.1.211:9090,在输入框中任意输入1个exporter能抓取得值,点击"Execute"与"Execute"按钮,即可见相应抓取数据的图形,同时可对时间与unit做调整,如下:

三.部署node_exporter

Node_exporter收集机器的系统数据,这里采用prometheus官方提供的exporter,除node_exporter外,官方还提供consul,memcached,haproxy,mysqld等exporter,具体可查看官网。

这里在prometheus node节点部署相关服务。

1. 下载&部署

  1. # 下载
  2. [root@node1 ~]# cd /usr/local/src/
  3. [root@node1 src]# wget https://github.com/prometheus/node_exporter/releases/download/v0.15.1/node_exporter-0.15.1.linux-amd64.tar.gz
  4.  
  5. # 部署
  6. [root@node1 src]# tar -zxvf node_exporter-0.15.1.linux-amd64.tar.gz -C /usr/local/
  7. [root@node1 src]# cd /usr/local/
  8. [root@node1 local]# mv node_exporter-0.15.1.linux-amd64/ node_exporter/

2. 设置用户

  1. [root@node1 ~]# groupadd prometheus
  2. [root@node1 ~]# useradd -g prometheus -s /sbin/nologin prometheus
  3. [root@node1 ~]# chown -R prometheus:prometheus /usr/local/node_exporter/

3. 设置开机启动

  1. [root@node1 ~]# vim /usr/lib/systemd/system/node_exporter.service
  2. [Unit]
  3. Description=node_exporter
  4. Documentation=https://prometheus.io/
  5. After=network.target
  6.  
  7. [Service]
  8. Type=simple
  9. User=prometheus
  10. ExecStart=/usr/local/node_exporter/node_exporter
  11. Restart=on-failure
  12.  
  13. [Install]
  14. WantedBy=multi-user.target
  15.  
  16. [root@node1 ~]# systemctl enable node_exporter
  17. [root@node1 ~]# systemctl start node_exporter

4. 设置iptables

  1. # 官方node_exporter默认使用9100端口
  2. [root@node1 ~]# vim /etc/sysconfig/iptables
  3. -A INPUT -p tcp -m state --state NEW -m tcp --dport 9100 -j ACCEPT
  4.  
  5. [root@node1 ~]# service iptables restart

5. 验证

访问:http://172.20.1.211:9090,可见node1主机已经可被监控,如下:

四.部署grafana

在prometheus& grafana server节点部署grafana服务。

1. 下载&安装

  1. # 下载
  2. [root@prometheus ~]# cd /usr/local/src/
  3. [root@prometheus src]# wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-4.6.2-1.x86_64.rpm
  4.  
  5. # 安装
  6. [root@prometheus src]# yum localinstall grafana-4.6.2-1.x86_64.rpm

2. 配置文件

配置文件位于/etc/grafana/grafana.ini,这里暂时保持默认配置即可。

3. 设置开机启动

  1. [root@prometheus src]# systemctl enable grafana-server
  2. [root@prometheus src]# systemctl start grafana-server

4. 设置iptables

  1. # grafana-server默认使用3000端口
  2. [root@prometheus src]# vim /etc/sysconfig/iptables
  3. -A INPUT -p tcp -m state --state NEW -m tcp --dport 3000 -j ACCEPT
  4.  
  5. [root@prometheus src]# service iptables restart

5. 添加数据源

1)登陆

访问:http://172.20.1.211:3000,默认账号/密码:admin/admin

2)添加数据源

在登陆首页,点击"Add data source"按钮,跳转到添加数据源页面,配置如下:

Name: prometheus

Type: prometheus

URL: http://localhost:9090/

Access: proxy

取消Default的勾选,其余默认,点击"Add",如下:

在"Dashboards"页签下"import"自带的模版,如下:

6. 导入dashboard

从grafana官网下载相关dashboaed到本地,如:https://grafana.com/dashboards/405

Grafana首页-->左上角图标-->Dashboard-->import

Upload已下载至本地的json文件(或者使用dashboard id,如这里的405),如下:

数据源选择"prometheus",即添加的数据源name,点击"Import"按钮,如下:

7. 查看dashboard

Grafana首页-->左上角图标-->Dashboard-->Home,Home下拉列表中可见有已添加的两个dashboard,"Prometheus Stats"与"Node Exporter Server Metrics",选择1个即可,如下:

Prometheus+Grafana监控部署实践的更多相关文章

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

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

  2. Prometheus Grafana监控全方位实践

    这次就不用 docker 部署服务了,这样大家会更容易接受.欢迎阅读. 引言 Prometheus 是一个监控系统,也是一个时间序列数据库,用Go语言开发的,官方文档.通过从某些特定的目标如主机,My ...

  3. 部署Prometheus+Grafana监控

    Prometheus 1.不是很友好,各种配置都手写 2.对docker和k8s监控有成熟解决方案 Prometheus(普罗米修斯) 是一个最初在SoudCloud上构建的监控系统,开源项目,拥有非 ...

  4. [转帖]Prometheus+Grafana监控Kubernetes

    原博客的位置: https://blog.csdn.net/shenhonglei1234/article/details/80503353 感谢原作者 这里记录一下自己试验过程中遇到的问题: . 自 ...

  5. Prometheus + Grafana 监控系统搭

    本文主要介绍基于Prometheus + Grafana 监控Linux服务器. 一.Prometheus 概述(略) 与其他监控系统对比 1 Prometheus vs. Zabbix Zabbix ...

  6. Prometheus+Grafana监控Kubernetes

    涉及文件下载地址:链接:https://pan.baidu.com/s/18XHK7ex_J0rzTtfW-QA2eA 密码:0qn6 文件中需要下载的镜像需要自己提前下载好,eg:prom/node ...

  7. cAdvisor+Prometheus+Grafana监控docker

    cAdvisor+Prometheus+Grafana监控docker 一.cAdvisor(需要监控的主机都要安装) 官方地址:https://github.com/google/cadvisor ...

  8. prometheus+grafana监控redis

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

  9. prometheus+grafana监控mysql

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

随机推荐

  1. Read a large file with python

    python读取大文件 较pythonic的方法,使用with结构 文件可以自动关闭 异常可以在with块内处理 with open(filename, 'rb') as f: for line in ...

  2. Java使用JodaTime处理时间

    简介 在Java中处理日期和时间是很常见的需求,基础的工具类就是我们熟悉的Date和Calendar,然而这些工具类的api使用并不是很方便和强大,于是就诞生了Joda-Time这个专门处理日期时间的 ...

  3. 一次JVM调优经历

    前几天前端同事找我帮忙解决一个频繁FullGC问题.在100用户,每秒5个请求条件下进行测试,发现频繁FullGC. 使用VisualVM观察Jvm运行时信息,发现DB连接池占用了较多的资源.于是看了 ...

  4. 领扣-无重复字符的最长子串-Python实现

    给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度. 示例 1: 输入: "abcabcbb" 输出: 3 解释: 因为无重复字符的最长子串是 "abc&qu ...

  5. PTA(BasicLevel)-1012 数字分类

    一 题目描述    给定一系列正整数,请按要求对数字进行分类,并输出以下 5 个数字: ​​ = 能被 5 整除的数字中所有偶数的和: ​​ = 将被 5 除后余 1 的数字按给出顺序进行交错求和,即 ...

  6. 音频算法之小黄人变声 附完整C代码

    前面提及到<大话音频变声原理 附简单示例代码>与<声音变调算法PitchShift(模拟汤姆猫) 附完整C++算法实现代码> 都稍微讲过变声的原理和具体实现. 大家都知道,算法 ...

  7. 实现虚拟机和宿主机之间的复制、粘贴(ubuntu系统)

    参考:https://blog.csdn.net/weixin_37850264/article/details/79057886 https://blog.csdn.net/zldz14/artic ...

  8. OpenFlow1.3.3 学习记录(持续更新)

    OpenFlow1.3.3 学习记录(持续更新) 正在学习OpenFlow1.3,该篇笔记将日常更新,主要内容大致为官方文档的总结与翻译. 交换机组件 按照优先级顺序进行包匹配,如果匹配到流表项,则执 ...

  9. 【Hutool】Hutool工具类之日期时间工具——DateUtil

    一.用于取代Date对象的DateTime对象 再也不用Date SimpleDateFormat Calendar之间倒腾来倒腾去了!日期创建-获取-操作一步到位! 如果JDK版本更新到了8及以上, ...

  10. HDFS要点

    namenode存储的数据: 主控服务器主要有三类数据:文件系统的目录结构数据,各个文件的分块信息,数据块的位置信息(就数据块放置在哪些数据服务器上...).在GFS和HDFS的架构中,只有文件的目录 ...