kibatic.prometheus

kibatic.prometheus for Ansible Galaxy

Circle CI Build Status

概述

Ansible Galaxy 中的角色名称:**kibatic.prometheus**

该 Ansible 角色具有以下对于 Prometheus 的功能:

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

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

角色变量

必需变量

要安装的组件:

# 支持的组件:
#
#   [服务器组件]
#     - "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.10"

可选变量:使用 systemd 或不使用

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

# 目前,仅支持 node_exporter。
prometheus_node_exporter_use_systemd

可选变量:Prometheus 服务器

用户可配置的默认值:

# 使用哪个版本?
prometheus_version:  1.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

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

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

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

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

触发的 Alertmanager:

prometheus_alertmanager_url

额外的命令行参数(如有)(使用 prometheus --help 查看完整参数列表):

prometheus_opts

可选变量:Node exporter

用户可配置的默认值:

# 使用哪个版本?
prometheus_node_exporter_version:  0.13.0

额外的命令行参数(如有)(使用 node_exporter --help 查看完整参数列表):

prometheus_node_exporter_opts

可选变量:Alertmanager

用户可配置的默认值:

# 使用哪个版本?
prometheus_alertmanager_version:  0.5.1

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

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

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

额外的命令行参数(如有)(使用 alertmanager --help 查看完整参数列表):

prometheus_alertmanager_opts

可选:从源树构建

(致谢:Robbie Trencheny

对于上述的 prometheus_components,您可以选择通过设置相应的版本为 gitPrometheus 代码仓库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

使用

第一步:添加角色

将角色名称 kibatic.prometheus 添加到您的 playbook 文件中。

第二步:添加变量

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

简单示例:

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

- hosts: all
  become: True
  roles:
    - kibatic.prometheus

  vars:
    prometheus_components: [ "prometheus", "alertmanager" ]
    prometheus_alertmanager_url: "http://localhost:9093/"

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

更实用的示例:

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

- hosts: all
  become: True
  roles:
    - kibatic.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

第四步:浏览默认的 Prometheus 页面

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

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

依赖关系

无。

贡献者

许可证

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

关于项目

Install and configure Prometheus

安装
ansible-galaxy install kibatic.prometheus
许可证
mit
下载
1k
拥有者
Ajoutez de l'intelligence à vos systèmes