前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >Prometheus监控学习笔记之prometheus的远端存储

Prometheus监控学习笔记之prometheus的远端存储

作者头像
Jetpropelledsnake21
发布于 2019-03-08 02:45:13
发布于 2019-03-08 02:45:13
5.1K00
代码可运行
举报
文章被收录于专栏:JetpropelledSnakeJetpropelledSnake
运行总次数:0
代码可运行

0x00 概述

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

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

0x01 远端存储方案

配置文件

远程写

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
# 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 ]

远程读

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
# 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。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
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的联邦和远程读写的可以考虑设置该配置项,从而区分各个集群
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
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'

0x03 已有的远端存储的方案

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

  • 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方案支持高可用。

0x04 后记

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

参考

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019-02-25 ,如有侵权请联系 cloudcommunity@tencent.com 删除

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

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

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

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
缺少VCRUNTIME140_1.dll的解决方法
缺少VCRUNTIME140_1.dll与缺少VCRUNTIME140.dll是不同的
六四零
2020/08/05
21.8K3
缺少VCRUNTIME140_1.dll的解决方法
获取和分析Dump的几种工具简介[通俗易懂]
最近在进一步学习support技能的时候,了解到分析Dump的重要性,经过学习,做一些笔记。
全栈程序员站长
2022/11/11
18.7K1
获取和分析Dump的几种工具简介[通俗易懂]
Github无法访问的解决方法
git是一个版本控制工具,github是一个用 git 做版本控制的项目托管平台,是世界上最大的开放源代码社区。
Gnep@97
2023/08/10
4.9K0
Github无法访问的解决方法
rar压缩文件密码破解工具介绍
很多人会遇到这样一个情况,网上千辛万苦寻觅来的资源,下载完了,纸都准备好了,结果弹出输入密码!
编程思维
2022/10/12
3.7K0
rar压缩文件密码破解工具介绍
VSCode配置 c++ 环境(小白教程)「建议收藏」
选择完后,点击 Installation > applychange,等待安装完就ok
全栈程序员站长
2022/08/01
1.4K0
VSCode配置 c++ 环境(小白教程)「建议收藏」
petalinux版本_中央一号文件2019解读
这里主要根据UG1144文档,这两天成功安装使用了PetaLinux的最新版本2019.1
全栈程序员站长
2022/10/01
1.2K0
petalinux版本_中央一号文件2019解读
创建Windows 7虚拟机(workstation工具)
1.打开workstation 工具(这里是16pro版),单击”主页”中的“创建新的虚拟机”。
Miloce
2022/09/28
1.6K0
创建Windows 7虚拟机(workstation工具)
QT6.1.2下载和安装教程
Qt 自从5.15版本开始,对非商业版本(开源版本)不提供已经制作好的离线exe安装包,QT6.1.2版本需要在线下载安装。
全栈程序员站长
2022/08/29
5.4K0
QT6.1.2下载和安装教程
Windows环境配置
因为最近做桌面端开发 ,要用到Windows,在Macbook上安装的Windows,环境好不容易全都配好的,用一段时间空间就不够了,又得重装,一些好用的软件老是忘记名字所以就写个博客记录一下。
码客说
2020/05/09
2.3K0
WSA微软官方安装教程
Windows 11 版本号为 Build 22000.xxx 或更高版本。您的电脑硬件 BIOS/UEFI 支持虚拟化功能。
萌海无涯
2022/01/20
4.4K1
WSA微软官方安装教程
配置PDB符号文件服务
刚入职的小木,前不久刚刚解决了一次crash问题《Windbg分析程序崩溃实践》。小木没有松懈,继续进行项目代码和Debug技术的学习,同时也思考了一个问题“产品每隔一段时间就会发布新的版本,当出现Crash问题的时候得手动去拷贝响应版本的pdb文件到本机进行调试,有没有什么方式可以实现自动化呢?” 嗯,小木是一个合格的程序员,程序员就是致力于让重复的工作自动化。
河边一枝柳
2021/08/06
5780
WDK7600编译器环境配置
在X64纵横的年代.很多人都直接使用VS+WDK配套的环境去开发驱动了. 这样是好事.说明驱动开发更快捷了.但是你开发的驱动是不能兼容所有系统的. 如XP 很多人说XP已经淘汰了.兼容不兼容无所谓了.
IBinary
2020/06/09
1.9K0
WDK7600编译器环境配置
分享一款投屏映射软件
QtScrcpy是一款在Scrcpy的基础上新增功能的安卓手机投屏工具,可以通过USB连接到电脑,把手机屏幕投映到电脑,电脑还可以操作手机,它不需要root特权,不需要在手机安装任何东西。
keyi的猫
2022/04/22
1.5K0
分享一款投屏映射软件
windows11运行安卓apk应用
输入https://www.microsoft.com/store/productid/9p3395vx91nr,后面的下拉框选择 「slow」,点击「✓」按钮
华创信息技术
2022/05/28
3.4K0
windows11运行安卓apk应用
CoreHook:基于.NET Core运行时实现的Windows HOOK库
今天为大家介绍一款基于.NET Core运行时实现的Windows HOOK库,CoreHook。
FB客服
2019/06/18
1.8K0
Visual Studio 2019软件下载和安装教程
Microsoft Visual Studio 2019(简称VS)是美国微软公司的开发工具包系列产品。VS是一个基本完整的开发工具集,它包括了整个软件生命周期中所需要的大部分工具,如UML工具、代码管控工具、集成开发环境(IDE)等等。所写的目标代码适用于微软支持的所有平台,包括Microsoft Windows、Windows Mobile、Windows CE、.NET Framework、.NET Compact Framework和Microsoft Silverlight 及Windows Phone。
肉肉软件安装
2022/12/10
3.8K1
Visual Studio 2019软件下载和安装教程
OpenCV(c++)-1 安装和配置OpenCV4.4(Windows+visual studio 2019)
OpenCV是一个基于BSD许可(开源)发行的跨平台计算机视觉和机器学习软件库,可以运行在Linux、Windows、Android和Mac OS操作系统上。 [1] 它轻量级而且高效——由一系列 C 函数和少量 C++ 类构成,同时提供了Python、Ruby、MATLAB等语言的接口,实现了图像处理和计算机视觉方面的很多通用算法。 OpenCV用C++语言编写,它具有C ++,Python,Java和MATLAB接口,并支持Windows,Linux,Android和Mac OS,OpenCV主要倾向于实时视觉应用,并在可用时利用MMX和SSE指令, 如今也提供对于C#、Ch、Ruby,GO的支持。
程序员小涛
2020/12/03
3.7K0
OpenCV(c++)-1 安装和配置OpenCV4.4(Windows+visual studio 2019)
Modelsim SE 下载安装、注册详细教程「建议收藏」
[1] Modelsim SE版本的安装及使用方法 [2] 【FPGA——工具篇】:Modelsim SE-64 10.4下载、注册、安装过程
全栈程序员站长
2022/07/25
7.7K0
Modelsim SE 下载安装、注册详细教程「建议收藏」
office2016、office365和office其它版本JH[通俗易懂]
Win10系统中会预安装Office,但是没有给JH,网上给了各种解决方案,如JH码、KMS等方式JH。
全栈程序员站长
2022/09/09
2.4K0
office2016、office365和office其它版本JH[通俗易懂]
Visual Studio 2013软件下载和安装教程
Microsoft Visual Studio 2013(简称VS)是美国微软公司的开发工具包系列产品。VS是一个基本完整的开发工具集,它包括了整个软件生命周期中所需要的大部分工具,如UML工具、代码管控工具、集成开发环境(IDE)等等。所写的目标代码适用于微软支持的所有平台,包括Microsoft Windows、Windows Mobile、Windows CE、.NET Framework、.NET Compact Framework和Microsoft Silverlight 及Windows Phone。
肉肉软件安装
2022/12/10
11.1K1
Visual Studio 2013软件下载和安装教程
推荐阅读
相关推荐
缺少VCRUNTIME140_1.dll的解决方法
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验