33

使用Thanos实现Prometheus指标联邦-Rancher Labs

 3 years ago
source link: https://blog.51cto.com/12462495/2511855
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

使用Thanos实现Prometheus指标联邦

本文来自Rancher Labs

Prometheus是CNCF中已经毕业的项目之一,主要用于监控和告警。在Kubernetes生态中,它是应用最为广泛的监控和告警工具之一。Rancher用户可以通过使用内置的监控堆栈来快速利用Prometheus。

Prometheus将其指标(metrics)作为时序数据库存储在本地磁盘上,因此Prometheus的本地存储会受到磁盘大小以及所能保留的指标数量的制约。但是,Prometheus允许与远程系统集成,通过_remotewrite和_remoteread指令读写指标,同时它还支持大量远程端点和存储集成

联邦可以实现可扩展的Prometheus监控设置,或者将相关的指标从一个服务的Prometheus拉取到另一个Prometheus中。

在本文中,我们将探索一个快速和简单的方式来设置Rancher监控远程端点与Thanos receive的集成。Thanos是一个开源的、高可用的Prometheus设置,有长期指标存储功能。你可以使用这个解决方案在所有的Prometheus实例中实现联邦指标,并允许中央Grafana dashboard在Thanos上运行。

重要提醒:作为指标联邦的一部分,项目/集群指标将不在Rancher管理平面内。此外,集群管理员必须确保建立适当的访问控制机制,以限制对该指标存储的访问。

安装Thanos

在本篇文章中,我们可以使用kube-thanos在Kubernetes集群上快速设置Thanos。

我们将需要以下Thanos组件:

  • Thanos存储gateway

  • Thanos接收器(receiver)

  • Thanos查询器(querier)

该解决方案如下所示:

                 +
Tenant's Premise | Provider Premise
                 |
                 |            +------------------------+
                 |            |                        |
                 |  +-------->+     Object Storage     |
                 |  |         |                        |
                 |  |         +-----------+------------+
                 |  |                     ^
                 |  | S3 API              | S3 API
                 |  |                     |
                 |  |         +-----------+------------+
                 |  |         |                        |       Store API
                 |  |         |  Thanos Store Gateway  +<-----------------------+
                 |  |         |                        |                        |
                 |  |         +------------------------+                        |
                 |  |                                                           |
                 |  +---------------------+                                     |
                 |                        |                                     |
+--------------+ |            +-----------+------------+              +---------+--------+
|              | | Remote     |                        |  Store API   |                  |
|  Prometheus  +------------->+     Thanos Receiver    +<-------------+  Thanos Querier  |
|              | | Write      |                        |              |                  |
+--------------+ |            +------------------------+              +---------+--------+
                 |                                                              ^
                 |                                                              |
+--------------+ |                                                              |
|              | |                PromQL                                        |
|    User      +----------------------------------------------------------------+
|              | |
+--------------+ |
                 +

来源:Thanos receive proposal

Thanos支持若干对象存储配置。我们将使用MinIO作为我们的对象存储。你需要在名为thanos-objectStorage的secret中定义对象存储,它需要在你的Thanos deployment命名空间中。

thanos-config.yaml如下所示:

type: s3
config:
  bucket: thanos
  endpoint: ${minio-endpoint}
  access_key: ${minio-access-key}
  secret_key: ${minio-secret-key}
  insecure: true

你可以按照以下方式创建secret:

kubectl create secret generic thanos-objectstorage --from-file=thanos.yaml="$PATH_TO_CONFIG"/thanos-config.yaml

配置Rancher监控

与Rancher监控operator打包的Prometheus版本已经支持remote_readremote_write集成。

Thanos receive endpoint的额外设置可以通过高级选项传递,如下所示:

使用Thanos实现Prometheus指标联邦

我们需要按照Prometheus remote_write规范的要求,指定一个唯一的名字。

# The name will be used in metrics and logging in place of a generated value to help users distinguish between
# remote write configs.
[ name: <string> ]

你完成了监控的部署之后,你应该可以使用Thanos查询器查看你的指标。

使用Thanos实现Prometheus指标联邦

已存储的指标也将在对象存储中获取。

使用Thanos实现Prometheus指标联邦

由于所有的集群指标在这个Thanos安装中都是可用的,所以工作负载的所有者需要确保对工作负载和指标的访问是安全的。

使用Rancher监控(即Prometheus)和Thanos接收器中的远程读写功能,你可以通过几个简单的步骤就能够实现长期指标存储和多个集群指标的全局视图。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK