Prometheus

监控告警:node

Prometheus + grafana +alertmanagerredis

Prometheus  介绍:bash

更多请参考官方文档: https://prometheus.io/docs/分布式

什么是prometheus :ide

Prometheus 是一个开源的监控系统,和告警工具,被多家公司所采纳监控。函数

特征:工具

 1 . 是一个多维数据模型,具备由度量名称/键值对标志的时间序列数据。lua

 2.  是一种灵活的查询语言url

 3.  单个服务节点是自制的, 不依赖分布式存储spa

 4.  时间序列经过http 的拉取模式

 5 . 推送时间序列经过中间网关支持

 6 . 经过服务发现和配置来来发现目标

 7. 多种模式的图形和仪表盘支持

Prometheus 构成:

 

 

    解释: 

     主要是用来抓取和存储时间序列,分为Prometheus Server 主要分为三个组成部分, Retrieval  主要是用来服务发现配置的, Storge 主要用来存储数据,PromQL 高级查询语句:抓取方式:

    主要是经过Jobs/Exporters  和中间网关拉取 metrics,并推送告警规则 alertmanager , 总的来讲是, Prometheus直接或经过中介推送网关从短时间工做中提取仪器化工做的指标。它在本地存储全部抓取的样本,并对这些数据运行规则,以聚合和记录现有数据的新时间序列或生成警报。Grafana或其余API消费者可用于可视化收集的数据。 

     适用范围;

       以机器为中心的监控和高度动态的面向服务体系的监控,支持多维数据的收集 和查询。prometheus可靠,可是不可是数据不会是百分一百的准确性的(好比按请求计费)

 

   Prometheus 安装部署:

    下载Prometheus ,解压:

1 tar xvfz prometheus-*.tar.gz
2 
3 cd 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']

  global :是全局配置, rule_files 是告警规则配置,也能够适用正则, 第三部分是抓取配置(好比redis监控信息),

scrape_interval表示每隔多久抓取一次,
evaluation_interval 表示多久一次评估规则,--》 生成告警


*.rules 告警规则文件。

scrape_configs: 配置完成,咱们能够经过:http:// localhost:9090 / metrics来抓取。

重启Prometheus : Curl -X Post http://localhost:port//-//

http_requests_total{code="200"} 表达式 能够查询信息.(参考表达是语言文档)

从官网下载 Exporter
tar xvfz node_exporter-*.tar.gz cd node_exporter-*

启动
./node_exporter 

须要配置Job_Name:

- job_name: node
    static_configs:
      - targets: ['localhost:9100']

 

 重启Prometheus ,就能够在consule 看到监控指标了。



Prometheus 度量类型:

1 .counter
一个计数器是表明永远只上升1个数值累计度量。计数器一般用于计数提供的请求数,完成的任务数,发生的错误数等。
2 .Gauge
仪表一般用于测量值,如温度或当前的存储器使用状况,但也能够上升和降低的“计数”,如正在运行的goroutines的数量。
3. histogram

   具备基本度量标准名称的直方图<basename>在刮取期间显示多个时间序列:

 
  •   观察桶的累计计数器,暴露为 <basename>_bucket{le="<upper inclusive bound>"}
  • 总和的全部观察值的,公开为<basename>_sum
  • 计数已观察到的事件的,公开为<basename>_count(等同于<basename>_bucket{le="+Inf"}上文)
 

     使用该 histogram_quantile()函数 从直方图或直方图聚合中计算分位数。直方图也适用于计算 Apdex分数在桶上操做时,请记住直方图是 累积的有关直方图使用状况和摘要差别的详细信息,请参阅 直方图和摘  要


4. Summary

Similar to a histogram, a summary samples observations (usually things like request durations and response sizes). While it also provides a total count of observations and a sum of all observed values, it calculates configurable quantiles over a sliding time window.

 

A summary with a base metric name of <basename> exposes multiple time series during a scrape:

 
  • streaming φ-quantiles (0 ≤ φ ≤ 1) of observed events, exposed as <basename>{quantile="<φ>"}
  • the total sum of all observed values, exposed as <basename>_sum
  • the count of events that have been observed, exposed as <basename>_count
 

See histograms and summaries for detailed explanations of φ-quantiles, summary usage, and differences to histograms.

相关文章
相关标签/搜索