k8s与监控--prometheus的远端存储

本文涉及的产品
容器服务 Serverless 版 ACK Serverless,317元额度 多规格
可观测监控 Prometheus 版,每月50GB免费额度
容器服务 Serverless 版 ACK Serverless,952元额度 多规格
简介: 前言 prometheus在容器云的领域实力毋庸置疑,越来越多的云原生组件直接提供prometheus的metrics接口,无需额外的exporter。所以采用prometheus作为整个集群的监控方案是合适的。

前言

prometheus在容器云的领域实力毋庸置疑,越来越多的云原生组件直接提供prometheus的metrics接口,无需额外的exporter。所以采用prometheus作为整个集群的监控方案是合适的。但是metrics的存储这块,prometheus提供了本地 存储,即tsdb时序数据库。本地存储的优势就是运维简单,启动prometheus只需一个命令,下面两个启动参数指定了数据路径和保存时间。

  • storage.tsdb.path: tsdb数据库路径,默认 data/
  • storage.tsdb.retention: 数据保留时间,默认15天

缺点就是无法大量的metrics持久化。当然prometheus2.0以后压缩数据能力得到了很大的提升。
为了解决单节点存储的限制,prometheus没有自己实现集群存储,而是提供了远程读写的接口,让用户自己选择合适的时序数据库来实现prometheus的扩展性。
prometheus通过下面两张方式来实现与其他的远端存储系统对接

  • Prometheus 按照标准的格式将metrics写到远端存储
  • prometheus 按照标准格式从远端的url来读取metrics

aa8ac42af03bafbd8a47de4201fcead9bd31e444

下面我将重点剖析远端存储的方案

远端存储方案

配置文件

远程写

# The URL of the endpoint to send samples to.
url: <string>

# Timeout for requests to the remote write endpoint.
[ remote_timeout: <duration> | default = 30s ]

# List of remote write relabel configurations.
write_relabel_configs:
 [ - <relabel_config> ... ]

# Sets the `Authorization` header on every remote write request with the # configured username and password. # password and password_file are mutually exclusive.
basic_auth:
 [ username: <string> ]
 [ password: <string> ]
 [ password_file: <string> ]

# Sets the `Authorization` header on every remote write request with # the configured bearer token. It is mutually exclusive with `bearer_token_file`.
[ bearer_token: <string> ]

# Sets the `Authorization` header on every remote write request with the bearer token # read from the configured file. It is mutually exclusive with `bearer_token`.
[ bearer_token_file: /path/to/bearer/token/file ]

# Configures the remote write request's TLS settings.
tls_config:
 [ <tls_config> ]

# Optional proxy URL.
[ proxy_url: <string> ]

# Configures the queue used to write to remote storage.
queue_config:
 # Number of samples to buffer per shard before we start dropping them.
 [ capacity: <int> | default = 100000 ]
 # Maximum number of shards, i.e. amount of concurrency.
 [ max_shards: <int> | default = 1000 ]
 # Maximum number of samples per send.
 [ max_samples_per_send: <int> | default = 100]
 # Maximum time a sample will wait in buffer.
 [ batch_send_deadline: <duration> | default = 5s ]
 # Maximum number of times to retry a batch on recoverable errors.
 [ max_retries: <int> | default = 10 ]
 # Initial retry delay. Gets doubled for every retry.
 [ min_backoff: <duration> | default = 30ms ]
 # Maximum retry delay.
 [ max_backoff: <duration> | default = 100ms ]

远程读

# The URL of the endpoint to query from.
url: <string>

# An optional list of equality matchers which have to be # present in a selector to query the remote read endpoint.
required_matchers:
 [ <labelname>: <labelvalue> ... ]

# Timeout for requests to the remote read endpoint.
[ remote_timeout: <duration> | default = 1m ]

# Whether reads should be made for queries for time ranges that # the local storage should have complete data for.
[ read_recent: <boolean> | default = false ]

# Sets the `Authorization` header on every remote read request with the # configured username and password. # password and password_file are mutually exclusive.
basic_auth:
 [ username: <string> ]
 [ password: <string> ]
 [ password_file: <string> ]

# Sets the `Authorization` header on every remote read request with # the configured bearer token. It is mutually exclusive with `bearer_token_file`.
[ bearer_token: <string> ]

# Sets the `Authorization` header on every remote read request with the bearer token # read from the configured file. It is mutually exclusive with `bearer_token`.
[ bearer_token_file: /path/to/bearer/token/file ]

# Configures the remote read request's TLS settings.
tls_config:
 [ <tls_config> ]

# Optional proxy URL.
[ proxy_url: <string> ]

PS

  • 远程写配置中的write_relabel_configs 该配置项,充分利用了prometheus强大的relabel的功能。可以过滤需要写到远端存储的metrics。

例如:选择指定的metrics。

remote_write:
 - url: "http://prometheus-remote-storage-adapter-svc:9201/write"  write_relabel_configs:
 - action: keep
 source_labels: [__name__]
 regex: container_network_receive_bytes_total|container_network_receive_packets_dropped_total
  • global配置中external_labels,在prometheus的联邦和远程读写的可以考虑设置该配置项,从而区分各个集群。
global: scrape_interval: 20s  # The labels to add to any time series or alerts when communicating with  # external systems (federation, remote storage, Alertmanager). external_labels: cid: '9'

已有的远端存储的方案

