前言

本文来自Prometheus官网手册 和 Prometheus简介

说明

Prometheus是一个监控平台,通过在监控目标上的HTTP端点来收集受监控目标的指标。本指南将向您展示如何使用Prometheus安装,配置和监控我们的第一个资源。 您将下载,安装并运行Prometheus。您还将下载并安装exporter,这些工具可在主机和服务上公开时间序列数据。我们的第一个exporter将是Prometheus本身,它提供了有关内存使用,垃圾收集等的各种主机级指标。

下载 Prometheus

在你的平台上下载最新的版本,然后解压它:

tar xvfz prometheus-*.tar.gz
cd prometheus-*

Prometheus服务器是一个称为prometheus(或Microsoft Windows上的prometheus.exe)的二进制文件。 我们可以运行二进制文件,并通过传递--help标志来查看有关其选项的帮助。

/usr/local/bin# ./prometheus --help
usage: prometheus [<flags>] The Prometheus monitoring server Flags:
#帮助
-h, --help Show context-sensitive help (also try --help-long and --help-man).
#版本
--version Show application version.
#配置文件
--config.file="prometheus.yml"
Prometheus configuration file path.
#监听端口
--web.listen-address="0.0.0.0:9090"
Address to listen on for UI, API, and telemetry.
#空闲连接的超时时间
--web.read-timeout=5m Maximum duration before timing out read of the request, and closing idle connections.
#最大连接数
--web.max-connections= Maximum number of simultaneous connections. #可从外部访问Prometheus的URL(例如,如果Prometheus是通过反向代理提供的)。 用于生成返回到Prometheus本身的相对和绝对链接。 如果URL包含路径部分,它将被用作Prometheus服务的所有HTTP端点的前缀。 如果省略,则会自动派生相关的URL组件。
--web.external-url=<URL> The URL under which Prometheus is externally reachable (for example, if Prometheus is served via a reverse proxy). Used for generating relative and absolute links back to
Prometheus itself. If the URL has a path portion, it will be used to prefix all HTTP endpoints served by Prometheus. If omitted, relevant URL components will be derived
automatically.
#内部路由的前缀。 默认为--web.external-url的路径。
--web.route-prefix=<path> Prefix for the internal routes of web endpoints. Defaults to path of --web.external-url.
#静态资源目录的路径,位于/ user
--web.user-assets=<path> Path to static asset directory, available at /user.
#启用是否通过HTTP请求重新加载
--web.enable-lifecycle Enable shutdown and reload via HTTP request.
#管理控制操作启用API端点
--web.enable-admin-api Enable API endpoints for admin control actions.
#模板目录的路径,位于/consoles
--web.console.templates="consoles"
Path to the console template directory, available at /consoles.
#控制台库目录的路径
--web.console.libraries="console_libraries"
Path to the console library directory.
#Prometheus实例页面的文档标题
--web.page-title="Prometheus Time Series Collection and Processing Server"
Document title of Prometheus instance.
#用于CORS来源的正则表达式。
--web.cors.origin=".*" Regex for CORS origin. It is fully anchored. Example: 'https?://(domain1|domain2)\.com'
#指标(数据)存储的基本路径
--storage.tsdb.path="data/"
Base path for metrics storage.
#将数据保留多长时间。 此标志已被弃用,请改用“ storage.tsdb.retention.time”。
--storage.tsdb.retention=STORAGE.TSDB.RETENTION
[DEPRECATED] How long to retain samples in storage. This flag has been deprecated, use "storage.tsdb.retention.time" instead.
#将数据保留多长时间。默认15天
--storage.tsdb.retention.time=STORAGE.TSDB.RETENTION.TIME
How long to retain samples in storage. When this flag is set it overrides "storage.tsdb.retention". If neither this flag nor "storage.tsdb.retention" nor
"storage.tsdb.retention.size" is set, the retention time defaults to 15d.
#可以为块存储的最大字节数。 支持的单位:KB,MB,GB,TB,PB。
--storage.tsdb.retention.size=STORAGE.TSDB.RETENTION.SIZE
[EXPERIMENTAL] Maximum number of bytes that can be stored for blocks. Units supported: KB, MB, GB, TB, PB. This flag is experimental and can be changed in future releases.
#不在数据目录中创建锁文件
--storage.tsdb.no-lockfile
Do not create lockfile in data directory.
#允许重叠的块,从而启用垂直压缩和垂直查询合并。
--storage.tsdb.allow-overlapping-blocks
[EXPERIMENTAL] Allow overlapping blocks, which in turn enables vertical compaction and vertical query merge.
#压缩tsdb WAL
--storage.tsdb.wal-compression
Compress the tsdb WAL.
#关闭或配置重新加载时等待刷写数据的时间
--storage.remote.flush-deadline=<duration>
How long to wait flushing sample on shutdown or config reload.
#在单个查询中通过远程读取接口返回的最大样本总数。 0表示没有限制。 对于流式响应类型,将忽略此限制。
--storage.remote.read-sample-limit=5e7
Maximum overall number of samples to return via the remote read interface, in a single query. means no limit. This limit is ignored for streamed response types.
#并发远程读取调用的最大数目。 0表示没有限制。
--storage.remote.read-concurrent-limit=
Maximum number of concurrent remote read calls. means no limit.
#用于流式传输远程读取响应类型的单个帧中的最大字节数。 请注意,客户端也可能会限制帧大小。 1MB为默认情况下由protobuf推荐
--storage.remote.read-max-bytes-in-frame=
Maximum number of bytes in a single frame for streaming remote read response types before marshalling. Note that client might have limit on frame size as well. 1MB as
recommended by protobuf by default.
#容忍中断以恢复警报“ for”状态的最长时间。
--rules.alert.for-outage-tolerance=1h
Max time to tolerate prometheus outage for restoring "for" state of alert.
#警报和恢复的“ for”状态之间的最短持续时间。 仅对于配置的“ for”时间大于宽限期的警报,才保持此状态。
--rules.alert.for-grace-period=10m
Minimum duration between alert and restored "for" state. This is maintained only for alerts with configured "for" time greater than grace period.
#将警报重新发送到Alertmanager之前等待的最短时间。
--rules.alert.resend-delay=1m
Minimum amount of time to wait before resending an alert to Alertmanager.
#等待的Alertmanager通知的队列容量。
--alertmanager.notification-queue-capacity=
The capacity of the queue for pending Alertmanager notifications.
#向Alertmanager发送警报的超时。
--alertmanager.timeout=10s
Timeout for sending alerts to Alertmanager.
#在表达式求值期间检索指标的最大回溯持续时间。
--query.lookback-delta=5m The maximum lookback duration for retrieving metrics during expression evaluations.
#最大查询时间。
--query.timeout=2m Maximum time a query may take before being aborted.
#最大查询并发数
--query.max-concurrency=
Maximum number of queries executed concurrently.
#单个查询可以加载到内存中的最大样本数。 请注意,如果查询尝试将更多的样本加载到内存中,则查询将失败,因此这也限制了查询可以返回的样本数。
      --query.max-samples=
