首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

运维监控-Prometheus

Prometheus是一个开源的系统监控和警报工具包。

特点:

• 多维数据模型,时间序列由metric名字和K/V标签标识

• 灵活的查询语言(PromQL)

• 单机模式,不依赖分布式存储

• 基于HTTP采用pull方式收集数据

• 支持push数据到中间件(pushgateway)

• 通过服务发现或静态配置发现目标

• 多种图表和仪表盘

注意:由于数据采集可能会有丢失,所以 Prometheus 不适用对采集数据要 100% 准确的情形。但如果用于记录时间序列数据,Prometheus 具有很大的查询优势,此外,Prometheus 适用于微服务的体系架构。

组件:

Prometheus生态系统由多个组件构成,其中多是可选的,根据具体情况选择

• Prometheus server - 收集和存储时间序列数据

• Client Library: 客户端库,为需要监控的服务生成相应的 metrics 并暴露给 Prometheus server。当 Prometheus server 来 pull 时,直接返回实时状态的 metrics。

• pushgateway - 对于短暂运行的任务,负责接收和缓存时间序列数据,同时也是一个数据源

• exporter - 各种专用exporter,面向硬件、存储、数据库、HTTP服务等

• alertmanager - 处理报警

• webUI等,其他各种支持的工具

安装

Prometheus是Golang写的,我们可以直接下载二进制文件直接解压执行即可。

wget -c https://github.com/prometheus/prometheus/releases/download/v2.9.2/prometheus-2.9.2.linux-amd64.tar.gz

wget -c https://github.com/prometheus/node_exporter/releases/download/v0.17.0/node_exporter-0.17.0.linux-amd64.tar.gz

其中,prometheus-2.9.2.linux-amd64.tar.gz就是服务端程序压缩包,node_exporter-0.17.0.linux-amd64.tar.gz是主机监控指标的包。

部署

客户端

node_exporter有默认的配置,可以直接使用nohup运行即可,会监听9100的端口

nohup ./node_exporter &

服务端

prometheus程序默认是找当前目录下的prometheus.yml配置文件,也可以使用--config.file="prometheus.yml"指定配置文件

nohup ./prometheus --config.file="prometheus.yml" &

配置文件

cat 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=` to any timeseries scraped from this config.

- job_name: 'prometheus'

# metrics_path defaults to '/metrics'

# scheme defaults to 'http'.

static_configs:

- targets: ['localhost:9090']

默认配置文件里面,使用了静态配置的方式,监控Prometheus的指标。

添加一个node指标

添加以下内容

- job_name: 'node_export'

static_configs:

- targets: ['192.168.100.171:9100']

重载配置

kill -HUP [prometheus_pid]

给Prometheus发现重载配置的信号,就会开始收集node的指标。

webUI

Prometheus提供了一个webUI可以查询对应的参数的值,,也有简单的图形趋势展示

http://[ip]:9090

但是我们一般会结合grafana使用,绘制出比较美观漂亮的界面。

  • 发表于:
  • 原文链接https://kuaibao.qq.com/s/20190828A0R6SW00?refer=cp_1026
  • 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。
  • 如有侵权,请联系 cloudcommunity@tencent.com 删除。

扫码

添加站长 进交流群

领取专属 10元无门槛券

私享最新 技术干货

扫码加入开发者社群
领券