现在社区已经实现了以下的远程存储方案

  • AppOptics: write
  • Chronix: write
  • Cortex: read and write
  • CrateDB: read and write
  • Elasticsearch: write
  • Gnocchi: write
  • Graphite: write
  • InfluxDB: read and write
  • OpenTSDB: write
  • PostgreSQL/TimescaleDB: read and write
  • SignalFx: write

上面有些存储是只支持写的。其实研读源码,能否支持远程读,
取决于该存储是否支持正则表达式的查询匹配。具体实现下一节,将会解读一下prometheus-postgresql-adapter和如何实现一个自己的adapter。
同时支持远程读写的

  • Cortex来源于weave公司,整个架构对prometheus做了上层的封装,用到了很多组件。稍微复杂。
  • InfluxDB 开源版不支持集群。对于metrics量比较大的,写入压力大,然后influxdb-relay方案并不是真正的高可用。当然饿了么开源了influxdb-proxy,有兴趣的可以尝试一下。
  • CrateDB 基于es。具体了解不多
  • TimescaleDB 个人比较中意该方案。传统运维对pgsql熟悉度高,运维靠谱。目前支持 streaming replication方案支持高可用。

后记

其实如果收集的metrics用于数据分析,可以考虑clickhouse数据库,集群方案和写入性能以及支持远程读写。这块正在研究中。待有了一定成果以后再专门写一篇文章解读。目前我们的持久化方案准备用TimescaleDB。

本文转自SegmentFault-k8s与监控--prometheus的远端存储

相关实践学习
通过Ingress进行灰度发布
本场景您将运行一个简单的应用,部署一个新的应用用于新的发布,并通过Ingress能力实现灰度发布。
容器应用与集群管理
欢迎来到《容器应用与集群管理》课程,本课程是“云原生容器Clouder认证“系列中的第二阶段。课程将向您介绍与容器集群相关的概念和技术,这些概念和技术可以帮助您了解阿里云容器服务ACK/ACK Serverless的使用。同时,本课程也会向您介绍可以采取的工具、方法和可操作步骤,以帮助您了解如何基于容器服务ACK Serverless构建和管理企业级应用。 学习完本课程后,您将能够: 掌握容器集群、容器编排的基本概念 掌握Kubernetes的基础概念及核心思想 掌握阿里云容器服务ACK/ACK Serverless概念及使用方法 基于容器服务ACK Serverless搭建和管理企业级网站应用
相关文章
|
13天前
|
Prometheus Kubernetes 监控
Prometheus 与 Kubernetes 的集成
【8月更文第29天】随着容器化应用的普及,Kubernetes 成为了管理这些应用的首选平台。为了有效地监控 Kubernetes 集群及其上的应用,Prometheus 提供了一个强大的监控解决方案。本文将详细介绍如何在 Kubernetes 集群中部署和配置 Prometheus,以便对容器化应用进行有效的监控。
30 1
|
13天前
|
存储 Kubernetes 容器
Kubernetes 存储选项:持久化卷与存储类
【8月更文第29天】随着容器化的普及,越来越多的应用程序需要持久化数据以保持状态信息。Kubernetes 提供了一套完整的解决方案来管理和配置持久化存储,包括持久卷 (Persistent Volume, PV)、持久卷声明 (Persistent Volume Claim, PVC) 和存储类 (StorageClass)。本文将详细介绍这些概念,并通过实际示例来演示如何在 Kubernetes 中配置存储。
33 1
|
23天前
|
Prometheus 监控 Cloud Native
【监控】prometheus传统环境监控告警常用配置
【监控】prometheus传统环境监控告警常用配置
【监控】prometheus传统环境监控告警常用配置
|
13天前
|
存储 Kubernetes 容器
k8s创建NFS动态存储
k8s创建NFS动态存储
|
13天前
|
存储 Prometheus 监控
Grafana 与 Prometheus 集成:打造高效监控系统
【8月更文第29天】在现代软件开发和运维领域,监控系统已成为不可或缺的一部分。Prometheus 和 Grafana 作为两个非常流行且互补的开源工具,可以协同工作来构建强大的实时监控解决方案。Prometheus 负责收集和存储时间序列数据,而 Grafana 则提供直观的数据可视化功能。本文将详细介绍如何集成这两个工具,构建一个高效、灵活的监控系统。
51 1
|
16天前
|
Prometheus 监控 Cloud Native
使用Prometheus搞定微服务监控
使用Prometheus搞定微服务监控
使用Prometheus搞定微服务监控
|
8天前
|
运维 Kubernetes 监控
Loki+Promtail+Grafana监控K8s日志
综上,Loki+Promtail+Grafana 监控组合对于在 K8s 环境中优化日志管理至关重要,它不仅提供了强大且易于扩展的日志收集与汇总工具,还有可视化这些日志的能力。通过有效地使用这套工具,可以显著地提高对应用的运维监控能力和故障诊断效率。
17 0
|
13天前
|
存储 Prometheus 监控
Prometheus 存储方案与优化
【8月更文第29天】Prometheus 是一个流行的开源监控系统,它使用时间序列数据库来存储监控数据。Prometheus 的时间序列数据库是基于本地文件系统的,这种设计提供了高吞吐量的读写能力,但同时也带来了存储方面的挑战。本文将详细介绍 Prometheus 存储的工作原理,并提出一些优化策略以减少磁盘占用。
10 0
|
16天前
|
Prometheus 监控 Cloud Native
基于prometheus的微服务指标监控
基于prometheus的微服务指标监控
|
22天前
|
Prometheus 监控 Cloud Native
在 HBase 集群中,Prometheus 通常监控哪些类型的性能指标?
在 HBase 集群中,Prometheus 通常监控哪些类型的性能指标?