Prometheus+Grafana监控部署

部署使用的系统为Ubuntu18.04,使用vagrant安装BOX后部署。

官方架构图:

从架构图中可以看到,我们先前验证的node_exporter属于jobs/exporter部分,称之为exporter导出器,是Prometheus主要的指标来源。
Prometheus Server是服务核心组件,存储使用时序数据库TSDB将数据保存在硬盘上,由于官方对SSD做了专门的优化,所以使用SSD性能会更优。
配置方式包含多种,可以直接在写在yaml文件中,但如果配置较长也可以写入其他文件并启用文件发现(file_sd)功能让其自行侦听配置文件变化,甚至可以使用consul或者kubernetes这样的服务发现来动态更新配置以适应频繁的节点变更。
Prometheus使用pull模型从节点暴露出来的端口拉取配置,这相比push方式更容易避免节点异常带来的干扰和繁琐的工作。
pushgateway类似于一个中转站,Prometheus的server端只会使用pull方式拉取数据,但是某些节点因为某些原因只能使用push方式推送数据,那么它就是用来接收push而来的数据并暴露给Prometheus的server拉取的中转站。
Prometheus支持告警系统,自带的alertmanager可以通过在配置文件中添加规则的方式,计算并发出警报,它支持多种发送方式比如pagerduty、Email等等。
对于已经存储的历史数据,Prometheus提供了PromQL语言进行查询,并自带了一个简易的UI界面,可以在界面上进行查询、绘图、查看配置、告警等等。

架构图中,Grafana等其他API客户端可以通过PromQL查询语言查询Prometheus中存储的数据。在这里,大部分用户喜欢将Grafana与Prometheus配合使用,因为Prometheus自带的UI界面太过简陋,而Grafana提供的界面非常的美观,且可以长期保留

链接:https://www.jianshu.com/p/413fd42ae660

Prometheus的官方下载地址为 https://prometheus.io/download/

1、下载并运行最新版的node_exporter 

配置参考:https://blog.csdn.net/weixin_44723434/article/details/89237202

sudo wget https://github.com/prometheus/node_exporter/releases/download/v0.17.0/node_exporter-0.17.0.linux-amd64.tar.gz
sudo tar -zxvf node_exporter-0.17.0.linux-amd64.tar.gz
cd node_exporter-0.17.0.linux-amd64
sudo ./node_exporter

使用IP+Port 访问检查是否启动正常,端口冲突时可以在

我们也可以自行编写代码访问这个接口,匹配出想要的指标和值即可

2、Prometheus下载安装

sudo wget https://github.com/prometheus/prometheus/releases/download/v2.6.0/prometheus-2.6.0.linux-amd64.tar.gz
sudo tar -zxvf prometheus-2.6.0.linux-amd64.tar.gz
cd prometheus-2.6.0.linux-amd64/

编辑配置文件sudo vim prometheus.yml在scrape_configs栏添加如下配置

  - job_name: "node"
    static_configs:
    - targets: ["localhost:9100"]

配置文件示例:


#my global config
global:
  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  #scrape_timeout is set to the global default (10s).

#Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets:
      #- alertmanager:9093

#Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  #- "first_rules.yml"
  #- "second_rules.yml"

#A scrape configuration containing exactly one endpoint to scrape:
#Here it's Prometheus itself.
scrape_configs:
  #The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'

    #metrics_path defaults to '/metrics'
    #scheme defaults to 'http'.

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


  - job_name: "node"
    static_configs:
    - targets: ["localhost:9100"]

使用   sudo ./prometheus  启动,然后使用IP+端口访问  ,需要注意端口冲突

使用http://IP+端口/targets 查看后台应用

3、安装Grafana, 使用http://IP+端口 登录

官网:https://grafana.com/docs/grafana/latest/installation/rpm/

Grafana是一个跨平台的开源的度量分析和可视化工具,可以通过将采集的数据查询然后可视化的展示,并及时通知。它主要有以下六大特点:
1、展示方式:快速灵活的客户端图表,面板插件有许多不同方式的可视化指标和日志,官方库中具有丰富的仪表盘插件,比如热图、折线图、图表等多种展示方式;
2、数据源:Graphite,InfluxDB,OpenTSDB,Prometheus,Elasticsearch,CloudWatch和KairosDB等;
3、通知提醒:以可视方式定义最重要指标的警报规则,Grafana将不断计算并发送通知,在数据达到阈值时通过Slack、PagerDuty等获得通知;
4、混合展示:在同一图表中混合使用不同的数据源,可以基于每个查询指定数据源,甚至自定义数据源;
5、注释:使用来自不同数据源的丰富事件注释图表,将鼠标悬停在事件上会显示完整的事件元数据和标记;
6、过滤器:Ad-hoc过滤器允许动态创建新的键/值过滤器,这些过滤器会自动应用于使用该数据源的所有查询。

官网下载链接:

Ubuntu and Debian(64 Bit)SHA256: 756eca8e7f1d3d8eb1bec4d516483778fb49868a9917b16d923e600d24ea7e45

sudo apt-get install -y adduser libfontconfig1
wget https://dl.grafana.com/oss/release/grafana_7.1.5_amd64.deb
sudo dpkg -i grafana_7.1.5_amd64.deb

Read the Ubuntu / Debian installation guide for more information. We also provide an APT package repository.

Standalone Linux Binaries(64 Bit)SHA256: 1210e29bcd158a7a7fc09adb7b69afb8730c0d34ec5356a7c346135efce03450

wget https://dl.grafana.com/oss/release/grafana-7.1.5.linux-amd64.tar.gz
tar -zxvf grafana-7.1.5.linux-amd64.tar.gz

Red Hat, CentOS, RHEL, and Fedora(64 Bit)SHA256: 1fe585db9e7d79cd93231f737ec7dd1bd7e53abca5ea808ecea6c4f697a1a883

wget https://dl.grafana.com/oss/release/grafana-7.1.5-1.x86_64.rpm
sudo yum install grafana-7.1.5-1.x86_64.rpm

OpenSUSE and SUSE

wget https://dl.grafana.com/oss/release/grafana-7.1.5-1.x86_64.rpm
sudo rpm -i --nodeps grafana-7.1.5-1.x86_64.rpm

初始密码admin/admin

https://blog.csdn.net/Sagitarioo/article/details/102805852

https://www.cnblogs.com/imyalost/p/9873641.html

4、配置数据源

5、配置预警参数及任务

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值