Grafana+Prometheus打造全方位立体监控系统
前言
本文主要介绍如何使用Grafana和Prometheus以及node_exporter对Linux服务器性能进行监控。下面两张图分别是两台服务器监控信息:
服务器A

服务器B

概述
Prometheus是一个开源的服务监控系统,它通过HTTP协议从远程的机器收集数据并存储在本地的时序数据库上。
- 多维数据模型(时序列数据由metric名和一组key/value组成)
- 在多维度上灵活的查询语言(PromQl)
- 不依赖分布式存储,单主节点工作.
- 通过基于HTTP的pull方式采集时序数据
- 可以通过push gateway进行时序列数据推送(pushing)
- 可以通过服务发现或者静态配置去获取要采集的目标服务器
- 多种可视化图表及仪表盘支持
Prometheus通过安装在远程机器上的exporter来收集监控数据,后面我们将使用到node_exporter收集系统数据。
架构

Grafana 是一个开箱即用的可视化工具,具有功能齐全的度量仪表盘和图形编辑器,有灵活丰富的图形化选项,可以混合多种风格,支持多个数据源特点。

架构

安装
Exporter
下载并解压:
#下载
wget https://github.com/prometheus/node_exporter/releases/download/v0.14.0/node_exporter-0.15.0.linux-amd64.tar.gz -O node_exporter-0.15.0.linux-amd64.tar.gz
# 可自定义解压目录
tar -xvf node_exporter-0.15.0.linux-amd64.tar.gz
运行node_exporter:
## 后台运行
./node_exporter &
Prometheus
下载地址:https://prometheus.io/download
执行以下命令:
## 下载
wget https://github.com/prometheus/prometheus/releases/download/v2.0.0-rc.3/prometheus-2.0.0-rc.3.linux-amd64.tar.gz
## 可自定义解压目录
tar -xvf prometheus-2.0.0-rc.3.linux-amd64.tar.gz
配置prometheus,vi prometheus.yml
global:
scrape_interval: 15s
evaluation_interval: 15s
- job_name: prometheus
static_configs:
- targets: ['localhost:9090']
labels:
instance: prometheus
- job_name: linux1
static_configs:
- targets: ['192.168.1.120:9100']
labels:
instance: sys1
- job_name: linux2
static_configs:
- targets: ['192.168.1.130:9100']
labels:
instance: sys2
IP对应的是我们内网的服务器,端口则是对应的exporter的监听端口。
运行Prometheus
./prometheus
level=info ts=2017-11-07T02:39:50.220187934Z caller=main.go:215 msg="Starting Prometheus" version="(version=2.0.0-rc.2, branch=HEAD, revision=ce63a5a8557bb33e2030a7756c58fd773736b592)"
level=info ts=2017-11-07T02:39:50.22025258Z caller=main.go:216 build_context="(go=go1.9.1, user=root@a6d2e4a7b8da, date=20171025-18:42:54)"
level=info ts=2017-11-07T02:39:50.220270139Z caller=main.go:217 host_details="(Linux 3.10.0-514.16.1.el7.x86_64 #1 SMP Wed Apr 12 15:04:24 UTC 2017 x86_64 iZ2ze74fkxrls31tr2ia2fZ (none))"
level=info ts=2017-11-07T02:39:50.223171565Z caller=web.go:380 component=web msg="Start listening for connections" address=0.0.0.0:9090
......
启动成功以后我们可以通过Prometheus内置了web界面访问,http://ip:9090 ,如果出现以下界面,说明配置成功

Grafana
执行以下安装命令:
## 安装依赖grafana运行需要go环境
yum install go -y
## 安装 grafana
yum install https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-4.6.1-1.x86_64.rpm -y
安装包信息:
二进制文件: /usr/sbin/grafana-server
init.d 脚本: /etc/init.d/grafana-server
环境变量文件: /etc/sysconfig/grafana-server
配置文件: /etc/grafana/grafana.ini
启动项: grafana-server.service
日志文件:/var/log/grafana/grafana.log
默认配置的sqlite3数据库:/var/lib/grafana/grafana.db
你可以执行以下启动命令:
service grafana-server start
启动grafana,并设置开机启动:
systemctl daemon-reload
systemctl start grafana-server
systemctl status grafana-server
systemctl enable grafana-server.service
服务器端图像(PNG)渲染是可选的功能,但在共享可视化时非常有用,例如在警报通知中。
如果图像缺少文本,请确保已安装字体包。
yum install fontconfig
yum install freetype*
yum install urw-fonts
访问Grafana通过Nginx代理,默认登录用户名密码:admin/admin,需及时修改。
server {
listen 80;
server_name grafana.52itstyle.com;
charset utf-8;
location / {
default_type text/html;
proxy_pass http://127.0.0.1:3000;
}
}
编辑配置文件/etc/grafana/grafana.ini ,修改dashboards.json段落下两个参数的值:
[dashboards.json]
enabled = true
path = /var/lib/grafana/dashboards
安装仪表盘JSON模版:
git clone https://github.com/percona/grafana-dashboards.git
cp -r grafana-dashboards/dashboards /var/lib/grafana/
最后,通过service grafana-server start命令启动服务,访问地址:http://grafana.52itstyle.com

然后在Data Sources选项中添加数据源:

