Prometheus的介绍及初步使用

 


一、Prometheus

  • 介绍
    prometheus是一个开源的集监控和报警等多个功能于一体的开源的应用状态监控系统。prometheus会定期从指定的目标处获取应用的性能指标信息(该信息应当由应用本身发布),然后存储起来,以供查询及分析,如果您还启用了监控功能,prometheus还会使用它的Alertmamanger系统使用一定方式将告警信息发布出去。
  • 应用架构图

     

    prometheus架构图


二、Prometheus的安装及配置

  • 下载地址
  • 进入到prometheus的目录,打开配置文件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=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
    - targets: ['localhost:9090']

  - job_name: 'springboot'
    scrape_interval: 5s
    metrics_path: "/actuator/prometheus"
    static_configs:
    - targets: ['localhost:8080']

scrape_config是用来配置需要进行监控的任务(job),每个任务对应一个或多个待监控的容器,默认配置只有名为“prometheus”的任务,该任务会从目标localhost:9090/metrics处获取发布的性能指标信息,第二个任务是我配置的,用于模拟真实环境中的一个待监控的应用,该应用是一个springboot项目,你可以从项目地址处克隆它,该应用会将相关性能指标信息发布到localhost:8080/actuactor/prometheus


三、Prometheus的简单使用

  • 运行springboot项目,打开浏览器访问localhost:8080/actuactor/prometheus,你会看到一些具有固定格式的性能指标信息
# HELP jvm_classes_unloaded_classes_total The total number of classes unloaded since the Java virtual machine has started execution
# TYPE jvm_classes_unloaded_classes_total counter
jvm_classes_unloaded_classes_total 0.0
# HELP tomcat_sessions_active_current_sessions  
# TYPE tomcat_sessions_active_current_sessions gauge
tomcat_sessions_active_current_sessions 0.0
# HELP jvm_buffer_count_buffers An estimate of the number of buffers in the pool
# TYPE jvm_buffer_count_buffers gauge
jvm_buffer_count_buffers{id="mapped",} 0.0
jvm_buffer_count_buffers{id="direct",} 1.0
# HELP jvm_gc_max_data_size_bytes Max size of old generation memory pool
# TYPE jvm_gc_max_data_size_bytes gauge
jvm_gc_max_data_size_bytes 0.0

每一种性能指标信息前面都加上了相关注释,用来告知该性能指标的类型等信息,且都有以下格式指标名{名值对} 指标值

  • 运行prometheus
$ prometheus --config.file=prometheus.yml
  • prometheus基本功能
    • http://localhost:9090/targets会显示prometheus监控的所有任务,并显示这些任务的状态信息,标签信息等等
    • http://localhost:9090/config显示prometheus的配置信息
    • http://localhost:9090/status显示prometheus自身的一些运行状态信息等等
    • http://localhost:9090/graph可以在该页面进行监控信息的查询和图标分析,在“expression”输入框输入PromQL表达式后点击“execute”就可以进行查询了,下方有“console”和“graph”两个按钮,前者显示普通的监控信息文本,后者显示图形化后数据界面

参考文档:
[1] Prometheus overview
[2] First steps with Prometheus

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值