前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Prometheus2.8简介 原

Prometheus2.8简介 原

作者头像
阿dai学长
发布2019-04-03 10:06:12
7580
发布2019-04-03 10:06:12
举报
文章被收录于专栏:阿dai_linux阿dai_linux

Prometheus是什么?

Prometheus(普罗米修斯)是一套最初在SoundCloud上构建的开源监视和告警系统 。

特征

普罗米修斯的主要特点是:

  • 具有由度量名称和键/值对标识的时间序列数据的多维数据模型
  • 可以利用PromQL 灵活的查询语言,
  • 不依赖分布式存储; 单个服务器节点是自治的
  • 时间序列集合通过HTTP上的拉模型发生
  • 通过中间网关支持 推送时间序列
  • 通过服务发现或静态配置发现目标
  • 多种图形和仪表板支持模式

组件

大部Prometheus分组件都是用go写的,因此很容易构建和部署为静态二进制文件。

Prometheus生态

Prometheus直接或通过中间推送网关从仪表工作中删除指标,用于短期工作。它在本地存储所有已删除的样本,并对此数据运行规则,以汇总和记录现有数据的新时间序列或生成警报。Grafana或其他API使用者可用于可视化收集的数据。

Prometheus适用场景

  • Prometheus适用于录制任何纯数字时间序列。它适用于以机器为中心的监控以及高度动态的面向服务架构的监控。在微服务的世界中,它对多维数据收集和查询的支持是一种特殊的优势。
  • Prometheus专为提高可靠性而设计,在停电期间可以快速诊断问题。每个Prometheus服务器都是独立的,不依赖于网络存储或其他远程服务。当基础架构的其他部分损坏时,您可以依赖它,并且您不需要设置大量的基础架构来使用它。
  • 普罗米修斯重视可靠性。即使在故障情况下,您也可以随时查看有关系统的可用统计信息。如果您需要100%的准确度,例如统计每个请求的情况,Prometheus不是一个好的选择,因为收集的数据可能不够详细和完整。在这种情况下,您最好使用其他系统来收集和分析数据以进行计费,并使用Prometheus进行其余监控。

更多参考

安装

Prometheus官方给出了多重部署方案,比如:Docker容器、Ansible、Chef、Puppet、Saltstack等。

Prometheus用Golang实现,因此具有天然可移植性(支持Linux、Windows、macOS和Freebsd)。这里直接使用预编译的二进制文件部署,开箱即用。

下载

下载地址

代码语言:javascript
复制
$ wget https://github.com/prometheus/prometheus/releases/download/v2.8.0/prometheus-2.8.0.linux-amd64.tar.gz

$ tar zxvf prometheus-2.8.0.linux-amd64.tar.gz

$ mv prometheus-2.8.0.linux-amd64 /usr/local/prometheus

Prometheus服务是一个单独的二进制文件 prometheus ,使用方法:

代码语言:javascript
复制
$ ./prometheus --help
usage: prometheus [<flags>]

The Prometheus monitoring server

Flags:
  -h, --help                     Show context-sensitive help (also try --help-long and --help-man).
      --version                  Show application version.
      --config.file="prometheus.yml"  
                                 Prometheus configuration file path.
... ...

创建prometheus普通用户

这里单独创建一个专门用于运行prometheus的用户,不用root运行程序是一种好习惯。

代码语言:javascript
复制
$ useradd prometheus
$ id prometheus
uid=1000(prometheus) gid=1000(prometheus) 组=1000(prometheus)
$ chown -R prometheus.prometheus /usr/local/prometheus

加入systemd管理

代码语言:javascript
复制
[Unit]
Description=prometheus
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --storage.tsdb.path=/usr/local/prometheus/data/
Restart=on-failure
[Install]
WantedBy=multi-user.target

Prometheus配置文件

官方文档

配置说明

Prometheus通过命令行参数和配置文件共同进行配置。

  • 命令行参数:指定一些固定的参数,如存储位置、数据挂在位置等;
  • 配置文件:用来定义和监控作业相关的所有配置,如

