前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Prometheus入门+grafana集成 原

Prometheus入门+grafana集成 原

作者头像
阿dai学长
发布2019-04-03 10:06:28
8070
发布2019-04-03 10:06:28
举报
文章被收录于专栏:阿dai_linux阿dai_linux

开始使用Prometheus

代码语言:javascript
复制
$ systemctl start prometheus
$ netstat -lntp
tcp6       0      0 :::9090                 :::*                    LISTEN      19824/./prometheus  

在浏览器访问:http://ip:9090/graph 。Prometheus会把自身作为一个项目进行自监控,查看收集到监控项:http://172.16.180.129:9090/metrics (如果是首次启动,需要等待30s左右的时间)

使用内置表达式查看数据

地址:http://ip:9090/graph

Prometheus内置监控项 prometheus_target_interval_length_seconds ,将该监控项直接输入console查询,可获取数据:

![image-20190322132500188](/Users/adai/Library/Application Support/typora-user-images/image-20190322132500188.png)

使用prometheus监控服务器

上面用Prometheus本身的数据简单演示了监控数据的查询,这里我们用一个监控服务器状态的例子来更加直观说明。

为监控服务器CPU、内存、磁盘、I/O等信息,首先需要安装node_exporter。node_exporter的作用是用于机器系统数据收集。

安装node_exporter

node_exporter也是用Golang实现,直接使用预编译的二进制文件部署,开箱即用。

代码语言:javascript
复制
$ cd /home/prometheus && wget https://github.com/prometheus/node_exporter/releases/download/v0.17.0/node_exporter-0.17.0.linux-amd64.tar.gz
$ tar zxvf node_exporter-0.17.0.linux-amd64.tar.gz 
$ mv node_exporter-0.17.0.linux-amd64 /usr/local/prometheus/node_exporter
  • 创建systemd服务 $ vim /usr/lib/systemd/system/node_exporter.service [Unit] Description=node_exporter After=network.target [Service] Type=simple User=prometheus ExecStart=/usr/local/prometheus/node_exporter/node_exporter Restart=on-failure [Install] WantedBy=multi-user.target
  • 启动node_exporter $ systemctl start node_exporter $netstat -lntp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp6 0 0 :::9100 :::* LISTEN 24126/node_exporter
  • 修改prometheus.yml,加入下面的监控目标(node_exporter默认的抓取地址为http://ip:9100) - job_name: 'linux' static_configs: - targets: ['localhost:9100'] labels: instance: node1

说明:prometheus.yml中一共定义了两个监控,一个是监控prometheus自身服务,另一个是监控Linux服务器。

这里给一个完整示例:

代码语言:javascript
复制
scrape_configs:

  - job_name: 'prometheus'
    static_configs:
      - targets: ['localhost:9090']

  - job_name: 'linux'
    static_configs:
      - targets: ['localhost:9100']
        labels:
          instance: node1
  • 重启prometheus服务 $ systemctl restart prometheus
  • 在Prometheus Web查看监控的目标:访问Prometheus Web,在Status->Targets页面下,我们可以看到我们配置的两个Target(linux和prometheus),它们的State为UP。
  • 查看memory使用情况 ![image-20190322134529082](/Users/adai/Library/Application Support/typora-user-images/image-20190322134529082.png)

Prometheus Web界面自带的图表是非常基础的,比较适合用来做测试。如果要构建强大的Dashboard,还是需要更加专业的工具才行。接下来我们将使用Grafana来对Prometheus采集到的数据进行可视化展示。

prometheus集成grafana

在Grafana中添加Prometheus数据源:Configuration——DataSource——"add new DataSource"——Prometheus

  • http
  • 上述配置完成后需要导入node-exporter-server-metrics 的数据模板到grafana,两种导入方法:
    • 通过url导入:grafana——菜单栏加号➕——import—— 输入URL https://grafana.com/dashboards/405 —— 导入——Options (Name、Folder、Prometheus) —— import
    • 下载后导入:grafana——菜单栏加号➕——import—— 输入 下载 好的json文件 ——import

    完成上述操作后即可看到node-exporter采集的数据。

  • 在Dashboards上选Node Exporter Server Metrics模板,就可以看到被监控服务器的CPU, 内存, 磁盘等统计信息。
  • 在Dashboards上选Prometheus Status模板,查看Prometheus各项指标数据。

(adsbygoogle = window.adsbygoogle || []).push({});

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 开始使用Prometheus
  • 使用内置表达式查看数据
  • 使用prometheus监控服务器
    • 安装node_exporter
    • prometheus集成grafana
    相关产品与服务
    Prometheus 监控服务
    Prometheus 监控服务(TencentCloud Managed Service for Prometheus,TMP)是基于开源 Prometheus 构建的高可用、全托管的服务,与腾讯云容器服务(TKE)高度集成,兼容开源生态丰富多样的应用组件,结合腾讯云可观测平台-告警管理和 Prometheus Alertmanager 能力,为您提供免搭建的高效运维能力,减少开发及运维成本。
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档