scrapy 监控 Prometheus 介绍与安装(1)

2022/8/5 23:25:14

本文主要是介绍scrapy 监控 Prometheus 介绍与安装(1),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

一. 概述

  Prometheus 是一个开源的服务监控系统和时间序列数据库。包括监控和告警,实现流式监控数据的收集、存储、查询、告警 ,它将指标收集并存储为时间序列数据库(time series data)。大多数 Prometheus 组件都是用Go编写的,这使得它们易于构建和部署为静态二进制文件。

  它支持灵活的查询语言PromQL,利用PromQL非常方便地查询和分析某个时间段内的各项指标数据,它提供了可视化UI,还支持告警配置等功能。

 

  下面是Prometheus 的架构及其一些生态系统组件:

 

 

2.什么时候合适使用

  Prometheus 可以很好的记录任何纯数字时间序列,它既适应于面向服务等硬件指标的监控,也适用于高动态的面向服务的架构的监控,对于现在流行的微服务,它的多维度数据收集和数据筛选查询语言也是非常强大的。

  Prometheus 专为可靠性而设计,是您在中断期间可以使用的系统,可让您快速诊断问题。每个 Prometheus 服务器都是独立的,不依赖于网络存储或其他远程服务。当您的基础设施的其他部分损坏时,您可以依赖它,并且您无需设置大量基础设施即可使用它。

 

3.什么时候不合适使用

  Prometheus 重视可靠性。即使在故障情况下,您也可以随时查看有关系统的可用统计信息。如果您需要 100% 的准确性,例如按请求计费,Prometheus 不是一个好的选择,因为收集的数据可能不够详细和完整。在这种情况下,您最好使用其他系统来收集和分析数据以进行计费,并使用 Prometheus 进行其余的监控

 

4.预编译的二进制文件包下载

  https://prometheus.io/download/ 下载解压,解压后如下所示

[root@iZwz97yqubb71vyxhuskfyZ prometheus-2.36.0.linux-amd64]# pwd
/root/prometheus/prometheus-2.36.0.linux-amd64
[root@iZwz97yqubb71vyxhuskfyZ prometheus-2.36.0.linux-amd64]# ls
console_libraries  consoles  data  LICENSE  NOTICE  prometheus  prometheus.yml  promtool

 

5.prometheus.yml配置文件

# my global config
global:
  scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
  alertmanagers:
    - static_configs:
        - targets:
          # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: "prometheus"

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["xx.xxx.xx.xx:9090"]

  - job_name: 'scrapy'
    static_configs:
      - targets: ['120.24.xx.xxx:9410']

  配置文件有三个配置块: global, rule_files, 和 scrape_configs

  global块为prometheus服务器的全局配置:

    1)scrape_interval 控制prometheus抓取目标的频率,默认15一次。

    2)evaluation_interval 评估规则(rule)的频率,默认15一次, prometheus使用规则来创建新的时间序列并生成警报。

  rule_files块指定prometheus服务器加载任何规则的位置,上面yml文件中没有任何规则。

  scrape_configs块控制prometheus监控的资源。由于它还将自身的数据公开为http站点,因此它可以抓取和监控自己的健康状况,上面yml文件监控了自己和scrapy(后续介绍)。默认配置中,只监控自己job_name:“prometheus”,它会抓取prometheus服务器公开的时间序列数据。该作业包含一个静态配置的目标,即localhost:9090,默认的作业是通过抓取http://localhost:9090/metrics的url指标站点。

    返回的时间序列数据将详细说明 Prometheus 服务器的状态和性能,如下所示:


6.启动prometheus

[root@iZwz97yqubb71vyxhuskfyZ prometheus-2.36.0.linux-amd64]# ls
console_libraries  consoles  data  LICENSE  NOTICE  prometheus  prometheus.yml  promtool
[root@iZwz97yqubb71vyxhuskfyZ prometheus-2.36.0.linux-amd64]# ./prometheus  --config.file=prometheus.yml

  启动成功后,tcp地址为: 0.0.0.0:9090

  打开 http://localhost:9090浏览到关于自身的状态页面。给它大约 30 秒的时间从它自己的 HTTP 指标端点收集关于它自己的数据。
  打开 http://localhost:9090/metrics指标端点来验证 Prometheus 是否正在提供有关自身的指标

 

官方文档地址: https://prometheus.io/docs/introduction/overview/

 

  



这篇关于scrapy 监控 Prometheus 介绍与安装(1)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程