添加成功以后,我们就可以查看到文章开头的效果图了。
总结
讲道理,这一套东西还是很强大的,各种开源组间一整合完美搭建出一套监控系统。当然了以上仅仅是系统的一个监控,Grafana以及exporter组间还可以实现对Nginx、MySql、Redis以及MongDB的监控。
监控不是目的,目的是出现问题能够及时发现并解决问题。
参考资料
https://github.com/prometheus/node_exporter
https://github.com/percona/grafana-dashboards
https://www.percona.com/blog/2016/02/29/graphing-mysql-performance-with-prometheus-and-grafana/
Grafana+Prometheus打造全方位立体监控系统的更多相关文章
- Linux下打造全方位立体监控系统
前言 本文主要介绍如何使用Grafana和Prometheus以及node_exporter对Linux服务器性能进行监控.下面两张图分别是两台服务器: 服务器A 服务器B 概述 Prometheus ...
- Grafana+Prometheus 搭建 JuiceFS 可视化监控系统
作为承载海量数据存储的分布式文件系统,用户通常需要直观地了解整个系统的容量.文件数量.CPU 负载.磁盘 IO.缓存等指标的变化. JuiceFS 没有重复造轮子,而是通过 Prometheus 兼容 ...
- 基于Prometheus搭建SpringCloud全方位立体监控体系
前提 最近公司在联合运维做一套全方位监控的系统,应用集群的技术栈是SpringCloud体系.虽然本人没有参与具体基础架构的研发,但是从应用引入的包和一些资料的查阅大致推算出具体的实现方案,这里做一次 ...
- Prometheus+Grafana+Alertmanager搭建全方位的监控告警系统
prometheus安装和配置 prometheus组件介绍 1.Prometheus Server: 用于收集和存储时间序列数据. 2.Client Library: 客户端库,检测应用程序代码,当 ...
- Zabbix+Grafana打造高逼格监控系统
第一章 zabbix监控的意义 1.1 为什么要监控 业务安全性的保障 系统的保障 产品持续性的运行 1.2 监控的内容 1.3 zabbix的选择性 [x] 纯命令监控太局限性 [x] 监控三剑客( ...
- Grafana+Prometheus打造springboot监控平台
1. 环境 springboot 1.5.10.RELEASE Grafana 5.4.2 Prometheus 2.6.0 jdk 1.8 2.通过micrometer与springboot应用和p ...
- collectd+logstash+influxdb+grafana构建windows服务器应用监控系统
一.背景介绍 本监控方案支持对Windows Server服务器集群的全面监控,方案提供丰富的图表展示, 以及对异常问题进行邮件的实时报警. 本系统由Collectd(操作系统数据搜集).logsta ...
- 【转】Windows7打造全方位护眼系统
原文网址:http://www.cnblogs.com/duboway/archive/2013/04/20/3033257.html 电脑屏幕: Win7和Vista系统设置如下: 第一步:桌面空白 ...
- Grafana+Prometheus系统监控之MySql
架构 grafana和prometheus之前安装配置过,见:Grafana+Prometheus打造全方位立体监控系统 MySql安装 MySql的地位和重要性就不言而喻了,作为开源产品深受广大中小 ...
随机推荐
- How do I install Daydream on my phone?
Google's philosophy with their newest VR platform is simple. In order to offer the best possible exp ...
- DAY5(PYTHON) 字典的增删改查和dict嵌套
一.字典的增删改查 dic={'name':'hui','age':17,'weight':168} dict1={'height':180,'sex':'b','class':3,'age':16} ...
- c# .Net随机生成字符串代码
/// <summary> /// 随机生成字符串 /// </summary> /// <param name="OperationType"> ...
- C#方法重载(overload)方法重写(override)隐藏(new)
一.重载:同一个作用域内发生(比如一个类里面),定义一系列同名方法,但是方法的参数列表不同.这样才能通过传递不同的参数来决定到底调用哪一个. 值得注意的是,方法重载只有通过参数不同来判断调用哪个方法, ...
- python拟合数据,并通过拟合的曲线去预测新值的方法
from scipy import interpolate import matplotlib.pyplot as plt import numpy as np def f(x): x_points ...
- JavaScript -- 时光流逝(十二):DOM -- Element 对象
JavaScript -- 知识点回顾篇(十二):DOM -- Element 对象 (1) element.accessKey: 设置或返回accesskey一个元素,使用 Alt + 指定快捷键 ...
- LeetCode算法题-Missing Number(Java实现-四种解法)
这是悦乐书的第200次更新,第209篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第65题(顺位题号是268).给定一个包含n个不同数字的数组,取自0,1,2,...,n ...
- java.util.LinkedHashMap cannot be cast to xxx 和 net.sf.ezmorph.bean.MorphDynaBean cannot be cast to xxx
java.util.LinkedHashMap cannot be cast to com.entity.Person 使用mybatis, resultMap映射的是实体类Person, 查询出来的 ...
- CentOS 7下安装Python3.6
CentOS 7下安装Python3.6.4 CentOS 7下安装Python3.5 •安装python3.6可能使用的依赖 yum install openssl-devel bzip2-de ...
- 16.ajax_case01
# 抓取北京市2018年积分落户公示名单 # 'http://www.bjrbj.gov.cn/integralpublic/settlePerson' import csv import json ...