
文章插图
图片
从上图可以看出,Prometheus 生态系统包含了几个关键的组件:Prometheus server、Pushgateway、Alertmanager、Web UI 等,但是大多数组件都不是必需的,其中最核心的组件当然是 Prometheus server,它负责收集和存储指标数据,支持表达式查询,和告警的生成 。接下来我们就来安装 Prometheus server 。
二、安装 Prometheus serverPrometheus 可以支持多种安装方式,包括 Docker、Ansible、Chef、Puppet、Saltstack 等 。下面介绍最简单的两种方式,一种是直接使用编译好的可执行文件,开箱即用,另一种是使用 Docker 镜像 。
2.1 开箱即用首先从 官网的下载页面 获取 Prometheus 的最新版本和下载地址,目前最新版本是 2.4.3(2018年10月),执行下面的命令下载并解压:
【号称下一代监控系统,来看看它有多强】
$ wget https://github.com/prometheus/prometheus/releases/download/v2.4.3/prometheus-2.4.3.linux-amd64.tar.gz $ tar xvfz prometheus-2.4.3.linux-amd64.tar.gz 然后切换到解压目录,检查 Prometheus 版本:$ cd prometheus-2.4.3.linux-amd64 $ ./prometheus --version prometheus, version 2.4.3 (branch: HEAD, revision: 167a4b4e73a8eca8df648d2d2043e21bdb9a7449) build user: root@1e42b46043e9 build date: 20181004-08:42:02 go version: go1.11.1 运行 Prometheus server:$ ./prometheus --config.file=prometheus.yml 2.2 使用 Docker 镜像使用 Docker 安装 Prometheus 更简单,运行下面的命令即可:$ sudo docker run -d -p 9090:9090 prom/prometheus 一般情况下,我们还会指定配置文件的位置:$ sudo docker run -d -p 9090:9090 -v ~/docker/prometheus/:/etc/prometheus/ prom/prometheus 我们把配置文件放在本地~/docker/prometheus/prometheus.yml,这样可以方便编辑和查看,通过 -v 参数将本地的配置文件挂载到 /etc/prometheus/ 位置,这是 prometheus 在容器中默认加载的配置文件位置 。如果我们不确定默认的配置文件在哪,可以先执行上面的不带 -v 参数的命令,然后通过 docker inspect 命名看看容器在运行时默认的参数有哪些(下面的 Args 参数):
$ sudo docker inspect 0c [...] "Id": "0c4c2d0eed938395bcecf1e8bb4b6b87091fc4e6385ce5b404b6bb7419010f46", "Created": "2018-10-15T22:27:34.56050369Z", "Path": "/bin/prometheus", "Args": [ "--config.file=/etc/prometheus/prometheus.yml", "--storage.tsdb.path=/prometheus", "--web.console.libraries=/usr/share/prometheus/console_libraries", "--web.console.templates=/usr/share/prometheus/consoles" ], [...] 2.3 配置 Prometheus正如上面两节看到的,Prometheus 有一个配置文件,通过参数 --config.file 来指定,配置文件格式为 YAML 。我们可以打开默认的配置文件 prometheus.yml 看下里面的内容:/etc/prometheus $ cat 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']
推荐阅读
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Intel|下一代硅光子芯片技术:Intel、NVIDIA都出手了
- 翡翠|拉什莫尔山号称石像山,山后还有一个密室,里面藏着“珍贵”文物
- iPad Pro M2,m2芯片的ipadpro-
- 男士是肝炎的能遗传给下一代吗
- 怎样锻炼肾功能,怎样瘦肚子最快最有效
- 三国中的庞统为什么称为凤雏?庞统号称凤雏
- 树莓派搭建网络视频实时监控系统
- 张飞号称什么将军 五虎上将张飞会返场吗
- 开源监控系统wgcloud-v3.3.0发布
- CentOS7下部署开源网络监控系统LibreNMS
