Skip to content

Commit

Permalink
netdata: allow customizing netdata.conf, allow custom host domain
Browse files Browse the repository at this point in the history
- use netdata.conf.j2 to template the netdata.conf file
- allow custom files to be templated
- mount netdata.conf file into docker container
- mount dbengine volume in container to allow history retention
  when rebuiliding container
- allow custom volumes to be mounted in the container
- add `ansible_nas_domain_root` variable used as netdata hostname
  when you have multiple nas servers this allows you to properly name
  the server in netdata.
  example:
  - `ansible_nas_hostname`: nas
  - `ansible_nas_domain`: nas.domain.tld
  - `ansible_nas_domain_root`: domain.tld

  original netdata hostname: nas.nas.domain.tld
  new netdata hostname: nas.domain.tld
  • Loading branch information
khartahk committed Nov 11, 2021
1 parent 1aa6c34 commit 0267119
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 5 deletions.
1 change: 1 addition & 0 deletions group_vars/all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ ansible_nas_email: [email protected]

# Applications will have subdomain SSL certificates created if Traefik is enabled, e.g. ansible-nas.<your-domain>, nextcloud.<your-domain>
ansible_nas_domain: example.com
ansible_nas_domain_root: "{{ ansible_nas_domain }}"

###
### Samba
Expand Down
25 changes: 25 additions & 0 deletions roles/netdata/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,34 @@
netdata_enabled: false
netdata_available_externally: "false"

# directories
netdata_data_directory: "{{ docker_home }}/netdata"

netdata_directories:
- "{{ netdata_data_directory }}"
netdata_directories_custom: []

netdata_template_files:
- src: netdata.conf.j2
dest: "{{ netdata_data_directory }}/etc/netdata.conf"
netdata_template_files_custom: []

# network
netdata_hostname: "netdata"
netdata_port: "19999"

# specs
netdata_memory: 1g
netdata_volumes:
- "/proc:/host/proc:ro"
- "/sys:/host/sys:ro"
- "/var/run/docker.sock:/var/run/docker.sock:ro"
- "{{ netdata_data_directory }}/etc/netdata.conf:/etc/netdata/netdata.conf:ro"
- "{{ netdata_data_directory }}/dbengine:/var/cache/netdata/dbengine:rw"
netdata_volumes_custom: []

# config - https://learn.netdata.cloud/docs/configure/common-changes
netdata_config:
global:
- "page cache size = 32" # MiB of RAM used to store metrics
- "dbengine multihost disk space = 128" # MiB of disk to store history
45 changes: 40 additions & 5 deletions roles/netdata/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,53 @@
name: docker
register: docker_group

- name: Create netdata group
group:
name: netdata
gid: "201"
state: present
register: netdata_group

- name: Create netdata user
user:
name: netdata
state: present
system: yes
create_home: no
group: netdata
uid: "201"
shell: /usr/sbin/nologin
register: netdata_user

- name: Create Directories
file:
path: "{{ item }}"
state: directory
mode: "0750"
owner: "netdata"
group: "netdata"
with_items: "{{ netdata_directories + netdata_directories_custom | sort }}"
when: netdata_user.state == "present" and netdata_group.state == "present"

- name: Template Files
register: template_config
template:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
force: "{{ item.force | default(false) }}"
mode: "{{ item.mode | default('0600') }}"
with_items: "{{ netdata_template_files + netdata_template_files_custom | sort }}"

- name: Netdata Docker Container
docker_container:
name: netdata
hostname: "{{ ansible_nas_hostname }}.{{ ansible_nas_domain }}"
hostname: "{{ ansible_nas_hostname }}.{{ ansible_nas_domain_root }}"
image: netdata/netdata
state: started
pull: true
ports:
- "{{ netdata_port }}:19999"
volumes:
- "/proc:/host/proc:ro"
- "/sys:/host/sys:ro"
- "/var/run/docker.sock:/var/run/docker.sock:ro"
volumes: "{{ netdata_volumes + netdata_volumes_custom | sort }}"
env:
PGID: "{{ docker_group.gid }}"
capabilities:
Expand All @@ -25,6 +59,7 @@
- apparmor:unconfined
restart_policy: unless-stopped
memory: "{{ netdata_memory }}"
recreate: "{{ template_config is changed }}"
labels:
traefik.enable: "{{ netdata_available_externally }}"
traefik.http.routers.netdata.rule: "Host(`{{ netdata_hostname }}.{{ ansible_nas_domain }}`)"
Expand Down
4 changes: 4 additions & 0 deletions roles/netdata/templates/netdata.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{% for key in netdata_config %}
[{{ key }}]
{# { netdata_config[[key][0]]|join("\n") } #}
{% endfor %}

0 comments on commit 0267119

Please sign in to comment.