Prometheus在哪里使用?

2020-12-02 14:53发布

2条回答
我的网名不再改
2楼 · 2020-12-07 09:57

1. 背景

1.1 TSDB?

TSDB(Time Series Database)时序列数据库,我们可以简单的理解为一个优化后用来处理时间序列数据的软件,并且数据中的数组是由时间进行索引的。

时间序列数据库的特点:

  • 大部分时间都是写入操作。

  • 写入操作几乎是顺序添加,大多数时候数据到达后都以时间排序。

  • 写操作很少写入很久之前的数据,也很少更新数据。大多数情况在数据被采集到数秒或者数分钟后就会被写入数据库。

  • 删除操作一般为区块删除,选定开始的历史时间并指定后续的区块。很少单独删除某个时间或者分开的随机时间的数据。

  • 基本数据大,一般超过内存大小。一般选取的只是其一小部分且没有规律,缓存几乎不起任何作用。

  • 读操作是十分典型的升序或者降序的顺序读。

  • 常见的时间序列数据库

TSDB项目 官网

influxDBhttps://influxdata.com/
RRDtoolhttp://oss.oetiker.ch/rrdtool/
Graphitehttp://graphiteapp.org/
OpenTSDBhttp://opentsdb.net/
Kdb+http://kx.com/
Druidhttp://druid.io/
KairosDBhttp://kairosdb.github.io/
Prometheushttps://prometheus.io/

2 简介

Prometheus是由SoundCloud开发的开源监控报警系统和时序列数据库(TSDB)。Prometheus使用Go语言开发,是Google BorgMon监控系统的开源版本。

2016年由Google发起Linux基金会旗下的原生云基金会(Cloud Native Computing Foundation), 将Prometheus纳入其下第二大开源项目。Prometheus目前在开源社区相当活跃。

Prometheus和Heapster(Heapster是K8S的一个子项目,用于获取集群的性能数据。)相比功能更完善、更全面。Prometheus性能也足够支撑上万台规模的集群。

3 特点

  • 多维度数据模型。

  • 灵活的查询语言。

  • 不依赖分布式存储,单个服务器节点是自主的。

  • 通过基于HTTP的pull方式采集时序数据。

  • 可以通过中间网关进行时序列数据推送。

  • 通过服务发现或者静态配置来发现目标服务对象。

  • 支持多种多样的图表和界面展示,比如Grafana等。

4 组件

Prometheus生态系统由多个组件组成,它们中的一些是可选的。多数Prometheus组件是Go语言写的,这使得这些组件很容易编译和部署。

  • Prometheus Server :主要负责数据采集和存储,提供PromQL查询语言的支持。

  • 客户端SDK:官方提供的客户端类库有go、java、scala、python、ruby,其他还有很多第三方开发的类库,支持nodejs、php、erlang等。

  • Push Gateway :支持临时性Job主动推送指标的中间网关。

  • PromDash:使用Rails开发可视化的Dashboard,用于可视化指标数据。

  • Exporter:Exporter是Prometheus的一类数据采集组件的总称。它负责从目标处搜集数据,并将其转化为Prometheus支持的格式。与传统的数据采集组件不同的是,它并不向中央服务器发送数据,而是等待中央服务器主动前来抓取。Prometheus提供多种类型的Exporter用于采集各种不同服务的运行状态。目前支持的有数据库、硬件、消息中间件、存储系统、HTTP服务器、JMX等。

  • alertmanager: 警告管理器,用来进行报警。

  • prometheus_cli: 命令行工具。

  • 其他辅助性工具:多种导出工具,可以支持Prometheus存储数据转化为HAProxy、StatsD、Graphite等工具所需要的数据存储格式。

5 架构

在这里插入图片描述
如上图,Prometheus主要由以下部分组成:

  • Prometheus Server:用于抓取和存储时间序列化数据

  • Exporters:主动拉取数据的插件

  • Pushgateway:被动拉取数据的插件

  • Altermanager:告警发送模块

  • Prometheus web UI:界面化,也包含结合Grafana进行数据展示或告警发送

6 安装

