prometheus和thanos集成方案

prometheus和thanos集成方案

公司新项目需要做服务器和微服务的指标监控,采用prometheus+thanos+grafana方案,这里记录一下prometheus如何与thanos无缝对接。

thanos prometheus下载

thanos官网地址:https://github.com/improbable-eng/thanos/releases
大家可以去thanos官网下适合自己的版本,此次试验我选择的是https://github.com/improbable-eng/thanos/releases/download/v0.6.0-rc.0/thanos-0.6.0-rc.0.linux-amd64.tar.gz

prometheus官网地址:https://prometheus.io/download/
为了此次实验,需要在prometheus官网下载2个组件,一个就是prometheus,还有一个就是node_exporter。
prometheus linux版本下载地址:https://github.com/prometheus/prometheus/releases/download/v2.11.1/prometheus-2.11.1.linux-amd64.tar.gz
node_exporter linux版本下载地址:https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz

prometheus安装与配置

下载好prometheus和node_exporter,用tar命令解压node_exporter-0.18.1.linux-amd64.tar.gzprometheus-2.11.1.linux-amd64.tar.gz
解压完毕,会生成node_exporter-0.18.1.linux-amd64和prometheus-2.11.1.linux-amd64俩个文件夹。
重命名node_exporter-0.18.1.linux-amd64 为node_exporter。
重命名prometheus-2.11.1.linux-amd64为prometheus。
cd进入prometheus文件夹,vim prometheus.yml,主要是在global:下面新增 external_labels:
monitor: 'monitor131’

这块主要是为了thanos 查询指标去重。
贴一下我的prometheus.yml文件

# 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).
  external_labels:
    monitor: 'monitor131'

# 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: ['10.10.20.131:19090','10.10.10.133:19090']
  - job_name: 'node'
    static_configs:
    - targets: ['10.10.20.131:9100','10.10.10.133:9100']

配置好prometheus.yml文件,就可以启动prometheus和node_exporter
prometheus启动命令:
nohup ./prometheus --config.file=prometheus.yml --web.listen-address=0.0.0.0:19090 --storage.tsdb.max-block-duration=2h --storage.tsdb.min-block-duration=2h --web.enable-lifecycle &
node_exporter启动命令:
nohup ./node_exporter &
这个时候prometheus就已经可以监控服务器的性能指标,打开web.listen-address里面配置的ip+port,我这里是http://10.10.20.131:19090/graph。

重复以上步骤,在10.10.10.133服务器再安装prometheus和node_exporter.
这样,我们就有2台服务器安装了prometheus和node_exporter.其中,133服务器的prometheus.yml的配置文件修改下
external_labels:
monitor: 'monitor133’

即可,其他配置与131一样即可。
在这里插入图片描述

thanos安装启动配置

thanos主要使用到sidecar和query,如果需要数据备份至云存储,store组件也得启动。
解压从官网下载的thanos-0.6.0-rc.0.linux-amd64.tar.gz,同理重命名为thanos。
thanos解压出来就一个thanos目录。启动sidecar和query即可使用。注意:需要安装在prometheus所在服务器。
sidecar启动命令:
nohup ./thanos sidecar --tsdb.path “/opt/idss/components/prometheus/data” --prometheus.url “http://localhost:19090” --http-address 0.0.0.0:19191 --grpc-address 0.0.0.0:19091&

query启动命令:
nohup ./thanos query --http-address “0.0.0.0:29090” --grpc-address 0.0.0.0:29091 --query.replica-label “monitor” --store “10.10.20.131:19091” --store “10.10.10.133:19091” &
在这里插入图片描述
当nohup.out日志显示adding new store to query storeset即表示query已经成功连上sidecar。

同样在133服务器也需要安装thanos。步骤操作相同,sidecar 和query启动命令也一样。

数据验证

此时我们的配置是131和133俩台服务器同时采集131和133各一份数据,在query启动命令参数中,我们配置的http端口是29090,我们可以打开其中一个queryweb ui
在这里插入图片描述
仔细看一下,thanos web ui其实和prometheus差不多,只不多在这里插入图片描述
这个单选框,默认勾选,意思是去重。
在这里插入图片描述
如果去掉勾选,则不去重,在这里插入图片描述
到这里,大家会发现俩台服务器我都启动了query命令,没错,俩个url都可以访问thanos web UI,并且指标数据是一致的,此时就可以价格nginx转发。grafana数据源指向nginx即可。

grafana配置thanos数据源

在这里插入图片描述

PS:thanos的store组件也是很实用的,备份数据至云存储,我这边实用的是腾讯云,
sidecar和store启动命令加个–objstore.config-file "bucket.yml"即可,其中bucket.yml为腾讯云连接的一些参数;如图:
在这里插入图片描述
启动store组件之后,隔一段时间,就会发现数据已经备份至腾讯云上。
在这里插入图片描述
如有不明白的,可以留言!

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值