Prometheus

Prometheus和Grafana组合基本上是监控系统的标配。Prometheus做存储后端,Grafana做分析及可视化界面。

普罗米修斯是开源的系统监控/报警工具库,功能非常全,且拥有活跃的开发者和用户社区。Prometheus通过HTTP定期主动拉取(Pull)的方式获得指标(直接获取或通过gateway推送),在本地存储所有抓取的样本,并对这些数据运行规则,从现有数据聚合和记录新的时间序列,或生成警报。

Prometheus原生的可视化界面做得比较原始(主要用于调试),所以社区(官方推荐)使用Grafana来做数据展示。

Grafana专注于数据展示,有着丰富用成熟的展示方式和插件,数据源支持Elasticsearch, Prometheus, Graphite, InfluxDB等等。可以让你通过界面点击(无需写前端代码)快速搭建一个非常专业漂亮的展示界面。即便对于前端零基础的开发者也非常友好!

安装Prometheus

  1. 官网下载需要的版本(uname -rv查看linux内核版本及发行号)。比如x86的就下载linux-386系列。

  2. Prometheus会主动通过HTTP请求来收集受监控目标的指标。 比如它也通过HTTP Rest API导出了自己的健康状态数据,所以也可以用来监控自己。解压下载源文件内包含一个基本的prometheus.yml配置可以参照。配置非常简单。

    1. global: # 全局配置
    2. scrape_interval: 15s #主动拉取指标的间隔
    3. evaluation_interval: 15s #计算间隔
    4. scrape_configs: #监控的目标配置
    5. - job_name: prometheus #名称
    6. static_configs: # 静态配置
    7. - targets: ['127.0.0.1:9090'] #监控目标暴露的HTTP API端口,是个列表
    • 把里面的localhost改成你对应机器的IP。
    • 其它详细的配置可见配置文档
  3. 前台启动Prometheus,如果是在生产环境,需要后台启动时,最好自行配置Systemd

    1. # Start Prometheus.
    2. # By default, Prometheus stores its database in ./data (flag --storage.tsdb.path).
    3. ./prometheus --config.file=prometheus.yml
  4. 用浏览器打开http://IP:9090/metrics查询所有指标列表。

  5. 用浏览器打开http://IP:9090/graph,原生的简易的展示界面(太简陋了,基本没人会用)。

    PS:因为Promethues自己导出的指标和展示界面都是同一个9090端口。但实践中metrics接口指向的是目标机器的指标列表,用于Promethues主动拉取。

丰富的Exporter可以下载使用,开箱即用。下面可以用NodeExporter来做个范例。

安装NodeExporter

NodeExporter暴露很多和硬件/软件相关的指标(metrics)。

    1. $ tar xvfz node_exporter-*
    2. $ cd node_exporter-*
  • 启动NodeExporter。

    1. $ ./node_exporter
    2. INFO[0000] Starting node_exporter (version=0.18.1, branch=HEAD, revision=3db77732e925c08f675d7404a8c46466b2ece83e) source="node_exporter.go:156"
    3. INFO[0000] Build context (go=go1.12.5, user=root@b50852a1acba, date=20190604-16:41:43) source="node_exporter.go:157"
    4. INFO[0000] Enabled collectors: source="node_exporter.go:97"
    5. INFO[0000] - arp source="node_exporter.go:104"
    6. ...
    7. INFO[0000] Listening on :9100 source="node_exporter.go:170"

    可以使用./node_exporter -h查看具体的启动参数。从上面可以看它使用的端口是9100,所有的指标列表都可以和上面示例中的prometheus的接口一样:

    1. $ curl http://localhost:9100/metrics
    2. # HELP go_gc_duration_seconds A summary of the GC invocation durations.
    3. # TYPE go_gc_duration_seconds summary
    4. go_gc_duration_seconds{quantile="0"} 2.8138e-05
    5. go_gc_duration_seconds{quantile="0.25"} 4.1588e-05
    6. go_gc_duration_seconds{quantile="0.5"} 0.000102923
    7. go_gc_duration_seconds{quantile="0.75"} 0.000162106
    8. go_gc_duration_seconds{quantile="1"} 0.000495923
    9. go_gc_duration_seconds_sum 0.060153937
    10. go_gc_duration_seconds_count 537
    11. # HELP go_goroutines Number of goroutines that currently exist.
    12. ...

    可以看到所有关于node_exporter的指标列表。接下来就是把让prometheus来取这些指标。

  • 配置prometheus拉node exporter的指标。即把targets增加9100端口。

    1. scrape_configs:
    2. - job_name: 'node'
    3. static_configs:
    4. - targets: ['127.0.0.1:9100']
  • 重启prometheus。

    1. ./prometheus --config.file=./prometheus.yml

    再次查看浏览器打开graph查看:http://127.0.0.1:9090/graph。勾选Enable query history后直接输入以node就可以看到大量关于node为前缀的指标了。比如:node_filesystem_avail_bytes查看文件系统可用空间大小情况。