配置文件为 YAML格式 ,结构如下,括号表示参数是可选的。对于非列表参数,该值设置为指定的默认值。

  • <boolean>:布尔值,取值为 truefalse
  • <duration>:与正则表达式匹配的持续时间 [0-9]+(ms|[smhdwy])
  • <labelname>:与正则表达式匹配的字符串 [a-zA-Z_][a-zA-Z0-9_]*
  • <labelvalue>:一串unicode字符
  • <filename>:当前工作目录中的有效路径
  • <host>:由主机名或IP后跟可选端口号组成的有效字符串
  • <path>:有效的URL路径
  • <scheme>:字符串,取值为 httphttps
  • <string>:常规字符串
  • <secret>:一个加密的常规字符串,例如密码
  • <tmpl_string>:模板字符串

命令行参数

通过 ./prometheus --help 查看所有命令行配置参数。Prometheus运行时重新加载配置,如果新配置格式错误,则不会应用更改。可以通过向Prometheus进程发送 SIGHUP 信号或向服务发送 /-/reload HTTP POST请求(前提是启动时开启--web.enable-lifecycle 参数)来 重新加载 服务,这会重新加载配置。

配置文件详解

Prometheus的配置文件为 prometheus.yml ,文件中 # 表示注释。

文件内容
代码语言:javascript
复制
global:
  # How frequently to scrape targets by default.
  [ scrape_interval: <duration> | default = 1m ]

  # How long until a scrape request times out.
  [ scrape_timeout: <duration> | default = 10s ]

  # How frequently to evaluate rules.
  [ evaluation_interval: <duration> | default = 1m ]

  # The labels to add to any time series or alerts when communicating with
  # external systems (federation, remote storage, Alertmanager).
  external_labels:
    [ <labelname>: <labelvalue> ... ]

# Rule files specifies a list of globs. Rules and alerts are read from
# all matching files.
rule_files:
  [ - <filepath_glob> ... ]

# A list of scrape configurations.
scrape_configs:
  [ - <scrape_config> ... ]

# Alerting specifies settings related to the Alertmanager.
alerting:
  alert_relabel_configs:
    [ - <relabel_config> ... ]
  alertmanagers:
    [ - <alertmanager_config> ... ]

# Settings related to the remote write feature.
remote_write:
  [ - <remote_write> ... ]

# Settings related to the remote read feature.
remote_read:
  [ - <remote_read> ... ]

配置文件分为6个模块:global、rule_files、scrape_configs、alerting、remote_write、remote_read。

scrape_configs模块

配置监控项,及相关参数。目标可以是静态的(static_configs指定),也可以是动态获取(通过Prometheus某种自发现功能),relabel_configs 可在抓取数据前对目标及起标签进行编辑。

  • static_configs:
代码语言:javascript
复制
# The targets specified by the static config.
targets:
  [ - '<host>' ]

# Labels assigned to all metrics scraped from the targets.
labels:
  [ <labelname>: <labelvalue> ... ]
  • scrape_configs:
代码语言:javascript
复制
job_name: <job_name>    # 任务名称,全局唯一
[ scrape_interval: <duration> | default = <global_config.scrape_interval> ]  # 抓取数据的频率
[ scrape_timeout: <duration> | default = <global_config.scrape_timeout> ]  # 抓取数据超时时间
[ metrics_path: <path> | default = /metrics ]  # 获取metrics的文件

# honor_labels controls how Prometheus handles conflicts between labels that are
# already present in scraped data and labels that Prometheus would attach
# server-side ("job" and "instance" labels, manually configured target
# labels, and labels generated by service discovery implementations).
#
# If honor_labels is set to "true", label conflicts are resolved by keeping label
# values from the scraped data and ignoring the conflicting server-side labels.
#
# If honor_labels is set to "false", label conflicts are resolved by renaming
# conflicting labels in the scraped data to "exported_<original-label>" (for
# example "exported_instance", "exported_job") and then attaching server-side
# labels. This is useful for use cases such as federation, where all labels
# specified in the target should be preserved.
#
# Note that any globally configured "external_labels" are unaffected by this
# setting. In communication with external systems, they are always applied only
# when a time series does not have a given label yet and are ignored otherwise.
[ honor_labels: <boolean> | default = false ]

[ scheme: <scheme> | default = http ]  # web请求协议类型
params: # 可选的 http URL 参数
  [ <string>: [<string>, ...] ]

