Skip to content

Commit

Permalink
feat: add optional defaults for cpu and memory limit
Browse files Browse the repository at this point in the history
  • Loading branch information
tboerger committed Aug 24, 2023
1 parent ea0b8cd commit 4ee11f6
Show file tree
Hide file tree
Showing 4 changed files with 240 additions and 0 deletions.
170 changes: 170 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Building and improving this Ansible role have been sponsored by my current and p

- [Requirements](#requirements)
- [Default Variables](#default-variables)
- [alertmanager_cpu_shares](#alertmanager_cpu_shares)
- [alertmanager_data_retention](#alertmanager_data_retention)
- [alertmanager_default_folders](#alertmanager_default_folders)
- [alertmanager_default_labels](#alertmanager_default_labels)
Expand All @@ -35,12 +36,17 @@ Building and improving this Ansible role have been sponsored by my current and p
- [alertmanager_inhibit_rules](#alertmanager_inhibit_rules)
- [alertmanager_installation](#alertmanager_installation)
- [alertmanager_listen_address](#alertmanager_listen_address)
- [alertmanager_memory_limit](#alertmanager_memory_limit)
- [alertmanager_memory_soft_limit](#alertmanager_memory_soft_limit)
- [alertmanager_memory_swap](#alertmanager_memory_swap)
- [alertmanager_network](#alertmanager_network)
- [alertmanager_number_of_cpus](#alertmanager_number_of_cpus)
- [alertmanager_oauth2_access_logging](#alertmanager_oauth2_access_logging)
- [alertmanager_oauth2_allowed_groups](#alertmanager_oauth2_allowed_groups)
- [alertmanager_oauth2_client_id](#alertmanager_oauth2_client_id)
- [alertmanager_oauth2_client_secret](#alertmanager_oauth2_client_secret)
- [alertmanager_oauth2_cookie_secret](#alertmanager_oauth2_cookie_secret)
- [alertmanager_oauth2_cpu_shares](#alertmanager_oauth2_cpu_shares)
- [alertmanager_oauth2_default_labels](#alertmanager_oauth2_default_labels)
- [alertmanager_oauth2_default_publish](#alertmanager_oauth2_default_publish)
- [alertmanager_oauth2_download](#alertmanager_oauth2_download)
Expand All @@ -50,7 +56,11 @@ Building and improving this Ansible role have been sponsored by my current and p
- [alertmanager_oauth2_image](#alertmanager_oauth2_image)
- [alertmanager_oauth2_keycloak_url](#alertmanager_oauth2_keycloak_url)
- [alertmanager_oauth2_listen_address](#alertmanager_oauth2_listen_address)
- [alertmanager_oauth2_memory_limit](#alertmanager_oauth2_memory_limit)
- [alertmanager_oauth2_memory_soft_limit](#alertmanager_oauth2_memory_soft_limit)
- [alertmanager_oauth2_memory_swap](#alertmanager_oauth2_memory_swap)
- [alertmanager_oauth2_network](#alertmanager_oauth2_network)
- [alertmanager_oauth2_number_of_cpus](#alertmanager_oauth2_number_of_cpus)
- [alertmanager_oauth2_provider](#alertmanager_oauth2_provider)
- [alertmanager_oauth2_pull_image](#alertmanager_oauth2_pull_image)
- [alertmanager_oauth2_request_logging](#alertmanager_oauth2_request_logging)
Expand Down Expand Up @@ -83,6 +93,22 @@ Building and improving this Ansible role have been sponsored by my current and p

## Default Variables

### alertmanager_cpu_shares

CPU shares with Docker deployment

#### Default value

```YAML
alertmanager_cpu_shares:
```
#### Example usage
```YAML
alertmanager_cpu_shares: '512'
```
### alertmanager_data_retention
Data retention for alertmanager state
Expand Down Expand Up @@ -329,6 +355,54 @@ Listen address for the alertmanager
alertmanager_listen_address: 0.0.0.0:9093
```
### alertmanager_memory_limit
Memory limit with Docker deployment
#### Default value
```YAML
alertmanager_memory_limit:
```
#### Example usage
```YAML
alertmanager_memory_limit: 1024m
```
### alertmanager_memory_soft_limit
Soft memory limit with Docker deployment
#### Default value
```YAML
alertmanager_memory_soft_limit:
```
#### Example usage
```YAML
alertmanager_memory_soft_limit: 512m
```
### alertmanager_memory_swap
Swap usage with Docker deployment
#### Default value
```YAML
alertmanager_memory_swap:
```
#### Example usage
```YAML
alertmanager_memory_swap: 2048m
```
### alertmanager_network
Optional docker network to attach
Expand All @@ -339,6 +413,22 @@ Optional docker network to attach
alertmanager_network:
```
### alertmanager_number_of_cpus
Number of CPUs with Docker deployment
#### Default value
```YAML
alertmanager_number_of_cpus:
```
#### Example usage
```YAML
alertmanager_number_of_cpus: '1.0'
```
### alertmanager_oauth2_access_logging
Enable access logging for OAuth2 proxy
Expand Down Expand Up @@ -398,6 +488,22 @@ Cookie secret used by OAuth2 proxy
alertmanager_oauth2_cookie_secret:
```
### alertmanager_oauth2_cpu_shares
CPU shares with Docker deployment
#### Default value
```YAML
alertmanager_oauth2_cpu_shares:
```
#### Example usage
```YAML
alertmanager_oauth2_cpu_shares: '512'
```
### alertmanager_oauth2_default_labels
List of default labels to assign to docker on OAuth2 Proxy
Expand Down Expand Up @@ -502,6 +608,54 @@ Listem address for the OAuth2 proxy
alertmanager_oauth2_listen_address: 0.0.0.0:9092
```
### alertmanager_oauth2_memory_limit
Memory limit with Docker deployment
#### Default value
```YAML
alertmanager_oauth2_memory_limit:
```
#### Example usage
```YAML
alertmanager_oauth2_memory_limit: 1024m
```
### alertmanager_oauth2_memory_soft_limit
Soft memory limit with Docker deployment
#### Default value
```YAML
alertmanager_oauth2_memory_soft_limit:
```
#### Example usage
```YAML
alertmanager_oauth2_memory_soft_limit: 512m
```
### alertmanager_oauth2_memory_swap
Swap usage with Docker deployment
#### Default value
```YAML
alertmanager_oauth2_memory_swap:
```
#### Example usage
```YAML
alertmanager_oauth2_memory_swap: 2048m
```
### alertmanager_oauth2_network
Optional docker network to attach on OAuth2 Proxy
Expand All @@ -512,6 +666,22 @@ Optional docker network to attach on OAuth2 Proxy
alertmanager_oauth2_network: '{{ alertmanager_network }}'
```
### alertmanager_oauth2_number_of_cpus
Number of CPUs with Docker deployment
#### Default value
```YAML
alertmanager_oauth2_number_of_cpus:
```
#### Example usage
```YAML
alertmanager_oauth2_number_of_cpus: '1.0'
```
### alertmanager_oauth2_provider
Provider for OAuth2 authentication
Expand Down
40 changes: 40 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,26 @@ alertmanager_default_volumes:
# @end
alertmanager_extra_volumes: []

# @var alertmanager_memory_limit:description: Memory limit with Docker deployment
# @var alertmanager_memory_limit:example: $ "1024m"
alertmanager_memory_limit:

# @var alertmanager_memory_swap:description: Swap usage with Docker deployment
# @var alertmanager_memory_swap:example: $ "2048m"
alertmanager_memory_swap:

# @var alertmanager_memory_soft_limit:description: Soft memory limit with Docker deployment
# @var alertmanager_memory_soft_limit:example: $ "512m"
alertmanager_memory_soft_limit:

# @var alertmanager_cpu_shares:description: CPU shares with Docker deployment
# @var alertmanager_cpu_shares:example: $ "512"
alertmanager_cpu_shares:

# @var alertmanager_number_of_cpus:description: Number of CPUs with Docker deployment
# @var alertmanager_number_of_cpus:example: $ "1.0"
alertmanager_number_of_cpus:

# @var alertmanager_default_templates:description: List of default template file definition
alertmanager_default_templates: []

Expand Down Expand Up @@ -186,6 +206,26 @@ alertmanager_oauth2_default_labels: []
# @var alertmanager_oauth2_extra_labels:description: List of extra labels to assign to docker on OAuth2 Proxy
alertmanager_oauth2_extra_labels: []

# @var alertmanager_oauth2_memory_limit:description: Memory limit with Docker deployment
# @var alertmanager_oauth2_memory_limit:example: $ "1024m"
alertmanager_oauth2_memory_limit:

# @var alertmanager_oauth2_memory_swap:description: Swap usage with Docker deployment
# @var alertmanager_oauth2_memory_swap:example: $ "2048m"
alertmanager_oauth2_memory_swap:

# @var alertmanager_oauth2_memory_soft_limit:description: Soft memory limit with Docker deployment
# @var alertmanager_oauth2_memory_soft_limit:example: $ "512m"
alertmanager_oauth2_memory_soft_limit:

# @var alertmanager_oauth2_cpu_shares:description: CPU shares with Docker deployment
# @var alertmanager_oauth2_cpu_shares:example: $ "512"
alertmanager_oauth2_cpu_shares:

# @var alertmanager_oauth2_number_of_cpus:description: Number of CPUs with Docker deployment
# @var alertmanager_oauth2_number_of_cpus:example: $ "1.0"
alertmanager_oauth2_number_of_cpus:

# @var alertmanager_oauth2_upstream:description: Upstream target for the OAuth2 proxy
alertmanager_oauth2_upstream: "http://{{ alertmanager_listen_address if alertmanager_installation == 'native' else 'alertmanager:9093' }}"

Expand Down
15 changes: 15 additions & 0 deletions templates/oauth2/service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,21 @@ ExecStart=/usr/bin/docker run --rm \
--name %p \
--hostname %p \
--env-file /etc/default/alertmanager-oauth2 \
{% if alertmanager_oauth2_memory_limit | default(False) %}
--memory {{ alertmanager_oauth2_memory_limit }} \
{% endif %}
{% if alertmanager_oauth2_memory_swap | default(False) %}
--memory-swap {{ alertmanager_oauth2_memory_swap }} \
{% endif %}
{% if alertmanager_oauth2_memory_soft_limit | default(False) %}
--memory-reservation {{ alertmanager_oauth2_memory_soft_limit }} \
{% endif %}
{% if alertmanager_oauth2_cpu_shares | default(False) %}
--cpu-shares {{ alertmanager_oauth2_cpu_shares }} \
{% endif %}
{% if alertmanager_oauth2_number_of_cpus | default(False) %}
--cpus {{ alertmanager_oauth2_number_of_cpus }} \
{% endif %}
{% for item in alertmanager_oauth2_default_labels + alertmanager_oauth2_extra_labels %}
--label {{ item }} \
{% endfor %}
Expand Down
15 changes: 15 additions & 0 deletions templates/service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@ ExecStart=/usr/bin/docker run --rm \
--name %p \
--hostname %p \
--env-file /etc/default/alertmanager \
{% if alertmanager_memory_limit | default(False) %}
--memory {{ alertmanager_memory_limit }} \
{% endif %}
{% if alertmanager_memory_swap | default(False) %}
--memory-swap {{ alertmanager_memory_swap }} \
{% endif %}
{% if alertmanager_memory_soft_limit | default(False) %}
--memory-reservation {{ alertmanager_memory_soft_limit }} \
{% endif %}
{% if alertmanager_cpu_shares | default(False) %}
--cpu-shares {{ alertmanager_cpu_shares }} \
{% endif %}
{% if alertmanager_number_of_cpus | default(False) %}
--cpus {{ alertmanager_number_of_cpus }} \
{% endif %}
{% for item in alertmanager_default_labels + alertmanager_extra_labels %}
--label {{ item }} \
{% endfor %}
Expand Down

0 comments on commit 4ee11f6

Please sign in to comment.