From 4e92a9865c07539ffcd8434a88d9a67653a5268c Mon Sep 17 00:00:00 2001 From: Thomas Boerger Date: Thu, 24 Aug 2023 11:32:38 +0200 Subject: [PATCH] feat: add optional defaults for cpu and memory limit --- README.md | 172 +++++++++++++++++++++++++++++++++++- defaults/main.yml | 40 +++++++++ templates/oauth2/service.j2 | 15 ++++ templates/service.j2 | 15 ++++ 4 files changed, 241 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f389f0c..ee08077 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Source Code](https://img.shields.io/badge/github-source%20code-blue?logo=github&logoColor=white)](https://github.com/rolehippie/prometheus) [![General Workflow](https://github.com/rolehippie/prometheus/actions/workflows/general.yml/badge.svg)](https://github.com/rolehippie/prometheus/actions/workflows/general.yml) -[![Readme Workflow](https://github.com/rolehippie/prometheus/actions/workflows/readme.yml/badge.svg)](https://github.com/rolehippie/prometheus/actions/workflows/readme.yml) +[![Readme Workflow](https://github.com/rolehippie/prometheus/actions/workflows/docs.yml/badge.svg)](https://github.com/rolehippie/prometheus/actions/workflows/docs.yml) [![Galaxy Workflow](https://github.com/rolehippie/prometheus/actions/workflows/galaxy.yml/badge.svg)](https://github.com/rolehippie/prometheus/actions/workflows/galaxy.yml) [![License: Apache-2.0](https://img.shields.io/github/license/rolehippie/prometheus)](https://github.com/rolehippie/prometheus/blob/master/LICENSE) [![Ansible Role](https://img.shields.io/badge/role-rolehippie.prometheus-blue)](https://galaxy.ansible.com/rolehippie/prometheus) @@ -18,6 +18,7 @@ Building and improving this Ansible role have been sponsored by my current and p - [Requirements](#requirements) - [Default Variables](#default-variables) - [prometheus_alertmanagers](#prometheus_alertmanagers) + - [prometheus_cpu_shares](#prometheus_cpu_shares) - [prometheus_default_folders](#prometheus_default_folders) - [prometheus_default_labels](#prometheus_default_labels) - [prometheus_default_publish](#prometheus_default_publish) @@ -35,12 +36,17 @@ Building and improving this Ansible role have been sponsored by my current and p - [prometheus_image](#prometheus_image) - [prometheus_installation](#prometheus_installation) - [prometheus_listen_address](#prometheus_listen_address) + - [prometheus_memory_limit](#prometheus_memory_limit) + - [prometheus_memory_soft_limit](#prometheus_memory_soft_limit) + - [prometheus_memory_swap](#prometheus_memory_swap) - [prometheus_network](#prometheus_network) + - [prometheus_number_of_cpus](#prometheus_number_of_cpus) - [prometheus_oauth2_access_logging](#prometheus_oauth2_access_logging) - [prometheus_oauth2_allowed_groups](#prometheus_oauth2_allowed_groups) - [prometheus_oauth2_client_id](#prometheus_oauth2_client_id) - [prometheus_oauth2_client_secret](#prometheus_oauth2_client_secret) - [prometheus_oauth2_cookie_secret](#prometheus_oauth2_cookie_secret) + - [prometheus_oauth2_cpu_shares](#prometheus_oauth2_cpu_shares) - [prometheus_oauth2_default_labels](#prometheus_oauth2_default_labels) - [prometheus_oauth2_default_publish](#prometheus_oauth2_default_publish) - [prometheus_oauth2_download](#prometheus_oauth2_download) @@ -50,7 +56,11 @@ Building and improving this Ansible role have been sponsored by my current and p - [prometheus_oauth2_image](#prometheus_oauth2_image) - [prometheus_oauth2_keycloak_url](#prometheus_oauth2_keycloak_url) - [prometheus_oauth2_listen_address](#prometheus_oauth2_listen_address) + - [prometheus_oauth2_memory_limit](#prometheus_oauth2_memory_limit) + - [prometheus_oauth2_memory_soft_limit](#prometheus_oauth2_memory_soft_limit) + - [prometheus_oauth2_memory_swap](#prometheus_oauth2_memory_swap) - [prometheus_oauth2_network](#prometheus_oauth2_network) + - [prometheus_oauth2_number_of_cpus](#prometheus_oauth2_number_of_cpus) - [prometheus_oauth2_provider](#prometheus_oauth2_provider) - [prometheus_oauth2_pull_image](#prometheus_oauth2_pull_image) - [prometheus_oauth2_request_logging](#prometheus_oauth2_request_logging) @@ -99,6 +109,22 @@ prometheus_alertmanagers: - loclhost:9093 ``` +### prometheus_cpu_shares + +CPU shares with Docker deployment + +#### Default value + +```YAML +prometheus_cpu_shares: +``` + +#### Example usage + +```YAML +prometheus_cpu_shares: '512' +``` + ### prometheus_default_folders List of default folders to create @@ -353,6 +379,54 @@ Listen address for the prometheus prometheus_listen_address: 0.0.0.0:9090 ``` +### prometheus_memory_limit + +Memory limit with Docker deployment + +#### Default value + +```YAML +prometheus_memory_limit: +``` + +#### Example usage + +```YAML +prometheus_memory_limit: 1024m +``` + +### prometheus_memory_soft_limit + +Soft memory limit with Docker deployment + +#### Default value + +```YAML +prometheus_memory_soft_limit: +``` + +#### Example usage + +```YAML +prometheus_memory_soft_limit: 512m +``` + +### prometheus_memory_swap + +Swap usage with Docker deployment + +#### Default value + +```YAML +prometheus_memory_swap: +``` + +#### Example usage + +```YAML +prometheus_memory_swap: 2048m +``` + ### prometheus_network Optional docker network to attach on OAuth2 Proxy @@ -363,6 +437,22 @@ Optional docker network to attach on OAuth2 Proxy prometheus_network: ``` +### prometheus_number_of_cpus + +Number of CPUs with Docker deployment + +#### Default value + +```YAML +prometheus_number_of_cpus: +``` + +#### Example usage + +```YAML +prometheus_number_of_cpus: '1.0' +``` + ### prometheus_oauth2_access_logging Enable access logging for OAuth2 proxy @@ -422,6 +512,22 @@ Cookie secret used by OAuth2 proxy prometheus_oauth2_cookie_secret: ``` +### prometheus_oauth2_cpu_shares + +CPU shares with Docker deployment + +#### Default value + +```YAML +prometheus_oauth2_cpu_shares: +``` + +#### Example usage + +```YAML +prometheus_oauth2_cpu_shares: '512' +``` + ### prometheus_oauth2_default_labels List of default labels to assign to docker on OAuth2 Proxy @@ -524,6 +630,54 @@ Listem address for the OAuth2 proxy prometheus_oauth2_listen_address: 0.0.0.0:9089 ``` +### prometheus_oauth2_memory_limit + +Memory limit with Docker deployment + +#### Default value + +```YAML +prometheus_oauth2_memory_limit: +``` + +#### Example usage + +```YAML +prometheus_oauth2_memory_limit: 1024m +``` + +### prometheus_oauth2_memory_soft_limit + +Soft memory limit with Docker deployment + +#### Default value + +```YAML +prometheus_oauth2_memory_soft_limit: +``` + +#### Example usage + +```YAML +prometheus_oauth2_memory_soft_limit: 512m +``` + +### prometheus_oauth2_memory_swap + +Swap usage with Docker deployment + +#### Default value + +```YAML +prometheus_oauth2_memory_swap: +``` + +#### Example usage + +```YAML +prometheus_oauth2_memory_swap: 2048m +``` + ### prometheus_oauth2_network #### Default value @@ -532,6 +686,22 @@ prometheus_oauth2_listen_address: 0.0.0.0:9089 prometheus_oauth2_network: '{{ prometheus_network }}' ``` +### prometheus_oauth2_number_of_cpus + +Number of CPUs with Docker deployment + +#### Default value + +```YAML +prometheus_oauth2_number_of_cpus: +``` + +#### Example usage + +```YAML +prometheus_oauth2_number_of_cpus: '1.5' +``` + ### prometheus_oauth2_provider Provider for OAuth2 authentication diff --git a/defaults/main.yml b/defaults/main.yml index f82a682..a7b3cf7 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -68,6 +68,26 @@ prometheus_default_volumes: # @end prometheus_extra_volumes: [] +# @var prometheus_memory_limit:description: Memory limit with Docker deployment +# @var prometheus_memory_limit:example: $ "1024m" +prometheus_memory_limit: + +# @var prometheus_memory_swap:description: Swap usage with Docker deployment +# @var prometheus_memory_swap:example: $ "2048m" +prometheus_memory_swap: + +# @var prometheus_memory_soft_limit:description: Soft memory limit with Docker deployment +# @var prometheus_memory_soft_limit:example: $ "512m" +prometheus_memory_soft_limit: + +# @var prometheus_cpu_shares:description: CPU shares with Docker deployment +# @var prometheus_cpu_shares:example: $ "512" +prometheus_cpu_shares: + +# @var prometheus_number_of_cpus:description: Number of CPUs with Docker deployment +# @var prometheus_number_of_cpus:example: $ "1.0" +prometheus_number_of_cpus: + # @var prometheus_domain:description: Domain for external access # @var prometheus_domain:example: $ "https://prometheus.example.com" prometheus_domain: @@ -195,6 +215,26 @@ prometheus_oauth2_default_labels: [] # @var prometheus_oauth2_extra_labels:description: List of extra labels to assign to docker on OAuth2 Proxy prometheus_oauth2_extra_labels: [] +# @var prometheus_oauth2_memory_limit:description: Memory limit with Docker deployment +# @var prometheus_oauth2_memory_limit:example: $ "1024m" +prometheus_oauth2_memory_limit: + +# @var prometheus_oauth2_memory_swap:description: Swap usage with Docker deployment +# @var prometheus_oauth2_memory_swap:example: $ "2048m" +prometheus_oauth2_memory_swap: + +# @var prometheus_oauth2_memory_soft_limit:description: Soft memory limit with Docker deployment +# @var prometheus_oauth2_memory_soft_limit:example: $ "512m" +prometheus_oauth2_memory_soft_limit: + +# @var prometheus_oauth2_cpu_shares:description: CPU shares with Docker deployment +# @var prometheus_oauth2_cpu_shares:example: $ "512" +prometheus_oauth2_cpu_shares: + +# @var prometheus_oauth2_number_of_cpus:description: Number of CPUs with Docker deployment +# @var prometheus_oauth2_number_of_cpus:example: $ "1.5" +prometheus_oauth2_number_of_cpus: + # @var prometheus_oauth2_upstream:description: Upstream target for the OAuth2 proxy prometheus_oauth2_upstream: "http://{{ prometheus_listen_address if prometheus_installation == 'native' else 'prometheus:9090' }}" diff --git a/templates/oauth2/service.j2 b/templates/oauth2/service.j2 index b1fe8f6..f31b342 100644 --- a/templates/oauth2/service.j2 +++ b/templates/oauth2/service.j2 @@ -22,6 +22,21 @@ ExecStart=/usr/bin/docker run --rm \ --name %p \ --hostname %p \ --env-file /etc/default/prometheus-oauth2 \ +{% if prometheus_oauth2_memory_limit | default(False) %} + --memory {{ prometheus_oauth2_memory_limit }} \ +{% endif %} +{% if prometheus_oauth2_memory_swap | default(False) %} + --memory-swap {{ prometheus_oauth2_memory_swap }} \ +{% endif %} +{% if prometheus_oauth2_memory_soft_limit | default(False) %} + --memory-reservation {{ prometheus_oauth2_memory_soft_limit }} \ +{% endif %} +{% if prometheus_oauth2_cpu_shares | default(False) %} + --cpu-shares {{ prometheus_oauth2_cpu_shares }} \ +{% endif %} +{% if prometheus_oauth2_number_of_cpus | default(False) %} + --cpus {{ prometheus_oauth2_number_of_cpus }} \ +{% endif %} {% for item in prometheus_oauth2_default_labels + prometheus_oauth2_extra_labels %} --label {{ item }} \ {% endfor %} diff --git a/templates/service.j2 b/templates/service.j2 index 603aad1..bd68e08 100644 --- a/templates/service.j2 +++ b/templates/service.j2 @@ -20,6 +20,21 @@ ExecStart=/usr/bin/docker run --rm \ --name %p \ --hostname %p \ --env-file /etc/default/prometheus \ +{% if prometheus_memory_limit | default(False) %} + --memory {{ prometheus_memory_limit }} \ +{% endif %} +{% if prometheus_memory_swap | default(False) %} + --memory-swap {{ prometheus_memory_swap }} \ +{% endif %} +{% if prometheus_memory_soft_limit | default(False) %} + --memory-reservation {{ prometheus_memory_soft_limit }} \ +{% endif %} +{% if prometheus_cpu_shares | default(False) %} + --cpu-shares {{ prometheus_cpu_shares }} \ +{% endif %} +{% if prometheus_number_of_cpus | default(False) %} + --cpus {{ prometheus_number_of_cpus }} \ +{% endif %} {% for item in prometheus_default_labels + prometheus_extra_labels %} --label {{ item }} \ {% endfor %}