Maximum number of samples a single query can load into memory. Note that queries will fail if they try to load more samples than this into memory, so this also limits the
number of samples a query can return.
#日志级别
--log.level=info Only log messages with the given severity or above. One of: [debug, info, warn, error]
#日志格式
--log.format=logfmt Output format of log messages. One of: [logfmt, json]

在启动Prometheus之前,让我们对其进行配置。

配置 Prometheus

Prometheus配置是YAML,Prometheus下载包里附带一个名为prometheus.yml的文件中的示例配置,这是一个很好的入门之处。我们删除了示例文件中的大部分注释,使其更简洁(注释是以#为前缀的行)。

global:
scrape_interval: 15s #抓取频率
scrape_timeout: 10s #抓取超时
evaluation_interval: 15s #评估规则评率 rule_files:
# - "first.rules"
# - "second.rules" scrape_configs:
- job_name: prometheus
static_configs:
- targets: ['localhost:9090']

示例配置文件中有三个配置块:global,rule_files和scrape_configs。

  • global:控制Prometheus服务器的全局配置。第一个是scrape_interval,它控制Prometheus抓取目标的频率,也可以为单个目标重写此值。在这种例子下,全局设置是每15s抓取一次。 evaluation_interval选项控制Prometheus评估规则的频率。 Prometheus使用规则创建新的时间序列并生成警报。
  • rule_files:Prometheus服务器加载的任何规则的位置。 现在我们没有规则。
  • scrape_configs:Prometheus监视的资源。 由于Prometheus还将自己的数据公开为HTTP端点,因此它可以抓取并监控自身的健康状况。 在默认配置中,有一个名为prometheus的作业,它会抓取Prometheus服务器公开的时间序列数据。 包含一个静态配置的目标,即端口9090上的localhost。Prometheus希望指标在/metrics路径上的目标上可用。 所以这个默认的工作是通过URL抓取:http//localhost:9090/metrics。返回的时间序列数据将详细说明Prometheus服务器的状态和性能。

有关配置选项的完整规范,请参阅配置文档

启动 Prometheus

要使用我们新创建的配置文件启动Prometheus,请切换到包含Prometheus二进制文件的目录并运行:

./prometheus --config.file = prometheus.yml

Prometheus启动后应该能够在http//localhost:9090浏览到状态页面,给它大约30秒的时间从自己的HTTP指标端点收集有关自己的数据。还可以通过导航到其自己的指标端点来验证是否正在提供有关自身的指标:http//localhost:9090/metrics

使用表达式浏览器

让我们试着看一下Prometheus收集的关于自己的一些数据。 要使用Prometheus的内置表达式浏览器,请导航到http//localhost:9090/graph并在“Graph”选项卡中选择“Console”视图。

Prometheus导出的一个度量标准称为promhttp_metric_handler_requests_total(Prometheus服务器已服务的/metrics请求的总数)。 继续并将其输入表达式控制台:

promhttp_metric_handler_requests_total

这应该返回许多不同的时间序列(以及为每个记录的最新值),所有时间序列都使用度量标准名称promhttp_metric_handler_requests_total,但具有不同的标签。 这些标签指定不同的请求状态。

如果我们只对导致HTTP代码200的请求感兴趣,我们可以使用此查询来检索该信息:

promhttp_metric_handler_requests_total{code=""}

要计算返回的时间序列总数,您可以写:

count(promhttp_metric_handler_requests_total)

有关表达式语言的更多信息,请参阅表达式语言文档

适用图表接口

要绘制表达式图表,请导航到http//localhost:9090/graph graph并使用“图表”选项卡。

例如,输入以下表达式来绘制在自我抓取的Prometheus中发生的返回状态代码200的每秒HTTP请求率:

rate(promhttp_metric_handler_requests_total{code=""}[1m])

您可以尝试使用图形范围参数和其他设置。

监控其他目标

仅从Prometheus那里收集指标并不能很好地反映Prometheus的能力。 为了更好地了解Prometheus可以做什么,我们建议您浏览有关其他exporter的文档。 使用node exporter指南监控Linux或macOS主机指标是一个很好的起点。

总结

在本指南中,您安装了Prometheus,配置了Prometheus实例来监视资源,并学习了在Prometheus表达式浏览器中处理时间序列数据的一些基础知识。 要继续了解Prometheus,请查看概述,了解接下来要探索的内容。

Prometheus学习系列(二)之Prometheus FIRST STEPS的更多相关文章

  1. prometheus学习系列二: Prometheus安装

    下载 在prometheus的官网的download页面,可以找到prometheus的下载二进制包. [root@node00 src]# cd /usr/src/ [root@node00 src ...

  2. prometheus学习系列十一: Prometheus和AlertManager的高可用

    前面的系列中, prometheus和alertmanager都是单机部署的,会有单机宕机导致系统不可用情况发生.本文主要介绍下prometheus和alertmanager的高可用方案. 服务的高可 ...

  3. prometheus学习系列十一: Prometheus 安全

    prometheus安全 我们这里说的安全主要是基本认证和https2种, 目前这2种安全在prometheus中都没有的, 需要借助第三方软件实现, 这里以nginx为例. 基本认证 配置基本认证 ...

  4. prometheus学习系列十一: Prometheus pushgateway的使用

    由于网络问题或者安全问题,可能我们的数据无法直接暴露出一个entrypoint 给prometheus采集. 这个时候可能就需要一个pushgateway来作为中间者完成中转工作.  promethe ...

  5. prometheus学习系列九: Prometheus AlertManager使用

    在Prometheus的报警系统中,是分为2个部分的, 规则是配置是在prometheus中的, prometheus组件完成报警推送给alertmanager的, alertmanager然后管理这 ...

  6. prometheus学习系列五: Prometheus配置文件

    在prometheus监控系统,prometheus的职责是采集,查询和存储和推送报警到alertmanager.本文主要介绍下prometheus的配置文件. 全局配置文件简介 默认配置文件 [ro ...

  7. prometheus学习系列十一: Prometheus exporter详解

    exporter详解 前面的系列中,我们在主机上面安装了node_exporter程序,该程序对外暴露一个用于获取当前监控样本数据的http的访问地址, 这个的一个程序成为exporter,Expor ...

  8. prometheus学习系列十一: Prometheus 采集器的编写

    在前面的文章已经写了官方的几个exporter的使用了. 在实际使用环境中,我们可能需要收集一些自定义的数据, 这个时候我们一般是需要自己编写采集器的. 快速入门编写一个入门的demo 编写代码 fr ...

  9. prometheus学习系列十一: Prometheus 报警规则配置

    prometheus监控系统的的报警规则是在prometheus这个组件完成配置的. prometheus支持2种类型的规则,记录规则和报警规则, 记录规则主要是为了简写报警规则和提高规则复用的, 报 ...

  10. prometheus学习系列十: Prometheus AlertManager配置文件说明

    alertmanager配置文件说明 alertmanager是通过命令行标记和配置文件配置的,命令行标记配置不可变的系统参数,配置文件定义抑制规则.通知路由和通知接收器.可以通过官方提供的routi ...

随机推荐

  1. elastic search(es)安装

    全文搜索属于最常见的需求,开源的 Elasticsearch (以下简称 Elastic)是目前全文搜索引擎的首选. 它可以快速地储存.搜索和分析海量数据.维基百科.Stack Overflow.Gi ...

  2. 2019-2020-11 20199304 《Linux内核原理与分析》 第十一周作业

    缓冲区溢出漏洞实验 一.简介 缓冲区溢出是指程序试图向缓冲区写入超出预分配固定长度数据的情况.这一漏洞可以被恶意用户利用来改变程序的流控制,甚至执行代码的任意片段.这一漏洞的出现是由于数据缓冲器和返回 ...

  3. 华为鲁勇:5G+云+AI三大核心引擎将驱动广州数字经济发展

    [摘要] 华为云将携手广州政企,全面释放 5G+云+AI新动能,推动广州步入高质量发展新阶段. [中国,广州] 广州是一座多样化的城市,在历史上被誉为千年的商都,现在,广州也在持续的开放.融合.与时俱 ...

  4. Python一秒搭建ftp服务器,帮助你在局域网共享文件

    "老板 来碗面" "要啥面?" "内牛满面.." 最近项目上的事情弄得人心累,本来是帮着兄弟项目写套入口代码,搞着搞着就被拉着入坑了.搞开发 ...

  5. Frida用法之函数操作

    Frida接口功能介绍   Frida是个so级别的hook框架,它可以帮助开发.安全人员对指定的进程的so模块进行分析.它主要提供了功能简单的Python接口和功能丰富的JS接口,使得hook函数和 ...

  6. HDU 2896病毒侵袭

    当太阳的光辉逐渐被月亮遮蔽,世界失去了光明,大地迎来最黑暗的时刻....在这样的时刻,人们却异常兴奋——我们能在有生之年看到500年一遇的世界奇观,那是多么幸福的事儿啊~~ 但网路上总有那么些网站,开 ...

  7. 洛谷 题解 P2312 【解方程】

    Problem P2312 [解方程] >>> record 用时: 1166ms 空间: 780KB(0.76MB) 代码长度: 2.95KB 提交记录: R9909587 > ...

  8. Python网络爬虫入门实战(爬取最近7天的天气以及最高/最低气温)

    _ 前言 本文文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者: Bo_wen   最近两天学习了一下python,并自己写了一个 ...

  9. unity3d 柏林噪声 PerlinNoise 规律 算法

    测试 每个小数值取100次 print(0.1); LaTest3(0.1f, 0.1f); print("Max:" + La.Max() + "|Min:" ...

  10. 小白学 Python 爬虫(20):Xpath 进阶

    人生苦短,我用 Python 前文传送门: 小白学 Python 爬虫(1):开篇 小白学 Python 爬虫(2):前置准备(一)基本类库的安装 小白学 Python 爬虫(3):前置准备(二)Li ...