这个界面还是太原始了,但可以用来体验一下PromQL。接下来演示一下接入grafana来展示这些数据。

安装Grafana

官方指引下载安装:比如Centos安装是

  1. $ wget https://dl.grafana.com/oss/release/grafana-6.3.3-1.x86_64.rpm
  2. $ sudo yum localinstall grafana-6.3.3-1.x86_64.rpm

配置grafana

你可以在/etc/grafana/grafana.ini中配置端口及其它的,具体所有的配置项在: https://grafana.com/docs/installation/configuration/,我们这里都保持默认值,端口默认为3000.用户名/密码默认为admin

你可以在这里找到对应的启动方式,比如在CentOS上就是

  1. sudo service grafana-server start

启动成功后,你可以使用浏览器打开http://IP:3000使用admin/admin登录。

创建界面

Prometheus的数据源(data source)

  • 点击侧边栏中的Grafana图标 -> DataSources -> Add New
  • 选择Prometheus类型.
  • 设置Prometheus的对外URL(比如 http://IP:9090).
  • 点击Add添加

Prometheus图表展示

  • 点击graph标题 --> Edits.
  • 在Metrics标签下选择你上一步刚增加的Prometheus数据库。
  • 在Query字段中输入Prometheus表达式,会自动补全。
  • 自定义图表横坐标中指标的名称: Legend format。

导入Dashboards

Grafana.com上有很多别人分享的优化的dashboards,我们可以直接从上面找到node exporter对应的dashboard来使用。下载对应的json文件,然后导入。

其它

在Grafana上如何为选择合适的图表来展示Prometheus对应的数据类型(单调递增的Counter,可降可升的Gauge,用于柱状图展示的Histogram),提供滑动窗口求和的Summary

Reference

Prometheus Grafana快速搭建的更多相关文章

  1. Telegraf+InfluxDB+Grafana快速搭建实时监控系统 监控postgresql

    Telegraf+InfluxDB+Grafana快速搭建实时监控系统  监控postgresql

  2. 通过 Telegraf + InfluxDB + Grafana 快速搭建监控体系的详细步骤

    第一部分 Telegraf 部署和配置 Telegraf 是实现 数据采集 的工具.Telegraf 具有内存占用小的特点,通过插件系统开发人员可轻松添加支持其他服务的扩展. 在平台监控系统中,可以使 ...

  3. Prometheus+Grafana安装搭建

    介绍 Prometheus是由SoundCloud开发的开源监控报警系统和时序列数据库(TSDB).Prometheus使用Go语言开发,是Google BorgMon监控系统的开源版本. 2016年 ...

  4. Prometheus+Grafana+Altermanager搭建监控系统

    基本概念 Prometheus 时间序列化数据库,我的理解就是将数据打上标签,以时间维度存储.后面有机会在深入研究. Prometheus架构如下: Grafana Prometheus中存储的数据, ...

  5. Prometheus+Grafana+Alertmanager搭建全方位的监控告警系统

    prometheus安装和配置 prometheus组件介绍 1.Prometheus Server: 用于收集和存储时间序列数据. 2.Client Library: 客户端库,检测应用程序代码,当 ...

  6. Prometheus+Grafana监控-基于docker-compose搭建

    前言 Prometheus Prometheus 是有 SoundCloud 开发的开源监控系统和时序数据库,基于 Go 语言开发.通过基于 HTTP 的 pull 方式采集时序数据,通过服务发现或静 ...

  7. Prometheus+Grafana+kafka_exporter监控kafka

    Prometheus+Grafana+kafka_exporter搭建监控系统监控kafka 一.Prometheus+Grafana+kafka_exporter搭建监控系统监控kafka 1.1K ...

  8. SpringCloud微服务实战——搭建企业级开发框架(四十五):【微服务监控告警实现方式二】使用Actuator(Micrometer)+Prometheus+Grafana实现完整的微服务监控

      无论是使用SpringBootAdmin还是使用Prometheus+Grafana都离不开SpringBoot提供的核心组件Actuator.提到Actuator,又不得不提Micrometer ...

  9. Prometheus+Grafana搭建监控系统

    之前在业务中遇到服务器负载过高问题,由于没有监控,一直没发现,直到业务方反馈网站打开速度慢,才发现问题.这样显得开发很被动.所以是时候搭建一套监控系统了. 由于是业余时间自己捯饬,所以神马业务层面的监 ...

随机推荐

  1. 剑指offer-47:不用加减乘除做加法

    参考:https://www.cnblogs.com/zhangziqiu/archive/2011/03/30/ComputerCode.html <原码,反码,补码 详解> 题目描述 ...

  2. Cocos Creator 资源加载流程剖析【四】——额外流程(MD5 PIPE)

    当我们将游戏构建发布到web平台时,勾选Md5 Cache选项可以开启MD5 Pipe,它的作用是给构建后的资源加上md5后缀,避免浏览器的缓存导致部分资源不是最新,因为使用了md5后缀后,当资源内容 ...

  3. Web安全测试学习笔记-DVWA-盲注(使用sqlmap)

    之前的sql注入页面(https://www.cnblogs.com/sallyzhang/p/11843291.html),返回了查询结果和错误信息.而下面的页面,返回信息只有存在和不存在两种情况, ...

  4. 微店APP协议简要分析

    1.通过抓包软件charles进行抓包,点击微信收款后,抓包内容都是加密处理过  2.加载分析定位这些字段的加密函数. WDTNThorParameterProcessor HTTPBody:task ...

  5. 5、netty第四个例子,空闲检测handle

    netty可支持空闲检测的处理器,用于心态检测,当服务器端超出等待时间,没发生事件时,会触发handler中的方法 userEventTriggered. initializer import io. ...

  6. vim简单操作命令

    vim简单操作命令: 开启编辑:按“i”或者“Insert”键 退出编辑:“Esc”键 退出vim:“:q” 保存vim:“:w” 保存退出vim:“:wq” 不保存退出vim:“:q!” 查看当前系 ...

  7. TICK技术栈(五)Kapacitor安装及使用

    1.什么是Kapacitor? Kapacitor是InfluxData开源的数据处理引擎.它可以处理来自InfluxDB的流数据和批处理数据,并且用户可以用tickScript脚本来处理,监视和警报 ...

  8. MySQL数据库:多表连接查询

    多表连接查询 注意:使用连接技术建议将表经行重命名! # explain 检索连接是否达标 # 内连接 # 语法1 from 表1 inner join 表2 on 主键字段=外键字段 [where ...

  9. 关于spring boot上手的一点介绍

    在spring官网网址 https://spring.io/guides 下,有许多相关介绍,包括可以构建的例子程序. 使用intellij idea,可以通过新建 spring boot initi ...

  10. Markdown数学公式语法

    详细网址:Markdown数学公式语法