#测试安装$ docker run -d -p 9090:9090  --name prometheus docker.io/prom/prometheus:latest 
#配置与数据持久存储部署$ chown -R 65534:65534 /monitor/prometheus/data
$ docker run -d -p 9090:9090   -v /monitor/prometheus/config:/etc/prometheus -v /monitor/prometheus/data:/prometheus --name prometheus  docker.io/prom/prometheus:latest 

#定制版安装$ chown -R 65534:65534 /monitor/prometheus/data
$ docker run -tid -p 9090:9090  --restart=always  -v /monitor/prometheus/config/prometheus:/etc/prometheus:z -v /monitor/prometheus/data:/prometheus:z --name prometheus docker.io/prom/prometheus:latest "--config.file=/etc/prometheus/prometheus.yml" "--storage.tsdb.path=/prometheus" "--web.console.libraries=/usr/share/prometheus/console_libraries" "--web.console.templates=/usr/share/prometheus/consoles" "--storage.tsdb.retention.time=15d"  "--storage.tsdb.min-block-duration=6h" "--web.enable-admin-api" "--web.enable-lifecycle" 123456789

7 启动参数

 -h, --help:显示帮助信息
      --version:显示版本信息
      --config.file="prometheus.yml":启动时,指定Prometheus读取配置文件的路径。  
      --web.listen-address="0.0.0.0:9090" :指定网页打开Prometheus的ip和端口,默认为"0.0.0.0:9090"。
      --web.read-timeout=5m:页面读取请求最大超时时间 。 
      --web.max-connections=512:同时访问Prometheus页面的最大连接数,默认为512。
      --web.external-url=:Prometheus对外提供的url(eg: Prometheus通过反向代理提供服务)。用于生成一个相对和绝对的链接返回给Prometheus本身。如果这个url有路径部分,它将用于Prometheus所有HTTP端点的前缀。如果省略了,则相关的url组件将自动派生(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.route-prefix=:Web端点内部路由的前缀。默认路径:web.external-url。
      --web.user-assets=:静态资源路径,可以在/user下找到。
      --web.enable-lifecycle:通过HTTP请求启用关闭和重新加载。
      --web.enable-admin-api:启用管理控制操作的api端点。(Enables API endpoints for admin control actions)
      --web.console.templates="consoles":到控制台模板目录的路径,可以在consoles/目录下找到。
      --web.console.libraries="console_libraries":控制台库目录的路径。 
      --storage.tsdb.path="data/":存储的基本路径。
      --storage.tsdb.min-block-duration=2h:在持久化之前数据块的最短保存期。
      --storage.tsdb.max-block-duration=:在持久化之前数据块的最大保存期(默认为保存期的10%)。
      --storage.tsdb.retention=15d:存储采样的保存时间。
      --storage.tsdb.no-lockfile:不在数据目录中创建lockfile(Do not create lockfile in data directory)。
      --alertmanager.notification-queue-capacity=10000:等待报警通知队列的大小。
      --alertmanager.timeout=10s:发送警报到Alertmanager的超时时间。
      --query.lookback-delta=5m:允许在表达式求值期间检索度量值的delta差值(The delta difference allowed for retrieving metrics during expression evaluations)。
     --query.timeout=2m: 一个查询在终止之前可以执行的最长时间(如果超过2min,就会自动kill掉)。
      --query.max-concurrency=20:并发执行的最大查询数,默认为20。
      --log.level=info: 开启打印日志级别(debug,info,warn,error,fatal)。默认为info。123456789101112131415161718192021222324

配置--web.enable-lifecycle后,API可重载配置文件

curl -X POST http://localhost:9090/-/reload1

8 配置

模板

global:
  scrape_interval:     15s # 采集间隔15s,默认为1min一次
  evaluation_interval: 15s # 计算规则的间隔15s默认为1min一次
  scrape_timeout: 10s # 采集超时时间,默认为10s
  external_labels:  # 当和其他外部系统交互时的标签,如远程存储、联邦集群时
    prometheus: monitoring/k8s  # 如:prometheus-operator的配置
    prometheus_replica: prometheus-k8s-1

alerting:
  alertmanagers:
  - static_configs:
    - targets:
      - 192.168.211.16:9093

rule_files:
    - "*rules.yml"scrape_configs:
 - job_name: 'prometheus'
    static_configs:
    - targets: ['192.168.211.16:9090']12345678910111213141516171819202122

8.1 全局配置global

global 属于全局的默认配置,它主要包含 4 个属性,

  scrape_interval: 拉取 targets 的默认时间间隔。默认每隔15秒
  scrape_timeout: 拉取一个 target 的超时时间。默认每隔10秒
  evaluation_interval: 执行 rules 的时间间隔。监控的评估频率,默认15秒
  external_labels: 为指标增加额外的维度,可用于区分不同的prometheus,在应用中多个1234

prometheus可以对应一个alertmanager

8.2 rule_files

指定告警策略文件
格式:

rule_files:
    - "*rules.yml"12

默认情况下Prometheus会每分钟对这些告警规则进行计算,如果用户想定义自己的告警计算周期,则可以通过evaluation_interval来覆盖默认的计算周期。

8.3 scrape_configs配置

scrape_configs 主要用于配置拉取数据节点,每一个拉取配置主要包含以下参数:
job_name:任务名称
honor_labels: 用于解决拉取数据标签有冲突,当设置为 true, 以拉取数据为准,否则以服务配置为准
params:数据拉取访问时带的请求参数
scrape_interval: 拉取时间间隔
scrape_timeout: 拉取超时时间
metrics_path: 拉取节点的 metric 路径
scheme: 拉取数据访问协议
sample_limit: 存储的数据标签个数限制,如果超过限制,该数据将被忽略,不入存储;默认值为0,表示没有限制
relabel_configs: 拉取数据重置标签配置
metric_relabel_configs:metric 重置标签配置1234567891011

示例:重定义标签,将__address__改为ip

  - job_name: 'node-exporter'
    static_configs:
    - targets: 
       - '192.168.1.193:9100'

    relabel_configs:
    - source_labels: [__address__]
      regex: (.+):(.+)
      target_label: __tmp_ip
      replacement: ${1}
    - source_labels: [__tmp_ip]
      regex: (.*)
      target_label: ip
      replacement: ${1}1234567891011121314

9 告警

9.1 格式

groups:
 - name: example
  rules:
 - alert: HighErrorRate
    expr: job:request_latency_seconds:mean5m{job="myjob"} > 0.5
    for: 10m
    labels:
      severity: page
    annotations:
      summary: High request latency
      description: description info1234567891011

9.2 参数说明

在告警规则文件中,我们可以将一组相关的规则设置定义在一个group下。在每一个group中我们可以定义多个告警规则(rule)。一条告警规则主要由以下几部分组成:

  • alert:告警规则的名称。

  • expr:基于PromQL表达式告警触发条件,用于计算是否有时间序列满足该条件。

  • for:评估等待时间,可选参数。用于表示只有当触发条件持续一段时间后才发送告警。在等待期间新产生告警的状态为pending。

  • labels:自定义标签,允许用户指定要附加到告警上的一组附加标签。

  • severity:设置告警级别,例如:正常、告警、错误、严重、紧急等。

  • annotations:用于指定一组附加信息,比如用于描述告警详细信息的文字,内容在告警产生时会一同作为参数发送到Alertmanager。

  • info:内容在告警产生时会一同作为参数发送到Alertmanager

  • summary:支持特定的匹配规则,将内容发送Alertmanager

  • description:内容在告警产生时会一同作为参数发送到Alertmanager

9.3 模板说明

Prometheus支持模板化label和annotations的中标签的值。
通过l a b e l s . < l> 变 量 可 以 访 问 当 前 告 警 实 例 中 指 定 标 签 的 值 。 labels.变量可以访问当前告警实例中指定标签的值。labels.<labelname>访value则可以获取当前PromQL表达式计算的样本值。

# To insert a firing element's label values:{{ $labels. }}# To insert the numeric expression value of the firing element:{{ $value }}1234

示例:

groups:
- name: example
  rules:  # Alert for any instance that is unreachable for >5 minutes.
  - alert: InstanceDown
    expr: up == 0
    for: 5m
    labels:
      severity: page
    annotations:
      summary: "Instance {{ $labels.instance }} down"
      description: "{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 5 minutes."1234567891011121314

10. prometheus metrics

arp 域名解析/proc/net/arp. 
bcache缓存  /sys/fs/bcache/. 
bonding 绑定
conntrack 链接跟踪模块 /proc/sys/net/netfilter/ present). x
cpu 
diskstats磁盘进出进程  disk I/O 
edac 错误校检与纠正
entropy 熵exec   执行程序  
filefd   公开文件描述符  /proc/sys/fs/file-nr.
filesystem 文件系统  disk space used. 
hwmon  硬件与传感器  /sys/class/hwmon/. x
infiniband  无线带宽技术
ipvs  /proc/net/ip_vs and /proc/net/ip_vs_stats. 
loadavg 平均负载
mdadm  /proc/mdstat (does nothing if no /proc/mdstat present) 设备
meminfo Exposes memory statistics. Darwin, Dragonfly, FreeBSD, Linux, OpenBSD
netdev Exposes network interface statistics such as bytes transferred. Darwin, Dragonfly, FreeBSD, Linux, OpenBSDnetstat Exposes network statistics from /proc/net/netstat. This is the same information as netstat -s. Linux
nfs Exposes NFS client statistics from /proc/net/rpc/nfs. This is the same information as nfsstat -c. Linux
nfsd Exposes NFS kernel server statistics from /proc/net/rpc/nfsd. This is the same information as nfsstat -s. Linux
sockstat Exposes various statistics from /proc/net/sockstat. Linuxstat Exposes various statistics from /proc/stat. This includes boot time, forks and interrupts. Linux
textfile Exposes statistics read from local disk. The --collector.textfile.directory flag must be set. anytime Exposes the current system time. any
timex Exposes selected adjtimex(2) system call stats. Linuxuname Exposes system information as provided by the uname system call. Linuxvmstat Exposes statistics from /proc/vmstat. Linux
wifi Exposes WiFi device and station statistics. Linux
xfs Exposes XFS runtime statistics. Linux (kernel 4.4+)zfs Exposes ZFS performance statistics. Linux
Disabled by default
Name Description OS
buddyinfo Exposes statistics of memory fragments as reported by /proc/buddyinfo. Linux
devstat Exposes device statistics Dragonfly, FreeBSD
drbd Exposes Distributed Replicated Block Device statistics (to version 8.4) Linux
interrupts Exposes detailed interrupts statistics. Linux, OpenBSD
ksmd Exposes kernel and system statistics from /sys/kernel/mm/ksm. Linux
logind Exposes session counts from logind. Linux
meminfo_numa Exposes memory statistics from /proc/meminfo_numa. Linux
mountstats Exposes filesystem statistics from /proc/self/mountstats. Exposes detailed NFS client statistics. Linux
ntp Exposes local NTP daemon health to check time any
qdisc Exposes queuing discipline statistics Linux
runit Exposes service status from runit. any
supervisord Exposes service status from supervisord. any
systemd Exposes service and system status from systemd. Linux
tcpstat Exposes TCP connection status information from /proc/net/tcp and /proc/net/tcp6. (Warning: the current version has potential performance issues in high load situations.) Linux1234567891011121314151617181920212223242526272829303132333435363738394041424344454647

