prometheus详解1

本文详细介绍了如何启动、重载配置和优雅关闭Prometheus进程,包括启动参数的解析,如使用web.enable-lifecycle功能通过HTTP操作,以及如何调整时区。还展示了如何通过API进行健康检查和数据查询示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、start、reload 与 shutdown

1、启动prometheus 进程

nohup ./prometheus --config.file=prometheus.yml > prometheus.log  2>&1 &

2、重载prometheus配置文件(reload)

kill -s SIGHUP <PID>

3、优雅的shutdown一个prometheus 进程实例

kill -s SIGTERM <PID>

二、 prometheus 启动参数详解

选项默认值描述
-h --help帮助
–version打印版本
–config.fileprometheus.yaml配置文件路径,主要是配置抓取的endpoint的配置,即prometheus.yaml配置文件
–web.listen-address0.0.0.0:9090监听端口即web UI 端监听端口和 API端监听端口
–web.enable-lifecyclefalse启用通过http来reload配置文件和shutdown服务的功能
–web.enable-admin-apifalse启用HTTP API管理控制
–web.page-titlePrometheus Time Series Collection and Processing Serverprometheus 服务实例的title
–web.console.templatesconsolesconsole template(管理端静态页面路径)
–query-timout2m一次查询的最大超时时间,默认2分钟(2m),只适用于server mode下
–query.max-concurrency20最大并发查询数量,默认20,只适用于server mode下 超出的并发数量会怎么样?
–log.levelinfo日志等级,默认info,可选值为[debug,info,warn,error]
–log.formatlogfmt日志格式,默认logfmt 可选值[logfmt,json]

三、实践

1、–web.enable-lifecycle

启用通过http来reload配置文件和shutdown服务的功能

# reload配置文件,并不会重启服务
 curl -X PUT http://10.240.184.81:9090/-/reload
 # shutdown服务
 curl -X PUT http://10.240.184.81:9090/-/quit

2、–web.page-title

默认值 Prometheus Time Series Collection and Processing Server
在这里插入图片描述
可以通过设置 –web.page-title=hello改成 hello
在这里插入图片描述

3、–web.enable-admin-api 启用HTTP API管理控制

[kyzjj@yyzc-zjjcs04 ~]$ curl -X GET  http://10.240.184.81:9090/-/healthy
Prometheus Server is Healthy.
[kyzjj@yyzc-zjjcs04 ~]$
[kyzjj@yyzc-zjjcs04 ~]$ curl -X GET  http://10.240.184.81:9090/-/ready
Prometheus Server is Ready.
[kyzjj@yyzc-zjjcs04 ~]$ curl -X GET  http://10.240.184.81:9090/api/v1/query?query=node_filesystem_files_free
{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"node_filesystem_files_free","device":"/dev/mapper/vg_app-lv_kyzjj","fstype":"xfs","instance":"localhost:9100","job":"prometheus---node","mountpoint":"/kyzjj"},"value":[1709356667.786,"20940287"]},{"metric":{"__name__":"node_filesystem_files_free","device":"/dev/mapper/vg_root-lv_root","fstype":"xfs","instance":"localhost:9100","job":"prometheus---node","mountpoint":"/"},"value":[1709356667.786,"15433370"]},{"metric":{"__name__":"node_filesystem_files_free","device":"/dev/mapper/vg_root-lv_tmp","fstype":"xfs","instance":"localhost:9100","job":"prometheus---node","mountpoint":"/tmp"},"value":[1709356667.786,"10485744"]},{"metric":{"__name__":"node_filesystem_files_free","device":"/dev/vda1","fstype":"xfs","instance":"localhost:9100","job":"prometheus---node","mountpoint":"/boot"},"value":[1709356667.786,"1048246"]},{"metric":{"__name__":"node_filesystem_files_free","device":"rootfs","fstype":"rootfs","instance":"localhost:9100","job":"prometheus---node","mountpoint":"/"},"value":[1709356667.786,"15433370"]},{"metric":{"__name__":"node_filesystem_files_free","device":"tmpfs","fstype":"tmpfs","instance":"localhost:9100","job":"prometheus---node","mountpoint":"/run"},"value":[1709356667.786,"483795"]},{"metric":{"__name__":"node_filesystem_files_free","device":"tmpfs","fstype":"tmpfs","instance":"localhost:9100","job":"prometheus---node","mountpoint":"/run/user/0"},"value":[1709356667.786,"485287"]},{"metric":{"__name__":"node_filesystem_files_free","device":"tmpfs","fstype":"tmpfs","instance":"localhost:9100","job":"prometheus---node","mountpoint":"/run/user/2411"},"value":[1709356667.786,"485285"]},{"metric":{"__name__":"node_filesystem_files_free","device":"tmpfs","fstype":"tmpfs","instance":"localhost:9100","job":"prometheus---node","mountpoint":"/run/user/370"},"value":[1709356667.786,"485287"]}]}}[kyzjj@yyzc-zjjcs04 ~]

4、使用本地时区

prometheus默认使用UTC+0时区,但是中国使用东八区时区即UTC+8,可以设置使用本地时区,设置方式如下:
在这里插入图片描述

