ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Prometheus安装手册

2022-08-13 12:34:57  阅读:195  来源: 互联网

标签:prometheus scrape server metrics Prometheus 手册 安装 localhost


目录

Welcome to Prometheus! Prometheus is a monitoring platform that collects metrics from monitored targets by scraping metrics HTTP endpoints on these targets. This guide will show you how to install, configure and monitor our first resource with Prometheus. You'll download, install and run Prometheus. You'll also download and install an exporter, tools that expose time series data on hosts and services. Our first exporter will be Prometheus itself, which provides a wide variety of host-level metrics about memory usage, garbage collection, and more.

安装参考文档:https://prometheus.io/docs/introduction/first_steps/

Prometheus生态系统

下图说明了Prometheus的体系结构及其生态系统组件:

Prometheus architecture

Prometheus Server: Prometheus服务端,由于存储及收集数据,提供相关api对外查询用。
Exporter: 类似传统意义上的被监控端的agent,有区别的是,它不会主动推送监控数据到server端,而是等待server端定时来手机数据,即所谓的主动监控。
Pushagateway: 用于网络不可直达而居于exporter与server端的中转站。
Alertmanager: 报警组件,将报警的功能单独剥离出来放在alertmanager。
Web UI: Prometheus的web接口,可用于简单可视化,及语句执行或者服务状态监控。

参考文档:https://prometheus.io/docs/introduction/overview/

下载Prometheus

下载并解压Prometheus安装包Download the latest release :

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

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

$ ./prometheus --help
usage: prometheus [<flags>]

The Prometheus monitoring server
. . .

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

配置Prometheus

Prometheus配置为YAML。配置Prometheus下的prometheus.yml的示例。

删除了示例文件中的大多数注释,以使其更加简洁。

global:
  scrape_interval:     15s
  evaluation_interval: 15s

rule_files:
  # - "first.rules"
  # - "second.rules"

scrape_configs:
  - job_name: prometheus
    static_configs:
      - targets: ['localhost:9090']

There are three blocks of configuration in the example configuration file: global, rule_files, and scrape_configs.

The global block controls the Prometheus server's global configuration. We have two options present. The first, scrape_interval, controls how often Prometheus will scrape targets. You can override this for individual targets. In this case the global setting is to scrape every 15 seconds. The evaluation_interval option controls how often Prometheus will evaluate rules. Prometheus uses rules to create new time series and to generate alerts.

The rule_files block specifies the location of any rules we want the Prometheus server to load. For now we've got no rules.

The last block, scrape_configs, controls what resources Prometheus monitors. Since Prometheus also exposes data about itself as an HTTP endpoint it can scrape and monitor its own health. In the default configuration there is a single job, called prometheus, which scrapes the time series data exposed by the Prometheus server. The job contains a single, statically configured, target, the localhost on port 9090. Prometheus expects metrics to be available on targets on a path of /metrics. So this default job is scraping via the URL: http://localhost:9090/metrics.

The time series data returned will detail the state and performance of the Prometheus server.

For a complete specification of configuration options, see the configuration documentation.

启动Prometheus

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

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

Prometheus开始运行。我们可以在 http://localhost:9090看到状态页。

Give it about 30 seconds to collect data about itself from its own HTTP metrics endpoint.

我们也可以通过导航到: http://localhost:9090/metrics.
验证Prometheus是否正在提供自身指标。

使用浏览器browser

让我们尝试查看Prometheus收集的有关自身的一些数据。要使用Prometheus的内置浏览器,请导航至 http://localhost:9090/graph,然后选择“console”控制台视图。

promhttp_metric_handler_requests_total

这应该返回多个不同的时间序列(以及每个序列的最新值),所有时间序列均带有度量名称promhttp_metric_handler_requests_total,但带有不同的标签。这些标签指定不同的请求状态。

如果我们需要HTTP代码200的请求,则可以使用此查询来检索该信息:

promhttp_metric_handler_requests_total{code="200"}

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

count(promhttp_metric_handler_requests_total)

For more about the expression language, see the expression language documentation.

使用Graph界面

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

例如,输入以下表达式以图形化显示在自抓取的Prometheus中发生的每秒HTTP请求速率返回状态代码200:

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

You can experiment with the graph range parameters and other settings.

标签:prometheus,scrape,server,metrics,Prometheus,手册,安装,localhost
来源: https://www.cnblogs.com/cscshi/p/16582755.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有