prometheus-普罗米修斯学习应用

HanGR 于 2025-08-21 发布


背景


prometheus概述

介绍


特性

1. 多维数据模型
2. PromQL 查询语言
3. 时间序列数据库
4. 数据抓取模型
5. 丰富的生态系统
6. 报警功能
7. 服务发现
8. 可视化工具


主要应用场景


生态系统组件


prometheus架构

组件介绍

1. Prometheus Server
2. Service Discovery
3.Jobs/Exporters
4. Pushgateway
5. Alertmanager
6. Visualization and API Clients


工作流程总结

通过这种架构设计,Prometheus 提供了一个灵活、高效且可扩展的监控和报警解决方案,适用于现代云原生和分布式系统的监控需求.


prometheus安装

准备镜像

编写配置文件

# Prometheus 配置文件
global:
  scrape_interval: 15s      # 全局抓取间隔
  evaluation_interval: 15s  # 规则评估间隔


# 抓取配置
scrape_configs:
  # Prometheus 自身监控
  - job_name: 'prometheus'
    metrics_path: /metrics
    static_configs:
      - targets: ['localhost:9090']
      
 
  # Spring Boot 应用监控
  - job_name: 'XXXXX'
    metrics_path: '/api/actuator/prometheus'  # Spring Boot Actuator 端点
    static_configs:
      - targets: ['localhost:8080']  # 应用服务器地址

准备dockerfile

# 使用阿里云私有仓库的镜像作为基础镜像
FROM registry.cn-beijing.aliyuncs.com/xxxxxx/prometheus:main

# 设置prometheus配置文件
COPY prometheus.yml /etc/prometheus/prometheus.yml

构建镜像

docker build -t prometheus .

启动容器

# 创建数据卷
docker volume create prometheus-data

# 启动容器
docker run -dit --name prometheus -p 9090:9090 -v prometheus-data:/prometheus prometheus:latest

验证


参考