├── .gitignore ├── .gitmodules ├── LICENSE ├── README.rst ├── meta.yaml ├── pillar_examples └── common.sls ├── states ├── _user.sls ├── collectd_exporter.sls ├── defaults.yaml ├── node_exporter.sls └── server.sls └── test ├── nodes.yaml.dist └── shared ├── boxes └── .gitkeep ├── misc └── .gitkeep └── salt └── devenv └── .gitkeep /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled source # 2 | ################### 3 | *.class 4 | *.com 5 | *.dll 6 | *.exe 7 | *.o 8 | *.so 9 | 10 | # Packages # 11 | ############ 12 | # it's better to unpack these files and commit the raw source 13 | # git has its own built in compression methods 14 | *.7z 15 | *.bzip2 16 | *.deb 17 | *.dmg 18 | *.gz 19 | *.iso 20 | *.jar 21 | *.rar 22 | *.rpm 23 | *.tar 24 | *.tgz 25 | *.udeb 26 | *.war 27 | *.zip 28 | 29 | # Logs and databases # 30 | ###################### 31 | *.log 32 | *.sql 33 | *.sqlite 34 | 35 | # OS generated files # 36 | ###################### 37 | *.pyc 38 | *.slsc 39 | .DS_Store 40 | .DS_Store? 41 | .Spotlight-V100 42 | .Trashes 43 | ._* 44 | Thumbs.db 45 | *.pyc 46 | *.slsc 47 | .tox/ 48 | ehthumbs.db 49 | 50 | # IDEs and editors # 51 | #################### 52 | *.iml 53 | *.sw* 54 | *.tmp 55 | *~ 56 | .idea 57 | .netrwhist 58 | .project 59 | 60 | # Development VMs and containers # 61 | ################################## 62 | *.box 63 | .vagrant/ 64 | test/.env 65 | test/.vagrant/ 66 | test/nodes.yaml 67 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "vagrant"] 2 | path = vagrant 3 | url = https://github.com/bechtoldt/iac-vagrant 4 | [submodule "test/vagrant"] 5 | path = test/vagrant 6 | url = https://github.com/bechtoldt/iac-vagrant 7 | [submodule "test/vagrant-assets"] 8 | path = test/vagrant-assets 9 | url = https://github.com/bechtoldt/vagrant-assets 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 Arnold Bechtoldt 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | ============================ 2 | saltstack-prometheus-formula 3 | ============================ 4 | 5 | 6 | .. image:: https://img.shields.io/badge/donate-flattr-red.svg 7 | :alt: Donate via flattr 8 | :target: https://flattr.com/profile/bechtoldt 9 | 10 | .. image:: https://img.shields.io/badge/license-Apache--2.0-blue.svg 11 | :alt: Apache-2.0-licensed 12 | :target: https://github.com/bechtoldt/saltstack-prometheus-formula/blob/master/LICENSE 13 | 14 | .. image:: https://img.shields.io/badge/chat-gitter-brightgreen.svg 15 | :alt: Join Gitter Chat 16 | :target: https://gitter.im/bechtoldt/saltstack-prometheus-formula?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge 17 | 18 | .. image:: https://img.shields.io/badge/chat-%23salt%20@%20Freenode-brightgreen.svg 19 | :alt: Join Internet Relay Chat 20 | :target: http://webchat.freenode.net/?channels=%23salt&uio=d4 21 | 22 | SaltStack formula to manage Prometheus, a service monitoring system and time series database. 23 | 24 | .. contents:: 25 | :backlinks: none 26 | :local: 27 | 28 | 29 | Instructions 30 | ------------ 31 | 32 | Please refer to https://github.com/bechtoldt/formula-docs to learn how to use 33 | this formula, how it is built and how you can add your changes. 34 | 35 | 36 | **NOTICE:** This formula might uses the formhelper module which is a very useful Salt execution module that isn't available in upstream yet. Please consider retrieving it manually from https://github.com/bechtoldt/salt-modules and make it available to your Salt installation. Read `SaltStack documentation `_ to see how this can be achieved. 37 | 38 | Take a look at older releases (branches) to get a version that isn't using the formhelper yet (if any). 39 | 40 | 41 | 42 | Contributing 43 | ------------ 44 | 45 | Contributions are welcome! All development guidelines we ask you to follow can 46 | be found at https://github.com/bechtoldt/formula-docs. 47 | 48 | In general: 49 | 50 | 1. Fork this repo on Github 51 | 2. Add changes, test them, update docs (README.rst) if possible 52 | 3. Submit your pull request (PR) on Github, wait for feedback 53 | 54 | But it’s better to `file an issue `_ with your idea first. 55 | 56 | 57 | TODO 58 | ---- 59 | 60 | * add instructions how to use formhelper, add information about it in the formula-docs (dependency), show up alternative? 61 | * table/ matrix: os/salt compatibility (dedicated file) 62 | * add list of available states 63 | * add tests 64 | 65 | 66 | Miscellaneous 67 | ------------- 68 | 69 | Recommended formulas: 70 | 71 | * SaltStack management: `saltstack-salt-formula `_ 72 | 73 | Further reading: 74 | 75 | * Documentation and Standardisation of SaltStack formulas: https://github.com/bechtoldt/formula-docs 76 | -------------------------------------------------------------------------------- /meta.yaml: -------------------------------------------------------------------------------- 1 | name: saltstack-prometheus-formula 2 | source: https://github.com/bechtoldt/saltstack-prometheus-formula 3 | summary: SaltStack formula to manage Prometheus, a service monitoring system and time series database. 4 | todo: 5 | - add instructions how to use formhelper, add information about it in the formula-docs (dependency), show up alternative? 6 | - 'table/ matrix: os/salt compatibility (dedicated file)' 7 | - add list of available states 8 | - add tests 9 | -------------------------------------------------------------------------------- /pillar_examples/common.sls: -------------------------------------------------------------------------------- 1 | prometheus: 2 | lookup: 3 | server: 4 | cur_version: 0.16.1 5 | versions: 6 | '0.16.1': 7 | # cd /vagrant/shared/misc && wget https://github.com/prometheus/prometheus/releases/download/0.16.1/prometheus-0.16.1.linux-amd64.tar.gz 8 | source: salt://misc/prometheus-0.16.1.linux-amd64.tar.gz 9 | source_hash: md5=ae89dcc61ad6b52caa4f9b652bebce36 10 | config: 11 | global: 12 | scrape_interval: 15s # By default, scrape targets every 15 seconds. 13 | evaluation_interval: 15s # By default, scrape targets every 15 seconds. 14 | # scrape_timeout is set to the global default (10s). 15 | 16 | # Attach these labels to any time series or alerts when communicating with 17 | # external systems (federation, remote storage, Alertmanager). 18 | external_labels: 19 | monitor: 'codelab-monitor' 20 | 21 | # A scrape configuration containing exactly one endpoint to scrape: 22 | # Here it's Prometheus itself. 23 | scrape_configs: 24 | # The job name is added as a label `job=` to any timeseries scraped from this config. 25 | - job_name: 'prometheus' 26 | 27 | # Override the global default and scrape targets from this job every 5 seconds. 28 | scrape_interval: 5s 29 | scrape_timeout: 10s 30 | 31 | target_groups: 32 | - targets: ['localhost:9090'] 33 | node_exporter: 34 | cur_version: 0.12.0rc1 35 | versions: 36 | '0.12.0rc1': 37 | # cd /vagrant/shared/misc && wget https://github.com/prometheus/node_exporter/releases/download/0.12.0rc1/node_exporter-0.12.0rc1.linux-amd64.tar.gz 38 | source: salt://misc/node_exporter-0.12.0rc1.linux-amd64.tar.gz 39 | source_hash: md5=43d253ea664ea446c6c4a42e03400b30 40 | collectd_exporter: 41 | cur_version: 0.2.0 42 | versions: 43 | '0.2.0': 44 | # cd /vagrant/shared/misc && wget https://github.com/prometheus/collectd_exporter/releases/download/0.2.0/collectd_exporter-0.2.0.linux-amd64.tar.gz 45 | source: salt://misc/collectd_exporter-0.2.0.linux-amd64.tar.gz 46 | source_hash: md5=2e43f4431375aae3afee8ad92f9e0970 47 | 48 | 49 | -------------------------------------------------------------------------------- /states/_user.sls: -------------------------------------------------------------------------------- 1 | #!jinja|yaml 2 | 3 | group_prometheus: 4 | group: 5 | - present 6 | - name: prometheus 7 | - system: True 8 | 9 | user_prometheus: 10 | user: 11 | - present 12 | - name: prometheus 13 | - groups: 14 | - prometheus 15 | - home: /srv/prometheus 16 | - createhome: True 17 | - shell: /bin/false 18 | - system: True 19 | -------------------------------------------------------------------------------- /states/collectd_exporter.sls: -------------------------------------------------------------------------------- 1 | #!jinja|yaml 2 | 3 | {% set datamap = salt['formhelper.defaults']('prometheus', saltenv) %} 4 | 5 | # SLS includes/ excludes 6 | include: {{ datamap.sls_include|default(['._user']) }} 7 | extend: {{ datamap.sls_extend|default({}) }} 8 | 9 | 10 | {% for v_id, version in datamap.collectd_exporter.versions|default({})|dictsort %} 11 | prometheus_collectd_exporter_version_{{ v_id }}: 12 | archive: 13 | - extracted 14 | - name: /srv/prometheus-collectd_exporter/{{ v_id }} 15 | - source: {{ version.source }} 16 | - source_hash: {{ version.source_hash }} 17 | - user: prometheus 18 | - group: prometheus 19 | - keep: True 20 | - archive_format: {{ version.archive_format|default('tar') }} 21 | {% endfor %} 22 | 23 | prometheus_collectd_exporter_link_current_version: 24 | file: 25 | - symlink 26 | - name: /srv/prometheus-collectd_exporter/current 27 | - target: /srv/prometheus-collectd_exporter/{{ datamap.collectd_exporter.cur_version }}/ 28 | - user: prometheus 29 | - group: prometheus 30 | 31 | {% if salt['grains.get']('init') == 'systemd' %} 32 | prometheus_collectd_exporter_service_script: 33 | file: 34 | - managed 35 | - name: /etc/systemd/system/prometheus-collectd_exporter.service 36 | - user: root 37 | - group: root 38 | - contents: | 39 | [Unit] 40 | Description=prometheus 41 | After=syslog.target network.target 42 | 43 | [Service] 44 | Type=simple 45 | RemainAfterExit=no 46 | WorkingDirectory=/srv/prometheus-collectd_exporter/current 47 | User=prometheus 48 | Group=prometheus 49 | ExecStart=/srv/prometheus-collectd_exporter/current/collectd_exporter -log.level info 50 | 51 | [Install] 52 | WantedBy=multi-user.target 53 | {% endif %} 54 | 55 | prometheus_collectd_exporter_service: 56 | service: 57 | - running 58 | - name: prometheus-collectd_exporter 59 | - enable: True 60 | -------------------------------------------------------------------------------- /states/defaults.yaml: -------------------------------------------------------------------------------- 1 | kernel: 2 | Linux: {} 3 | -------------------------------------------------------------------------------- /states/node_exporter.sls: -------------------------------------------------------------------------------- 1 | #!jinja|yaml 2 | 3 | {% set datamap = salt['formhelper.defaults']('prometheus', saltenv) %} 4 | 5 | # SLS includes/ excludes 6 | include: {{ datamap.sls_include|default(['._user']) }} 7 | extend: {{ datamap.sls_extend|default({}) }} 8 | 9 | 10 | {% for v_id, version in datamap.node_exporter.versions|default({})|dictsort %} 11 | prometheus_node_exporter_version_{{ v_id }}: 12 | archive: 13 | - extracted 14 | - name: /srv/prometheus-node_exporter/{{ v_id }} 15 | - source: {{ version.source }} 16 | - source_hash: {{ version.source_hash }} 17 | - user: prometheus 18 | - group: prometheus 19 | - keep: True 20 | - archive_format: {{ version.archive_format|default('tar') }} 21 | {% endfor %} 22 | 23 | prometheus_node_exporter_link_current_version: 24 | file: 25 | - symlink 26 | - name: /srv/prometheus-node_exporter/current 27 | - target: /srv/prometheus-node_exporter/{{ datamap.node_exporter.cur_version }}/ 28 | - user: prometheus 29 | - group: prometheus 30 | 31 | {% if salt['grains.get']('init') == 'systemd' %} 32 | prometheus_node_exporter_service_script: 33 | file: 34 | - managed 35 | - name: /etc/systemd/system/prometheus-node_exporter.service 36 | - user: root 37 | - group: root 38 | - contents: | 39 | [Unit] 40 | Description=prometheus 41 | After=syslog.target network.target 42 | 43 | [Service] 44 | Type=simple 45 | RemainAfterExit=no 46 | WorkingDirectory=/srv/prometheus-node_exporter/current 47 | User=prometheus 48 | Group=prometheus 49 | ExecStart=/srv/prometheus-node_exporter/current/node_exporter -log.level info 50 | 51 | [Install] 52 | WantedBy=multi-user.target 53 | {% endif %} 54 | 55 | prometheus_node_exporter_service: 56 | service: 57 | - running 58 | - name: prometheus-node_exporter 59 | - enable: True 60 | -------------------------------------------------------------------------------- /states/server.sls: -------------------------------------------------------------------------------- 1 | #!jinja|yaml 2 | 3 | {% set datamap = salt['formhelper.defaults']('prometheus', saltenv) %} 4 | 5 | # SLS includes/ excludes 6 | include: {{ datamap.sls_include|default(['._user']) }} 7 | extend: {{ datamap.sls_extend|default({}) }} 8 | 9 | 10 | {% for v_id, version in datamap.server.versions|default({})|dictsort %} 11 | prometheus_server_version_{{ v_id }}: 12 | archive: 13 | - extracted 14 | - name: /srv/prometheus/{{ v_id }} 15 | - source: {{ version.source }} 16 | - source_hash: {{ version.source_hash }} 17 | - user: prometheus 18 | - group: prometheus 19 | - keep: True 20 | - archive_format: {{ version.archive_format|default('tar') }} 21 | 22 | prometheus_server_{{ v_id }}_config: 23 | file: 24 | - serialize 25 | - name: /srv/prometheus/{{ v_id }}/prometheus-{{ datamap.server.cur_version }}.linux-amd64/prometheus.yaml 26 | - user: prometheus 27 | - group: prometheus 28 | - mode: 640 29 | - dataset_pillar: prometheus:lookup:server:versions:{{ v_id }}:config 30 | - watch_in: 31 | - service: prometheus 32 | {% endfor %} 33 | 34 | prometheus_server_link_current_version: 35 | file: 36 | - symlink 37 | - name: /srv/prometheus/current 38 | - target: /srv/prometheus/{{ datamap.server.cur_version }}/prometheus-{{ datamap.server.cur_version }}.linux-amd64 39 | - user: prometheus 40 | - group: prometheus 41 | 42 | {% if salt['grains.get']('init') == 'systemd' %} 43 | prometheus_server_service_script: 44 | file: 45 | - managed 46 | - name: /etc/systemd/system/prometheus.service 47 | - user: root 48 | - group: root 49 | - contents: | 50 | [Unit] 51 | Description=prometheus 52 | After=syslog.target network.target 53 | 54 | [Service] 55 | Type=simple 56 | RemainAfterExit=no 57 | WorkingDirectory=/srv/prometheus/current 58 | User=prometheus 59 | Group=prometheus 60 | ExecStart=/srv/prometheus/current/prometheus -config.file=/srv/prometheus/current/prometheus.yaml -log.level info 61 | 62 | [Install] 63 | WantedBy=multi-user.target 64 | {% endif %} 65 | 66 | prometheus_server_service: 67 | service: 68 | - running 69 | - name: prometheus 70 | - enable: True 71 | -------------------------------------------------------------------------------- /test/nodes.yaml.dist: -------------------------------------------------------------------------------- 1 | --- 2 | defaults: 3 | domain: prometheus.local.arnoldbechtoldt.com 4 | base_box: bechtoldt/centos-7.0-salt-2015.8.0 5 | osfam: rhel 6 | synced_folders: 7 | # Common folders 8 | - src: ../shared/misc 9 | dst: /vagrant/shared/misc 10 | 11 | # Salt related folders 12 | - src: ../shared/salt/devenv 13 | dst: /vagrant/shared/salt/devenv 14 | - src: ../../../salt-modules/_modules 15 | dst: /vagrant/salt/_modules 16 | - src: ../../../salt-modules/_states 17 | dst: /vagrant/salt/_states 18 | provision: 19 | - name: basic 20 | # - name: saltstack_install_bootstrap 21 | - name: saltstack_formulas 22 | formulas: 23 | - name: prometheus 24 | base_dir: ../.. 25 | - name: saltstack_config 26 | - name: saltstack_services 27 | nodes: 28 | prometheus1: {} 29 | -------------------------------------------------------------------------------- /test/shared/boxes/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arnisoph/saltstack-prometheus-formula/6cb8d4bf1197d9b6f559ee8acdb05d0cbf517c5b/test/shared/boxes/.gitkeep -------------------------------------------------------------------------------- /test/shared/misc/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arnisoph/saltstack-prometheus-formula/6cb8d4bf1197d9b6f559ee8acdb05d0cbf517c5b/test/shared/misc/.gitkeep -------------------------------------------------------------------------------- /test/shared/salt/devenv/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arnisoph/saltstack-prometheus-formula/6cb8d4bf1197d9b6f559ee8acdb05d0cbf517c5b/test/shared/salt/devenv/.gitkeep --------------------------------------------------------------------------------