Prometheus-部署

ops/2024/10/11 11:22:08/

Prometheus-部署

  • Server端安装配置
  • 部署Node Exporters监控系统指标
  • 监控MySQL数据库
  • 监控nginx
  • 安装grafana

Server端安装配置

1、上传安装包,并解压

cd /opt/
tar xf prometheus-2.30.3.linux-amd64.tar.gz
mv prometheus-2.30.3.linux-amd64 /usr/local/prometheus

cat /usr/local/prometheus/prometheus.yml

# my global config
global:   #用于prometheus的全局配置,比如采集间隔,抓取超时时间等scrape_interval: 15s # 采集目标主机监控数据的时间间隔,默认为1mevaluation_interval: 15s # 触发告警生成alert的时间间隔,默认是1m# scrape_timeout is set to the global default (10s).scrape_timeout: 10s # 数据采集超时时间,默认10s# Alertmanager configuration
alerting: # 用于alertmanager实例的配置,支持静态配置和动态服务发现的机制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=<job_name>` to any timeseries scraped from this config.- job_name: "prometheus"  #每个被监控实例的集合用job_name命名,支持静态配置(static_configs)和动态
服务发现的机制(*_sd_configs)# metrics_path defaults to '/metrics'metrics_path: '/metrics' # 指标数据采集路径,默认为 /metrics# scheme defaults to 'http'.static_configs:  # 静态目标配置,固定从某个target拉取数据- targets: ["localhost:9090"]

2、配置系统启动文件