11. promtool工具

检查metrics

curl -s http://localhost:9090/metrics | promtool check metrics1

检查配置文件

promtool check config /etc/prometheus/prometheus.yml1

检查告警策略文件

promtool check rules /path/to/example.rules.yml


相关问题推荐

  • 什么是大数据时代?2021-01-13 21:23
    回答 100

    大数据(big data)一词越来越多地被提及,人们用它来描述和定义信息爆炸时代产生的海量数据,而这个海量数据的时代则被称为大数据时代。随着云时代的来临,大数据(Big data)也吸引了越来越多的关注。大数据(Big data)通常用来形容一个公司创造的大量非结...

  • 回答 84

    Java和大数据的关系:Java是计算机的一门编程语言;可以用来做很多工作,大数据开发属于其中一种;大数据属于互联网方向,就像现在建立在大数据基础上的AI方向一样,他两不是一个同类,但是属于包含和被包含的关系;Java可以用来做大数据工作,大数据开发或者...

  • 回答 52
    已采纳

    学完大数据可以从事很多工作,比如说:hadoop 研发工程师、大数据研发工程师、大数据分析工程师、数据库工程师、hadoop运维工程师、大数据运维工程师、java大数据工程师、spark工程师等等都是我们可以从事的工作岗位!不同的岗位,所具备的技术知识也是不一样...

  • 回答 29

    简言之,大数据是指大数据集,这些数据集经过计算分析可以用于揭示某个方面相关的模式和趋势。大数据技术的战略意义不在于掌握庞大的数据信息,而在于对这些含有意义的数据进行专业化处理。大数据的特点:数据量大、数据种类多、 要求实时性强、数据所蕴藏的...

  • 回答 14

    tail -f的时候,发现一个奇怪的现象,首先 我在一个窗口中 tail -f test.txt 然后在另一个窗口中用vim编辑这个文件,增加了几行字符,并保存,这个时候发现第一个窗口中并没有变化,没有将最新的内容显示出来。tail -F,重复上面的实验过程, 发现这次有变化了...

  • 回答 18

    您好针对您的问题,做出以下回答,希望有所帮助!1、大数据行业还是有非常大的人才需求的,对于就业也有不同的岗位可选,比如大数据工程师,大数据运维,大数据架构师,大数据分析师等等,就业难就难在能否找到适合的工作,能否与你的能力和就业预期匹配。2、...

  • 回答 17

    最小的基本单位是Byte应该没多少人不知道吧,下面先按顺序给出所有单位:Byte、KB、MB、GB、TB、PB、EB、ZB、YB、DB、NB,按照进率1024(2的十次方)计算:1Byte = 8 Bit1 KB = 1,024 Bytes 1 MB = 1,024 KB = 1,048,576 Bytes 1 GB = 1,024 MB = 1,048,576...

  • 回答 33

    大数据的定义。大数据,又称巨量资料,指的是所涉及的数据资料量规模巨大到无法通过人脑甚至主流软件工具,在合理时间内达到撷取、管理、处理、并整理成为帮助企业经营决策更积极目的的资讯。大数据是对大量、动态、能持续的数据,通过运用新系统、新工具、新...

  • 回答 5

    MySQL是一种关系型数据库管理系统,关系数据库将数据保存在不同的表中,而不是将所有数据放在一个大仓库内,这样就增加了速度并提高了灵活性。MySQL的版本:针对不同的用户,MySQL分为两种不同的版本:MySQL Community Server社区版本,免费,但是Mysql不提供...

  • mysql安装步骤mysql 2022-05-07 18:01
    回答 2

    mysql安装需要先使用yum安装mysql数据库的软件包 ;然后启动数据库服务并运行mysql_secure_installation去除安全隐患,最后登录数据库,便可完成安装

  • 回答 5

    1.查看所有数据库showdatabases;2.查看当前使用的数据库selectdatabase();3.查看数据库使用端口showvariableslike&#39;port&#39;;4.查看数据库编码showvariableslike‘%char%’;character_set_client 为客户端编码方式; character_set_connection 为建立连接...

  • 回答 5

    CREATE TABLE IF NOT EXISTS `runoob_tbl`(    `runoob_id` INT UNSIGNED AUTO_INCREMENT,    `runoob_title` VARCHAR(100) NOT NULL,    `runoob_author` VARCHAR(40) NOT NULL,    `submission_date` DATE,    PRI...

  • 回答 9

    学习多久,我觉得看你基础情况。1、如果原来什么语言也没有学过,也没有基础,那我觉得最基础的要先选择一种语言来学习,是VB,C..,pascal,看个人的喜好,一般情况下,选择C语言来学习。2、如果是有过语言的学习,我看应该一个星期差不多,因为语言的理念互通...

  • 回答 7

    添加语句 INSERT插入语句:INSERT INTO 表名 VALUES (‘xx’,‘xx’)不指定插入的列INSERT INTO table_name VALUES (值1, 值2,…)指定插入的列INSERT INTO table_name (列1, 列2,…) VALUES (值1, 值2,…)查询插入语句: INSERT INTO 插入表 SELECT * FROM 查...

  • 回答 5

    看你什么岗位吧。如果是后端,只会CRUD。应该是可以找到实习的,不过公司应该不会太好。如果是数据库开发岗位,那这应该是不会找到的。

  • 回答 7

    查找数据列 SELECT column1, column2, … FROM table_name; SELECT column_name(s) FROM table_name 

没有解决我的问题,去提问