basic_auth: # 用户认证相关配置
  [ username: <string> ]
  [ password: <secret> ]
  [ password_file: <string> ]

# Sets the `Authorization` header on every scrape request with
# the configured bearer token. It is mutually exclusive with `bearer_token_file`.
[ bearer_token: <secret> ]  # 认证token

# Sets the `Authorization` header on every scrape request with the bearer token
# read from the configured file. It is mutually exclusive with `bearer_token`.
[ bearer_token_file: /path/to/bearer/token/file ]

# Configures the scrape request's TLS settings.
tls_config:
  [ <tls_config> ]

# Optional proxy URL.
[ proxy_url: <string> ]

# List of Azure service discovery configurations.
azure_sd_configs:
  [ - <azure_sd_config> ... ]

# List of Consul service discovery configurations.
consul_sd_configs:
  [ - <consul_sd_config> ... ]

# List of DNS service discovery configurations.
dns_sd_configs:
  [ - <dns_sd_config> ... ]

# List of EC2 service discovery configurations.
ec2_sd_configs:
  [ - <ec2_sd_config> ... ]

# List of OpenStack service discovery configurations.
openstack_sd_configs:
  [ - <openstack_sd_config> ... ]

# List of file service discovery configurations.
file_sd_configs:
  [ - <file_sd_config> ... ]

# List of GCE service discovery configurations.
gce_sd_configs:
  [ - <gce_sd_config> ... ]

# List of Kubernetes service discovery configurations.
kubernetes_sd_configs:
  [ - <kubernetes_sd_config> ... ]

# List of Marathon service discovery configurations.
marathon_sd_configs:
  [ - <marathon_sd_config> ... ]

# List of AirBnB's Nerve service discovery configurations.
nerve_sd_configs:
  [ - <nerve_sd_config> ... ]

# List of Zookeeper Serverset service discovery configurations.
serverset_sd_configs:
  [ - <serverset_sd_config> ... ]

# List of Triton service discovery configurations.
triton_sd_configs:
  [ - <triton_sd_config> ... ]

# List of labeled statically configured targets for this job.
static_configs:
  [ - <static_config> ... ]

# List of target relabel configurations.
relabel_configs:
  [ - <relabel_config> ... ]

# List of metric relabel configurations.
metric_relabel_configs:
  [ - <relabel_config> ... ]

# Per-scrape limit on number of scraped samples that will be accepted.
# If more than this number of samples are present after metric relabelling
# the entire scrape will be treated as failed. 0 means no limit.
[ sample_limit: <int> | default = 0 ]
tls_config
代码语言:javascript
复制
# CA certificate to validate API server certificate with.
[ ca_file: <filename> ]

# Certificate and key files for client cert authentication to the server.
[ cert_file: <filename> ]
[ key_file: <filename> ]

# ServerName extension to indicate the name of the server.
# https://tools.ietf.org/html/rfc4366#section-3.1
[ server_name: <string> ]

# Disable validation of the server certificate.
[ insecure_skip_verify: <boolean> ]

配置文件示例

kubernetes_sd_config

prometheus支持好多种服务收集,从上面的配置信息说明就可以看得出比如kubernetes、openstack、ec2、dns等等,下面了解一下当前应用最多的kubernetes监控,参考文档

参考文档

(adsbygoogle = window.adsbygoogle || []).push({});

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Prometheus是什么?
  • 特征
  • 组件
  • Prometheus生态
  • Prometheus适用场景
  • 安装
    • 下载
      • 创建prometheus普通用户
        • 加入systemd管理
        • Prometheus配置文件
          • 配置说明
            • 命令行参数
              • 配置文件详解
                • 文件内容
              • 参考文档
              相关产品与服务
              容器服务
              腾讯云容器服务(Tencent Kubernetes Engine, TKE)基于原生 kubernetes 提供以容器为核心的、高度可扩展的高性能容器管理服务,覆盖 Serverless、边缘计算、分布式云等多种业务部署场景,业内首创单个集群兼容多种计算节点的容器资源管理模式。同时产品作为云原生 Finops 领先布道者,主导开源项目Crane,全面助力客户实现资源优化、成本控制。
              领券
              问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档