vim /usr/lib/systemd/system/prometheus.service
[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io
After=network.target[Service]
Type=simple
ExecStart=/usr/local/prometheus/prometheus \
--config.file=/usr/local/prometheus/prometheus.yml \
--storage.tsdb.path=/usr/local/prometheus/data/ \
--storage.tsdb.retention=15d \
--web.enable-lifecycleExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure[Install]
WantedBy=multi-user.target

3、启动服务

systemctl start prometheus
systemctl enable prometheus

4、网页访问
http://ip:9090/targets

点击页面的 Status -> Targets,如看到 Target 状态都为 UP,说明 Prometheus 能正常采集到数据

在这里插入图片描述
http://ip:9090/metrics

可以看到 Prometheus 采集到自己的指标数据,其中 Help 字段用于解释当前指标的含义,Type 字段用于说明数据的类型

在这里插入图片描述

部署Node Exporters监控系统指标

1、上传安装包,并解压

cd /opt/
tar xf node_exporter-1.3.1.linux-amd64.tar.gz
mv node_exporter-1.3.1.linux-amd64/node_exporter /usr/local/bin

vim /usr/lib/systemd/system/node_exporter.service

[Unit]
Description=node_exporter
Documentation=https://prometheus.io/
After=network.target[Service]
Type=simple
ExecStart=/usr/local/bin/node_exporter \
--collector.ntp \
--collector.mountstats \
--collector.systemd \
--collector.tcpstatExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure[Install]
WantedBy=multi-user.target
systemctl start node_exporter
systemctl enable node_exporter
netstat -natp | grep :9100

2、网页访问
http://ip:9100/metrics

常用的各指标:
node_cpu_seconds_total
node_memory_MemTotal_bytes
node_filesystem_size_bytes{mount_point=PATH}
node_system_unit_state{name=}
node_vmstat_pswpin:系统每秒从磁盘读到内存的字节数
node_vmstat_pswpout:系统每秒钟从内存写到磁盘的字节数

更多指标介绍:https://github.com/prometheus/node_exporter

#修改 prometheus 配置文件,加入到 prometheus 监控中

vim /usr/local/prometheus/prometheus.yml

#在尾部增加如下内容

  • job_name: nodes
    metrics_path: “/metrics”
    static_configs:
    • targets:
      • 192.168.200.141:9100
      • 192.168.200.138:9100
        labels:
        service: test

#重新载入配置
curl -X POST http://127.0.0.1:9090/-/reload 或 systemctl reload prometheus

监控MySQL数据库

监控nginx

安装grafana

yum install -y https://dl.grafana.com/enterprise/release/grafana-enterprise-11.1.3-1.x86_64.rpmsystemctl start grafana-server
systemctl enable grafana-server
netstat -natp | grep :3000

http://ip:3000
在这里插入图片描述配置数据源
Connections -> Data Sources -> Add data source -> 选择 Prometheus
HTTP -> URL 输入 http://192.168.200.138:9090
点击 Save & Test

导入grafana模版

浏览器访问:https://grafana.com/grafana/dashboards ,在页面中搜索 node exporter ,选择适合的面板,点击 Copy ID 或者 Download JSON在 grafana 页面中,+ Create -> Import ,输入面板 ID 号或者上传 JSON 文件,点击 Load,即可导入监控面板

在这里插入图片描述


http://www.ppmy.cn/ops/86940.html

相关文章

ChatGPT的原理和成本

ChatGPT就是人机交互的一个底层系统&#xff0c;某种程度上可以类比于操作系统。在这个操作系统上&#xff0c;人与AI之间的交互用的是人的语言&#xff0c;不再是冷冰冰的机器语言&#xff0c;或者高级机器语言&#xff0c;当然&#xff0c;在未来的十来年内&#xff0c;机器语…

【WRF安装第三期(Ubuntu)】搭建WRF编译所需系统-第三方依赖库安装

WRF安装第三期&#xff1a;搭建WRF编译所需系统-第三方依赖库安装 1 设置环境变量1.0 支持库的下载1.1 打开环境变量文本1.2 输入环境变量设置1.3 重新生效环境变量 2 构建第三方依赖库&#xff08;Building Libraries&#xff09;2.0 进入LIBRARIES文件夹2.1 netcdf的安装【必…

长短期记忆网络(LSTM)预测模型及其Python和MATLAB实现

## LSTM预测模型背景 长短期记忆网络&#xff08;Long Short-Term Memory&#xff0c;LSTM&#xff09;是一种特殊的递归神经网络&#xff08;RNN&#xff09;&#xff0c;于1997年首次由Sepp Hochreiter和Jrgen Schmidhuber提出。LSTM主要用于处理和预测序列数据中的时间依赖…

OpenStack——存储服务

存储侧&#xff1a; 块存储 文件存储 对象存储 存储简介 特点&#xff1a; 1、OS盘只能使用块存储 2、不能实现共享【不能解决两个主机同时去读写同一个block的问题】 3、性能最优 filesystem——文件存储 VIMS&#xff1a;高可用文件系统 ——提供了锁机制 对象存储 ——解…

WordPress建站:如何使用Hostinger搭建WordPress外贸独立站

随着电商平台竞争的加剧&#xff0c;许多外贸从业者意识到减少对平台依赖的重要性&#xff0c;并选择搭建自己的外贸独立站来获得更多的控制权和灵活性。即使是没有建站基础的新手&#xff0c;也可以通过学习建站来实现这一目标。下面是一个适用于新手的外贸建站教程&#xff0…

网络模型的使用以及修改 pytorch

VGG16_Weights.DEFAULT 或 VGG16_Weights.IMAGENET1K_V1&#xff1a;使用在 ImageNet 上训练的权重 import torchvision from torch import nnvgg16_false torchvision.models.vgg16() vgg16_true torchvision.models.vgg16(weightsDEFAULT) print(vgg16_true) train_data …

Python 爬虫入门(一):从零开始学爬虫 「详细介绍」

Python 爬虫入门&#xff08;一&#xff09;&#xff1a;从零开始学爬虫 「详细介绍」 前言1.爬虫概念1.1 什么是爬虫&#xff1f;1.2 爬虫的工作原理 2. HTTP 简述2.1 什么是 HTTP&#xff1f;2.2 HTTP 请求2.3 HTTP 响应2.4 常见的 HTTP 方法 3. 网页的组成3.1 HTML3.2 CSS3.…

Vue 3 中使用 inMap.js 实现蜂窝热力图的可视化

本文由ScriptEcho平台提供技术支持 项目地址&#xff1a;传送门 Vue 3 中使用 inMap.js 实现蜂窝热力图的可视化 应用场景介绍 蜂窝热力图是一种可视化技术&#xff0c;用于在地图上显示数据的分布情况。它将数据点划分为六边形单元格&#xff0c;并根据单元格内数据的密度…