diff --git a/_modules/prometheus.py b/_modules/prometheus.py new file mode 100644 index 0000000..da5bcbc --- /dev/null +++ b/_modules/prometheus.py @@ -0,0 +1,68 @@ +# ------------------------------------------------------------- +# Salt — Prometheus execution module +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Project: Nasqueron +# Description: Functions related to Prometheus configuration +# License: BSD-2-Clause +# ------------------------------------------------------------- + + +SCRAPE_CONFIG_OPTIONS_RENAME = { + "name": "job_name", +} + +SCRAPE_CONFIG_OPTIONS_PASSTHROUGH = [ + "scheme", + "metrics_path", +] + + +def get_scrape_configs(): + configs = __pillar__.get("prometheus_scrape_jobs", {}).values() + return [_build_scrape_config(config) for config in configs] + + +def _build_scrape_config(config): + scrape_config = {} + + for key in SCRAPE_CONFIG_OPTIONS_PASSTHROUGH: + if key in config: + scrape_config[key] = config[key] + + for pillar_key, scrape_config_key in SCRAPE_CONFIG_OPTIONS_RENAME.items(): + if pillar_key in config: + scrape_config[scrape_config_key] = config[pillar_key] + + scrape_targets = [] + + for target in config.get("services_targets", []): + address = _resolve_service(target) + scrape_targets.append(address) + + for targets in config.get("services_targets_list", []): + addresses = _resolve_service_list(targets) + scrape_targets.extend(addresses) + + scrape_config["static_configs"] = [{"targets": scrape_targets}] + + return scrape_config + + +def _resolve_service(config): + if "service" not in config or "port" not in config: + raise ValueError("service and port keys are both required to define a service") + + key = "nasqueron_services:" + config["service"] + address = __salt__["pillar.get"](key) + + return address + ":" + str(config["port"]) + + +def _resolve_service_list(config): + if "service" not in config or "port" not in config: + raise ValueError("service and port keys are both required to define a service") + + key = "nasqueron_services:" + config["service"] + addresses = __salt__["pillar.get"](key) + + return [address + ":" + str(config["port"]) for address in addresses] diff --git a/_tests/data/prometheus.yaml b/_tests/data/prometheus.yaml new file mode 100644 index 0000000..ebfadc5 --- /dev/null +++ b/_tests/data/prometheus.yaml @@ -0,0 +1,21 @@ +nasqueron_services: + green: emerald + + blue: + all: + - cyan + - turquoise + - ultramarine + +prometheus_scrape_jobs: + green_nodes: + name: green + services_targets: + - service: green + port: 9090 + + blue_nodes: + name: blue + services_targets_list: + - service: "blue:all" + port: 9100 diff --git a/_tests/data/prometheus_scrape_configs.yml b/_tests/data/prometheus_scrape_configs.yml new file mode 100644 index 0000000..9034c6e --- /dev/null +++ b/_tests/data/prometheus_scrape_configs.yml @@ -0,0 +1,10 @@ +- job_name: green + static_configs: + - targets: + - emerald:9090 +- job_name: blue + static_configs: + - targets: + - cyan:9100 + - turquoise:9100 + - ultramarine:9100 diff --git a/_tests/modules/test_prometheus.py b/_tests/modules/test_prometheus.py new file mode 100755 index 0000000..ddfa5b6 --- /dev/null +++ b/_tests/modules/test_prometheus.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python3 + +from importlib.machinery import SourceFileLoader +import unittest + +salt_test_case = SourceFileLoader("salt_test_case", "salt_test_case.py").load_module() +prometheus = SourceFileLoader("prometheus", "../_modules/prometheus.py").load_module() + + +class Testinstance(unittest.TestCase, salt_test_case.SaltTestCase): + def setUp(self): + self.initialize_mocks() + self.instance = prometheus + + self.mock_pillar("data/prometheus.yaml") + + self.mock_salt() + self.mock_salt_pillar_get() + + def test_resolve_service(self): + service = { + "service": "green", + "port": "9090", + } + + self.assertEquals("emerald:9090", prometheus._resolve_service(service)) + + def test_resolve_service_list(self): + service = { + "service": "blue:all", + "port": "9090", + } + + expected = [ + "cyan:9090", + "turquoise:9090", + "ultramarine:9090", + ] + + self.assertEquals(expected, prometheus._resolve_service_list(service)) + + def test_get_scrape_configs(self): + expected = self.import_data_from_yaml("data/prometheus_scrape_configs.yml") + actual = prometheus.get_scrape_configs() + + self.assertEquals(expected, actual) + + +if __name__ == "__main__": + unittest.main() diff --git a/_tests/salt_test_case.py b/_tests/salt_test_case.py index 5aff1f2..abf7ec4 100644 --- a/_tests/salt_test_case.py +++ b/_tests/salt_test_case.py @@ -1,36 +1,54 @@ from importlib.machinery import SourceFileLoader import yaml class SaltTestCase: def initialize_mocks(self): source = SourceFileLoader("dunder", "mocks/dunder.py").load_module() self.pillar = source.dunder() self.salt = source.dunder() self.grains = source.dunder() @staticmethod def import_data_from_yaml(filename): with open(filename, "r") as fd: return yaml.safe_load(fd.read()) def mock_pillar(self, filename=None, target=None): if not target: target = self.instance if filename: self.pillar.data = self.import_data_from_yaml(filename) target.__pillar__ = self.pillar def mock_grains(self, target=None): if not target: target = self.instance target.__grains__ = self.grains def mock_salt(self, target=None): if not target: target = self.instance target.__salt__ = self.salt + + def mock_salt_pillar_get(self, target=None): + if not target: + target = self.instance + + target.__salt__["pillar.get"] = lambda key: pillar_get(target.__pillar__, key) + + +def pillar_get(pillar, key, default=""): + if ":" not in key: + return pillar.get(key, default) + + keys = key.split(":") + + data = pillar[keys[0]] + remaining_key = ":".join(keys[1:]) + + return pillar_get(data, remaining_key, default) diff --git a/pillar/observability/prometheus.sls b/pillar/observability/prometheus.sls new file mode 100644 index 0000000..debd3ce --- /dev/null +++ b/pillar/observability/prometheus.sls @@ -0,0 +1,50 @@ +# ------------------------------------------------------------- +# Salt configuration for Nasqueron servers +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Project: Nasqueron +# License: Trivial work, not eligible to copyright +# Description: Prometheus configuraiton +# ------------------------------------------------------------- + +# ------------------------------------------------------------- +# Scrape jobs +# +# Options supported from Prometheus scrape_config syntax: +# - name +# - scheme +# - metrics_path +# +# Options mapped with pillar/services/table.sls for services: +# - services_targets: list of services dictionaries +# - service: name in nasqueron_services pillar +# - port +# +# - services_targets_list will have the same behavior +# but will read a list of services in nasqueron_services +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +prometheus_scrape_jobs: + prometheus_itself: + name: prometheus + services_targets: + - service: prometheus + port: 9090 + + node_exporter: + name: node + services_targets_list: + - service: "all" + port: 9100 + + netbox: + name: netbox + scheme: https + services_targets: + - service: netbox_domain + port: 443 + + paas_docker: + name: docker + services_targets_list: + - service: "docker:all" + port: 9323 diff --git a/pillar/services/table.sls b/pillar/services/table.sls index a75bdf1..0446195 100644 --- a/pillar/services/table.sls +++ b/pillar/services/table.sls @@ -1,25 +1,45 @@ # ------------------------------------------------------------- # Salt configuration for Nasqueron servers # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Project: Nasqueron # License: Trivial work, not eligible to copyright # Description: Table of the services to use in configuration # ------------------------------------------------------------- nasqueron_services: # Complector services salt_primary: 172.27.27.7 salt_api_url: https://172.27.27.7:8300 vault: 172.27.27.7 vault_url: https://172.27.27.7:8200 # PaaS Docker docker: api: 172.27.27.5 cd: 172.27.27.5 notifications: 172.27.27.5 + all: + - 172.27.27.4 + - 172.27.27.5 # Databases db-A: 172.27.27.8 db-B: 172.27.27.9 + + # NetBox + netbox_domain: netbox.nasqueron.org + + # Observability + prometheus: 172.27.27.35 + + all: + - 172.27.27.1 # router-001 + - 172.27.27.3 # hervil + - 172.27.27.4 # dwellers + - 172.27.27.5 # docker-002 + - 172.27.27.7 # complector + - 172.27.27.8 # db-A-001 + - 172.27.27.9 # db-B-001 + - 172.27.27.10 # web-001 + - 172.27.27.35 # windriver diff --git a/pillar/top.sls b/pillar/top.sls index da52fc4..aebf3e4 100644 --- a/pillar/top.sls +++ b/pillar/top.sls @@ -1,73 +1,74 @@ # ------------------------------------------------------------- # Salt configuration for Nasqueron servers # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Project: Nasqueron # Created: 2016-04-10 # License: Trivial work, not eligible to copyright # ------------------------------------------------------------- base: '*': - core.users - core.groups - core.network - nodes.nodes - nodes.forests - hotfixes.roles - services.monitoring-reporting - services.table - webserver.sites - credentials.vault cloudhugger: - opensearch.software - opensearch.clusters complector: - credentials.vault # To provision services - saas.rabbitmq docker-002: - notifications.config - paas.docker - saas.jenkins - saas.phpbb db-A-001: - dbserver.cluster-A db-B-001: - dbserver.cluster-B dwellers: - paas.docker - saas.airflow - saas.jenkins eglide: - shellserver.quassel hervil: - mailserver.vimbadmin ysul: - devserver.repos - saas.mediawiki - viperserv.bots - viperserv.fantoir - webserver.labs - webserver.wwwroot51 web-001: - saas.mediawiki - saas.wordpress windriver: - devserver.datacubes - devserver.ports - devserver.repos + - observability.prometheus - webserver.labs - webserver.wwwroot51 diff --git a/roles/prometheus/init.sls b/roles/prometheus/init.sls new file mode 100644 index 0000000..d5dc6c2 --- /dev/null +++ b/roles/prometheus/init.sls @@ -0,0 +1,10 @@ +# ------------------------------------------------------------- +# Salt — Provision Prometheus +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Project: Nasqueron +# License: Trivial work, not eligible to copyright +# ------------------------------------------------------------- + +include: + - .prometheus + - .monitoring diff --git a/roles/prometheus/monitoring/files/check-prometheus.sh b/roles/prometheus/monitoring/files/check-prometheus.sh new file mode 100755 index 0000000..1059aa0 --- /dev/null +++ b/roles/prometheus/monitoring/files/check-prometheus.sh @@ -0,0 +1,33 @@ +#!/bin/sh + +# ------------------------------------------------------------- +# Monitoring :: NRPE check :: Prometheus +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Project: Nasqueron +# License: Trivial work, not eligible to copyright +# Source file: roles/prometheus/monitoring/files/check-prometheus.sh +# ------------------------------------------------------------- +# +# <auto-generated> +# This file is managed by our rOPS SaltStack repository. +# +# Changes to this file may cause incorrect behavior +# and will be lost if the state is redeployed. +# </auto-generated> + +set -e + +EXIT_UNKNOWN=3 + +CHECK_COMMAND="{{ dirs.bin }}/promtool" +CONFIG_FILE="{{ dirs.etc }}/prometheus.yml" + +if ! command -v "$CHECK_COMMAND" >/dev/null 2>&1; then + echo "promtool isn't available, can't run check" >&2 + exit $EXIT_UNKNOWN +fi + +# As far as tested, promtool exits with 0 or 1. +# Parsing and success messages are sent to stdout. +# Parsing and validation errors are sent to stderr. +"$CHECK_COMMAND" check config "$CONFIG_FILE" > /dev/null diff --git a/roles/prometheus/monitoring/init.sls b/roles/prometheus/monitoring/init.sls new file mode 100644 index 0000000..a8b1d46 --- /dev/null +++ b/roles/prometheus/monitoring/init.sls @@ -0,0 +1,17 @@ +# ------------------------------------------------------------- +# Salt :: Monitoring :: Prometheus +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Project: Nasqueron +# License: Trivial work, not eligible to copyright +# ------------------------------------------------------------- + +{% from "map.jinja" import dirs with context %} + +{{ dirs.share }}/monitoring/checks/nrpe/check-prometheus: + file.managed: + - source: salt://roles/prometheus/monitoring/files/check-prometheus.sh + - mode: 755 + - template: jinja + - makedirs: True + - context: + dirs: {{ dirs }} diff --git a/roles/prometheus/prometheus/config.sls b/roles/prometheus/prometheus/config.sls new file mode 100644 index 0000000..6103ecc --- /dev/null +++ b/roles/prometheus/prometheus/config.sls @@ -0,0 +1,46 @@ +# ------------------------------------------------------------- +# Salt — Provision Prometheus +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Project: Nasqueron +# License: Trivial work, not eligible to copyright +# ------------------------------------------------------------- + +{% from "map.jinja" import dirs with context %} + +# ------------------------------------------------------------- +# Prometheus configuration +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +{{ dirs.etc }}/prometheus.yml: + file.managed: + - source: salt://roles/prometheus/prometheus/files/prometheus.yml + - template: jinja + +# ------------------------------------------------------------- +# Syslog configuration +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +{% if grains["os"] == "FreeBSD" %} + +{{ dirs.etc }}/newsyslog.conf.d/prometheus.conf: + file.managed: + - source: salt://roles/prometheus/prometheus/files/syslog/newsyslog.conf + - makedirs: True + +{{ dirs.etc }}/syslog.d/prometheus.conf: + file.managed: + - source: salt://roles/prometheus/prometheus/files/syslog/prometheus.conf + - makedirs: True + +prometheus_newsyslog_run: + cmd.run: + - name: newsyslog -C + - creates: /var/log/prometheus.log + +prometheus_syslog_reload: + cmd.run: + - name: /etc/rc.d/syslogd reload + - onchanges: + - file: {{ dirs.etc }}/syslog.d/prometheus.conf + +{% endif %} diff --git a/roles/prometheus/prometheus/files/prometheus.yml b/roles/prometheus/prometheus/files/prometheus.yml new file mode 100644 index 0000000..be82509 --- /dev/null +++ b/roles/prometheus/prometheus/files/prometheus.yml @@ -0,0 +1,49 @@ +# ------------------------------------------------------------- +# Prometheus configuration +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Project: Nasqueron +# License: Trivial work, not eligible to copyright +# Source file: roles/prometheus/prometheus/files/prometheus.yml +# ------------------------------------------------------------- +# +# <auto-generated> +# This file is managed by our rOPS SaltStack repository. +# +# Changes to this file may cause incorrect behavior +# and will be lost if the state is redeployed. +# </auto-generated> + +# ------------------------------------------------------------- +# Global configuration +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +global: + scrape_interval: 15s + evaluation_interval: 15s + scrape_timeout: 10s + +# ------------------------------------------------------------- +# Alertmanager +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +alerting: + alertmanagers: + - static_configs: + - targets: + # - alertmanager:9093 + +# ------------------------------------------------------------- +# Rules +# +# Load rules once and periodically evaluate them. +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +rule_files: [] + +# ------------------------------------------------------------- +# Scrape +# +# Auto-generated from pillar/observability/prometheus.sls +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +scrape_configs: {{ salt["prometheus.get_scrape_configs"]() }} diff --git a/roles/prometheus/prometheus/files/rc/prometheus b/roles/prometheus/prometheus/files/rc/prometheus new file mode 100755 index 0000000..183e50c --- /dev/null +++ b/roles/prometheus/prometheus/files/rc/prometheus @@ -0,0 +1,177 @@ +#!/bin/sh + +# PROVIDE: prometheus +# REQUIRE: LOGIN +# KEYWORD: shutdown + +# ------------------------------------------------------------- +# Prometheus service +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Project: Nasqueron +# License: Trivial work, not eligible to copyright +# Source file: roles/prometheus/prometheus/files/rc/prometheus +# Description: Custom servie allowing to set address and port +# ------------------------------------------------------------- +# +# <auto-generated> +# This file is managed by our rOPS SaltStack repository. +# +# Changes to this file may cause incorrect behavior +# and will be lost if the state is redeployed. +# </auto-generated> + +# +# Add the following lines to /etc/rc.conf.local or /etc/rc.conf +# to enable this service: +# +# prometheus_enable (bool) +# Set it to YES to enable prometheus +# Set to NO by default +# prometheus_user (string) +# Set user that prometheus will run under +# Default is "prometheus" +# prometheus_group (string) +# Set group that own prometheus files +# Default is "prometheus" +# prometheus_config (string) +# Set full path to config file +# Default is "/usr/local/etc/prometheus.yml" +# prometheus_pidfile (string) +# Set full path to pid file +# Default is "/var/run/prometheus.pid" +# prometheus_syslog_output_enable (bool) +# Set it to NO to disable syslog output +# Set to YES by default +# prometheus_syslog_output_tag (str) +# Set syslog tag if syslog enabled +# Default is "prometheus" +# prometheus_syslog_output_priority (string) +# Set syslog priority if syslog enabled +# Default is "info" +# prometheus_syslog_output_facility (string) +# Set syslog facility if syslog enabled +# Default is "daemon" +# prometheus_agent_mode (bool) +# Set to "YES" to enable Prometheus Agent Mode +# Default is "NO" +# prometheus_address (string) +# Set address to listen +# Default is "127.0.0.1" +# prometheus_port (string) +# Set port to listen +# Default is "9090" +# prometheus_consoles (string) +# Set dir that contains Prometheus consoles +# Default is "/usr/local/share/prometheus/consoles" +# prometheus_console_libraries (string) +# Set dir containing Prometheus console libraries +# Default is "/usr/local/share/prometheus/console_libraries" +# prometheus_data_dir (string) +# Set dir to run prometheus in +# Default is "/var/db/prometheus" +# prometheus_loglevel (string) +# Set one of [debug, info, warn, error] +# Default is "info" +# prometheus_logformat (string) +# Set one of [logfmt, json] +# Default is "logfmt" +# prometheus_env (string) +# Set environment variables used with prometheus +# Default is "" +# prometheus_args (string) +# Set additional command line arguments +# Default is "" + +. /etc/rc.subr + +name=prometheus +rcvar=prometheus_enable + +load_rc_config $name + +: ${prometheus_enable:="NO"} +: ${prometheus_user:="prometheus"} +: ${prometheus_group:="prometheus"} +: ${prometheus_config:="/usr/local/etc/prometheus.yml"} +: ${prometheus_pidfile:="/var/run/prometheus.pid"} +: ${prometheus_syslog_output_enable:="YES"} +: ${prometheus_agent_mode:="NO"} +: ${prometheus_address:="127.0.0.1"} +: ${prometheus_port:="9090"} +: ${prometheus_consoles_dir:="/usr/local/share/prometheus/consoles"} +: ${prometheus_console_libraries_dir:="/usr/local/share/prometheus/console_libraries"} +: ${prometheus_data_dir:="/var/db/prometheus"} +: ${prometheus_loglevel:="info"} +: ${prometheus_logformat:="logfmt"} + +if checkyesno prometheus_syslog_output_enable; then + if [ -n "${prometheus_syslog_output_tag}" ]; then + prometheus_syslog_output_flags="-T ${prometheus_syslog_output_tag}" + else + prometheus_syslog_output_flags="-T ${name}" + fi + if [ -n "${prometheus_syslog_output_priority}" ]; then + prometheus_syslog_output_flags="${prometheus_syslog_output_flags} -s ${prometheus_syslog_output_priority}" + fi + if [ -n "${prometheus_syslog_output_facility}" ]; then + prometheus_syslog_output_flags="${prometheus_syslog_output_flags} -l ${prometheus_syslog_output_facility}" + fi +fi + +if checkyesno prometheus_agent_mode; then + prometheus_storage_flags="--enable-feature=agent --storage.agent.path=${prometheus_data_dir}" +else + prometheus_storage_flags="--storage.tsdb.path=${prometheus_data_dir}" +fi + +pidfile="${prometheus_pidfile}" +required_files="${prometheus_config}" + +procname="/usr/local/bin/prometheus" +command="/usr/sbin/daemon" +command_args="-f ${prometheus_syslog_output_flags} -p ${pidfile} -t ${name} \ + /usr/bin/env ${prometheus_env} ${procname} \ + --config.file=${prometheus_config} \ + --web.listen-address=${prometheus_address}:${prometheus_port} \ + --web.console.templates=${prometheus_consoles_dir} \ + --web.console.libraries=${prometheus_console_libraries_dir} \ + --log.level=${prometheus_loglevel} \ + --log.format=${prometheus_logformat} \ + ${prometheus_storage_flags} \ + ${prometheus_args}" + +start_precmd="prometheus_start_precmd" +extra_commands="reload" + +# This checks for the existence of a prometheus 1.x data at the +# $prometheus_data_dir location. If one is found, Prometheus will not start. +prometheus_check_data_version() +{ + local _version + local _version_file="${prometheus_data_dir}/VERSION" + + if [ -f "${_version_file}" ]; then + read _version < "${_version_file}" + + if [ "${_version}" = "1" ]; then + return 1 + fi + fi +} + +prometheus_start_precmd() +{ + if [ ! -e "${pidfile}" ]; then + install -m 0600 -o "${prometheus_user}" -g "${prometheus_group}" /dev/null "${pidfile}" + fi + if [ ! -d "${prometheus_data_dir}" ]; then + install -d -m 750 -o "${prometheus_user}" -g "${prometheus_group}" "${prometheus_data_dir}" + else + # Ensure it's not a prometheus 1.x data + if [ ! prometheus_check_data_version ]; then + err 1 "Found \"net-mgmt/prometheus1\" data, refusing to start." + fi + fi +} + +run_rc_command "$1" diff --git a/roles/prometheus/prometheus/files/rc/prometheus.conf b/roles/prometheus/prometheus/files/rc/prometheus.conf new file mode 100644 index 0000000..9f08f1f --- /dev/null +++ b/roles/prometheus/prometheus/files/rc/prometheus.conf @@ -0,0 +1,18 @@ +# ------------------------------------------------------------- +# prometheus — rc configuration +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Project: Nasqueron +# License: Trivial work, not eligible to copyright +# Source file: roles/prometheus/prometheus/files/prometheus.rc +# ------------------------------------------------------------- +# +# <auto-generated> +# This file is managed by our rOPS SaltStack repository. +# +# Changes to this file may cause incorrect behavior +# and will be lost if the state is redeployed. +# </auto-generated> + +prometheus_enable="YES" +prometheus_address="{{ ip }}" +prometheus_loglevel="notice" diff --git a/roles/prometheus/prometheus/files/syslog/newsyslog.conf b/roles/prometheus/prometheus/files/syslog/newsyslog.conf new file mode 100644 index 0000000..e37c321 --- /dev/null +++ b/roles/prometheus/prometheus/files/syslog/newsyslog.conf @@ -0,0 +1,16 @@ +# ------------------------------------------------------------- +# Prometheus :: newsyslog configuration +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Project: Nasqueron +# License: Trivial work, not eligible to copyright +# Source file: roles/prometheus/prometheus/files/syslog/newsyslog.conf +# ------------------------------------------------------------- +# +# <auto-generated> +# This file is managed by our rOPS SaltStack repository. +# +# Changes to this file may cause incorrect behavior +# and will be lost if the state is redeployed. +# </auto-generated> + +/var/log/prometheus.log 644 5 1000 * JC diff --git a/roles/prometheus/prometheus/files/syslog/prometheus.conf b/roles/prometheus/prometheus/files/syslog/prometheus.conf new file mode 100644 index 0000000..8a0d6f7 --- /dev/null +++ b/roles/prometheus/prometheus/files/syslog/prometheus.conf @@ -0,0 +1,17 @@ +# ------------------------------------------------------------- +# Prometheus :: syslog configuration +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Project: Nasqueron +# License: Trivial work, not eligible to copyright +# Source file: roles/prometheus/prometheus/files/syslog/prometheus.conf +# ------------------------------------------------------------- +# +# <auto-generated> +# This file is managed by our rOPS SaltStack repository. +# +# Changes to this file may cause incorrect behavior +# and will be lost if the state is redeployed. +# </auto-generated> + +!prometheus,node_exporter +*.info /var/log/prometheus.log diff --git a/roles/prometheus/prometheus/init.sls b/roles/prometheus/prometheus/init.sls new file mode 100644 index 0000000..15789d9 --- /dev/null +++ b/roles/prometheus/prometheus/init.sls @@ -0,0 +1,11 @@ +# ------------------------------------------------------------- +# Salt — Provision Prometheus +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Project: Nasqueron +# License: Trivial work, not eligible to copyright +# ------------------------------------------------------------- + +include: + - .software + - .config + - .service diff --git a/roles/prometheus/prometheus/service.sls b/roles/prometheus/prometheus/service.sls new file mode 100644 index 0000000..85ea2f3 --- /dev/null +++ b/roles/prometheus/prometheus/service.sls @@ -0,0 +1,31 @@ +# ------------------------------------------------------------- +# Salt — Provision Prometheus +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Project: Nasqueron +# License: Trivial work, not eligible to copyright +# ------------------------------------------------------------- + +# ------------------------------------------------------------- +# Prometheus service +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +{% if grains['os'] == 'FreeBSD' %} + +/usr/local/etc/rc.d/prometheus: + file.managed: + - source: salt://roles/prometheus/prometheus/files/rc/prometheus + - mode: 755 + +/etc/rc.conf.d/prometheus: + file.managed: + - source: salt://roles/prometheus/prometheus/files/rc/prometheus.conf + - template: jinja + - context: + ip: {{ pillar["nasqueron_services"]["prometheus"] }} + +{% endif %} + +prometheus_running: + service.running: + - name: prometheus + diff --git a/roles/prometheus/prometheus/software.sls b/roles/prometheus/prometheus/software.sls new file mode 100644 index 0000000..0e914a5 --- /dev/null +++ b/roles/prometheus/prometheus/software.sls @@ -0,0 +1,11 @@ +# ------------------------------------------------------------- +# Salt — Provision Prometheus +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Project: Nasqueron +# License: Trivial work, not eligible to copyright +# ------------------------------------------------------------- + +prometheus_software: + pkg.installed: + - pkgs: + - prometheus diff --git a/top.sls b/top.sls index 0cb112b..1ace58e 100644 --- a/top.sls +++ b/top.sls @@ -1,57 +1,58 @@ # ------------------------------------------------------------- # Salt configuration for Nasqueron servers # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Project: Nasqueron # Created: 2016-04-10 # License: Trivial work, not eligible to copyright # ------------------------------------------------------------- base: '*': - roles/core - roles/webserver-content 'local': - roles/salt-primary 'ysul': - roles/builder - roles/dbserver-mysql - roles/devserver - roles/viperserv - roles/webserver-core - roles/webserver-legacy - roles/webserver-varnish 'windriver': - roles/builder - roles/dbserver-mysql - roles/dbserver-pgsql - roles/devserver - roles/grafana + - roles/prometheus - roles/redis - roles/saas-nextcloud - roles/webserver-alkane - roles/webserver-core - roles/webserver-legacy 'cloudhugger': - roles/opensearch 'db-A-001': - roles/dbserver-pgsql 'db-B-001': - roles/dbserver-mysql 'docker-002': - roles/paas-docker 'dwellers': - roles/paas-docker/docker - roles/paas-lxc/lxc - roles/saas-airflow 'eglide': - roles/webserver-core - roles/shellserver 'hervil': - roles/mailserver - roles/webserver-core - roles/webserver-alkane 'web-001': - roles/webserver-core - roles/webserver-alkane - roles/saas-mediawiki - roles/saas-wordpress