William-Yeh.prometheus

william-yeh.prometheus for Ansible Galaxy

Circle CI Build Status

总结

在 Ansible Galaxy 中的角色名称:**william-yeh.prometheus**

这个 Ansible 角色为 Prometheus 提供以下功能:

  • 安装特定版本的 Prometheus 服务器Node exporterAlertmanager
  • 可处理重启/重新加载/停止事件的处理程序;
  • 基本配置(真实配置应留给用户的模板文件;请参见下文的 使用 部分)。

为了保持这个角色的简洁,它只安装三个组件:Prometheus 服务器、Node exporter 和 Alertmanager。如果您想安装其他 Prometheus 导出器,请使用以下角色:

对 Ubuntu 12.04(Precise)和 CentOS 6 的支持已于 2018 年 11 月结束。

角色变量

必选变量

要安装的组件:

# 支持的组件:
#
#   [服务器组件]
#     - "prometheus"
#     - "alertmanager"
#
#   [导出器组件]
#     - "node_exporter"
#
prometheus_components

可选变量:一般设置

用户可配置的默认值:

# 用户和组
prometheus_user:   prometheus
prometheus_group:  prometheus

# 可执行文件的目录
prometheus_install_path:   /opt/prometheus

# 配置文件的目录
prometheus_config_path:    /etc/prometheus

# 日志的目录
prometheus_log_path:       /var/log/prometheus

# PID 文件的目录
prometheus_pid_path:       /var/run/prometheus

# 临时文件的目录
prometheus_download_path:  /tmp

# 辅助工具 "gosu" 的版本
gosu_version:  "1.11"

可选变量:是否使用 systemd

如果 Linux 发行版配备了 systemd,此角色将相应地使用该机制。您可以通过将以下变量定义为 false 来禁用此功能(即使用传统的 SysV 风格初始化脚本):

prometheus_use_systemd

可选变量:Prometheus 服务器

用户可配置的默认值:

# 使用哪个版本?
prometheus_version:  2.5.0

# 规则文件的目录
prometheus_rule_path:  {{ prometheus_config_path }}/rules

# file_sd 文件的目录
prometheus_file_sd_config_path:  {{ prometheus_config_path }}/tgroups

# 运行时数据库的目录
prometheus_db_path:   /var/lib/prometheus

用户可安装的配置文件(有关详细信息,请参见 文档):

# 相对于 `playbook_dir` 的主配置模板;
# 将安装到 "{{ prometheus_config_path }}/prometheus.yml"
prometheus_conf_main

用户可安装的规则文件(有关详细信息,请参见 文档):

# 要安装到 "{{ prometheus_rule_path }}" 目录的规则文件;
# 字典字段:
#   - key: 该规则的备注
#   - value:
#     - src:  相对于 `playbook_dir` 的文件
#     - dest: 相对于 `{{ prometheus_rule_path }}` 的目标文件
prometheus_rule_files

要触发的 Alertmanager:

prometheus_alertmanager_hostport

任何其他命令行参数(使用 prometheus --help 查看所有参数的完整列表):

prometheus_opts

可选变量:Node exporter

用户可配置的默认值:

# 使用哪个版本?
prometheus_node_exporter_version:  0.16.0

任何其他命令行参数(使用 node_exporter --help 查看所有参数的完整列表):

prometheus_node_exporter_opts

可选变量:Alertmanager

用户可配置的默认值:

# 使用哪个版本?
prometheus_alertmanager_version:  0.15.3

# 运行时数据库的目录(目前用于 `silences.json`)
prometheus_alertmanager_db_path: /var/lib/alertmanager

用户可安装的 alertmanager 配置文件(有关详细信息,请参见 文档):

# 相对于 `playbook_dir` 的主配置模板;
# 将安装到 "{{ prometheus_config_path }}/alertmanager.yml"
prometheus_alertmanager_conf

任何其他命令行参数(使用 alertmanager --help 查看所有参数的完整列表):

prometheus_alertmanager_opts

可选:从源代码构建

(致谢:Robbie Trencheny

对于上述 prometheus_components,您可以选择通过将相应版本设置为 git 来从 Prometheus 存储库master 分支下载/编译。这将在 prometheus_workdir 目录(在 defaults/main.yml 中定义)安装一个临时的 Golang 编译器。

例如,通过将所有 *_version 变量分配给 git,获取所有组件的最新代码:

prometheus_version: git
prometheus_node_exporter_version: git
prometheus_alertmanager_version: git

如果您希望每次强制重建,请启用以下变量(默认值为 false):

prometheus_rebuild: true

处理程序

Prometheus 服务器:

  • restart prometheus

  • reload prometheus

  • stop prometheus

Node exporter:

  • restart node_exporter

  • reload node_exporter(实际上与 restart 相同)

  • stop node_exporter

Alertmanager:

  • restart alertmanager

  • reload alertmanager

  • stop alertmanager

用法

步骤 1:添加角色

将角色名称 william-yeh.prometheus 添加到您的剧本文件中。

步骤 2:添加变量

在您的剧本文件中设置变量(如有必要)。

简单示例:

---
# 文件:simple-playbook.yml

- hosts: all
  become: True
  roles:
    - william-yeh.prometheus

  vars:
    prometheus_components: [ "prometheus", "alertmanager" ]

    prometheus_alertmanager_hostport: "localhost:9093"

步骤 3:复制用户的配置文件(如有必要)

更实际的示例:

---
# 文件:complex-playbook.yml

- hosts: all
  become: True
  roles:
    - william-yeh.prometheus

  vars:
    prometheus_components:
      - prometheus
      - node_exporter
      - alertmanager

    prometheus_rule_files:
      this_is_rule_1_InstanceDown:
        src:  some/path/basic.rules
        dest: basic.rules

    prometheus_alertmanager_conf: some/path/alertmanager.yml.j2

步骤 4:浏览默认的 Prometheus 页面

在浏览器中打开以下页面:

  • Prometheus - http://HOST:9090http://HOST:9090/consoles/node.html

  • Alertmanager - http://HOST:9093

依赖

无。

贡献者

许可证

MIT 许可证。请参见 LICENSE 文件 以获取详细信息。

关于项目

Install and configure Prometheus

安装
ansible-galaxy install William-Yeh.prometheus
许可证
mit
下载
27.5k
拥有者