初识Prometheus

Posted twobrother

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了初识Prometheus相关的知识,希望对你有一定的参考价值。

安装Prometheus Server

Prometheus基于Golang编写,编译后的软件包,不依赖于任何的第三方依赖。用户只需要下载对应平台的二进制包,解压并且添加基本的配置即可正常启动Prometheus Server。

从二进制包安装

对于非Docker用户,可以从https://prometheus.io/download/找到最新版本的Prometheus Sevrer软件包:

  1. export VERSION=2.4.3
  2. curl -LO https://github.com/prometheus/prometheus/releases/download/v$VERSION/prometheus-$VERSION.darwin-amd64.tar.gz

解压,并将Prometheus相关的命令,添加到系统环境变量路径即可:

  1. tar -xzf prometheus-${VERSION}.darwin-amd64.tar.gz
  2. cd prometheus-${VERSION}.darwin-amd64

解压后当前目录会包含默认的Prometheus配置文件promethes.yml:

  1. # my global config
  2. global:
  3. scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  4. evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  5. # scrape_timeout is set to the global default (10s).
  6. # Alertmanager configuration
  7. alerting:
  8. alertmanagers:
  9. - static_configs:
  10. - targets:
  11. # - alertmanager:9093
  12. # Load rules once and periodically evaluate them according to the global ‘evaluation_interval‘.
  13. rule_files:
  14. # - "first_rules.yml"
  15. # - "second_rules.yml"
  16. # A scrape configuration containing exactly one endpoint to scrape:
  17. # Here it‘s Prometheus itself.
  18. scrape_configs:
  19. # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  20. - job_name: ‘prometheus‘
  21. # metrics_path defaults to ‘/metrics‘
  22. # scheme defaults to ‘http‘.
  23. static_configs:
  24. - targets: [‘localhost:9090‘]

Promtheus作为一个时间序列数据库,其采集的数据会以文件的形似存储在本地中,默认的存储路径为data/,因此我们需要先手动创建该目录:

  1. mkdir -p data

用户也可以通过参数--storage.tsdb.path="data/"修改本地数据存储的路径。

启动prometheus服务,其会默认加载当前路径下的prometheus.yaml文件:

  1. ./prometheus

正常的情况下,你可以看到以下输出内容:

  1. level=info ts=2018-10-23T14:55:14.499484Z caller=main.go:554 msg="Starting TSDB ..."
  2. level=info ts=2018-10-23T14:55:14.499531Z caller=web.go:397 component=web msg="Start listening for connections" address=0.0.0.0:9090
  3. level=info ts=2018-10-23T14:55:14.507999Z caller=main.go:564 msg="TSDB started"
  4. level=info ts=2018-10-23T14:55:14.508068Z caller=main.go:624 msg="Loading configuration file" filename=prometheus.yml
  5. level=info ts=2018-10-23T14:55:14.509509Z caller=main.go:650 msg="Completed loading of configuration file" filename=prometheus.yml
  6. level=info ts=2018-10-23T14:55:14.509537Z caller=main.go:523 msg="Server is ready to receive web requests."

使用容器安装

对于Docker用户,直接使用Prometheus的镜像即可启动Prometheus Server:

  1. docker run -p 9090:9090 -v /etc/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus

启动完成后,可以通过http://localhost:9090访问Prometheus的UI界面:

技术图片

以上是关于初识Prometheus的主要内容,如果未能解决你的问题,请参考以下文章

初识Prometheus

性能监控之初识 Prometheus

初识Spring源码 -- doResolveDependency | findAutowireCandidates | @Order@Priority调用排序 | @Autowired注入(代码片段

初识Spring源码 -- doResolveDependency | findAutowireCandidates | @Order@Priority调用排序 | @Autowired注入(代码片段

Java初识方法

初识OpenGL 片段着色器(Fragment Shader)