<think>好的,用户想详细了解Prometheus监控系统,包括架构、配置和使用教程。我需要先回忆Prometheus的核心组件和工作原理。首先,Prometheus的主要架构包括Server、Client Libraries、Pushgateway、Exporters、Alertmanager以及服务发现等部分。 用户提到的引用中提到了官方架构图,需要确保在回答中涵盖这些组件。引用[1]提到Prometheus是一个开源的监控与时间序列数据库系统,引用[2]提到了服务发现方法和Pushgateway,引用[3]则指向了中文技术文档,可能需要参考其中的时间序列数据部分。 接下来,需要分块介绍架构。首先从Server开始,解释其抓取和存储机制。然后说明Client Libraries和Exporters的作用,比如Node Exporter。Pushgateway用于短生命周期的任务,这点需要强调。Alertmanager处理报警,服务发现部分可以举例static_configs和consul_sd_configs等,如引用[2]中提到的。 配置部分需要给出一个基本的prometheus.yml示例,说明global、scrape_configs等部分,特别是static_configs的目标配置。同时提到其他服务发现方式,如ec2_sd_configs,引用[2]的内容需要在这里引用。 使用教程部分,可以分步骤:安装、配置监控目标、使用表达式查询、设置告警和集成可视化工具如Grafana。每个步骤简要说明,并提示参考官方文档或引用中的链接,比如引用[3]的中文文档。 相关问题需要围绕用户可能感兴趣的扩展内容,比如与其他监控系统的对比、优化存储、告警规则编写、Kubernetes中的使用以及高可用方案。这些问题需要自然引出,帮助用户深入探索。 需要检查LaTeX格式是否正确,所有数学表达式用$...$,独立公式用$$...$$,但当前内容可能不涉及数学公式,所以可能不需要。但如果有性能分析中的公式,比如计算内存使用,可能需要使用,例如时间序列存储的计算,但用户问题中没有涉及,所以可能不需要。 最后确保引用正确添加到对应的部分,例如在架构中的服务发现部分添加[^2],在配置部分提到Pushgateway时引用,在时间序列数据部分引用[^3]。确保回答结构清晰,分点说明,使用代码块展示配置示例,语言用中文,符合用户要求。</think>### Prometheus 监控系统详解 #### 一、系统架构 Prometheus 是一个开源的监控与时间序列数据库系统,其核心架构包含以下组件: 1. **Prometheus Server** 负责定时从配置的目标(如Exporters、应用程序)拉取(Pull)指标数据,并存储在本地时间序列数据库中。数据存储采用自定义的压缩算法,支持高效查询[^1]。 2. **Client Libraries** 提供多种编程语言(如Go、Java、Python)的客户端库,供应用程序集成并暴露监控指标。 3. **Exporters** 用于将第三方系统(如MySQL、Node Exporter)的指标转换为Prometheus兼容格式。例如,`node_exporter`用于收集服务器硬件和OS指标。 4. **Pushgateway** 适用于短暂任务(如定时任务)的监控,任务将指标推送到Pushgateway,再由Prometheus Server拉取[^2]。 5. **Alertmanager** 处理Prometheus发送的告警,支持去重、分组和路由(如邮件、Slack通知)。 6. **服务发现** 支持静态配置(`static_configs`)和动态发现(如Consul、Kubernetes、EC2)[^2]。 #### 二、配置示例 以下是一个基本的`prometheus.yml`配置: ```yaml global: scrape_interval: 15s # 抓取间隔 scrape_configs: - job_name: "node_exporter" # 监控目标组名称 static_configs: - targets: ["192.168.1.100:9100", "192.168.1.101:9100"] # 目标地址 - job_name: "pushgateway" honor_labels: true # 保留Pushgateway的标签 static_configs: - targets: ["pushgateway:9091"] ``` #### 三、使用教程 1. **安装与启动** 通过Docker或二进制包部署Prometheus Server和Exporters: ```bash docker run -p 9090:9090 -v /path/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus ``` 2. **配置监控目标** 修改`prometheus.yml`,添加需监控的Exporter地址,或使用服务发现(如Kubernetes自动发现Pod)。 3. **查询数据** 使用PromQL在Web界面(`http://localhost:9090/graph`)查询指标,例如: ```promql rate(node_cpu_seconds_total{mode="idle"}[5m]) # 计算CPU空闲率 ``` 4. **设置告警规则** 在`rules.yml`中定义告警条件,例如检测服务宕机: ```yaml groups: - name: example rules: - alert: InstanceDown expr: up == 0 # 目标健康状态为0时触发 for: 5m labels: severity: critical annotations: summary: "实例 {{ $labels.instance }} 宕机" ``` 5. **可视化集成** 通过Grafana导入Prometheus数据源,使用预置仪表盘(如ID 8919展示Node Exporter指标)。 #### 四、核心优势 - **多维数据模型**:通过标签(Labels)灵活区分指标来源。 - **高效的存储与查询**:时间序列数据压缩存储,支持实时聚合计算。 - **动态服务发现**:适配云原生环境,自动发现Kubernetes集群中的Pod。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值