系统监控Prometheus安装和基本配置
Prometheus是一套开源的系统监控和报警框架,灵感源自Google的Borgmon监控系统。2012年,SoundCloud的Google前员工创造了Prometheus,并作为社区开源项目进行开发。2015年,该项目正式发布。2016年,Prometheus加入云原生计算基金会(Cloud Native Computing Foundation),成为受欢迎度仅次于Kubernetes的项目。
Prometheus具有以下特性
-
多维的数据模型(基于时间序列的Key、Value键值对) -
灵活的查询和聚合语言PromQL -
提供本地存储和分布式存储 -
通过基于HTTP的Pull模型采集时间序列数据 -
可利用Pushgateway(Prometheus的可选中间件)实现Push模式 -
可通过动态服务发现或静态配置发现目标机器 -
支持多种图表和数据大盘
安装Prometheus
我们在Centos7 上安装Prometheus
创建账户
> groupadd prometheus
> useradd -g prometheus -M -s /sbin/nologin prometheus
下载prometheus
> wget https://github.com/prometheus/prometheus/releases/download/v2.28.1/prometheus-2.28.1.linux-amd64.tar.gz
解压并安装 prometheus 服务
> tar -xzvf prometheus-2.28.1.linux-amd64.tar.gz
> mv prometheus-2.28.1.linux-amd64 /usr/local/prometheus
> mkdir /usr/local/prometheus/data
> chown -R prometheus:prometheus /usr/local/prometheus
创建 prometheus 系统服务
> vim /usr/lib/systemd/system/prometheus.service
[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io/docs/introduction/overview/
After=network-online.target
[Service]
User=prometheus
Restart=on-failure
ExecStart=/usr/local/prometheus/prometheus \
--config.file=/usr/local/prometheus/prometheus.yml \
--storage.tsdb.path=/usr/local/prometheus/data
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
prometheus 配置
> vim /usr/local/prometheus/prometheus.yaml
global:
scrape_interval: 15s
evaluation_interval: 15s
alerting:
alertmanagers:
- static_configs:
- targets: ["localhost:9093"]
rule_files:
#- "alert.rules"
scrape_configs:
- job_name: 'prometheus'
scrape_interval: 5s
static_configs:
- targets: ['localhost:9090']
- job_name: 'node'
scrape_interval: 10s
static_configs:
- targets: ['localhost:9100']
启动服务
> systemctl daemon-reload
> systemctl start prometheus.service
> systemctl enable prometheus.service
> systemctl status prometheus.service
Prometheus 服务支持热加载配置
> systemctl reload prometheus.service
访问http://ip:9090
近期热文
入门小站
全栈入门知识
Official Account