prometheus: Use os packaged prometheus

This commit is contained in:
Timo Makinen 2023-11-04 20:36:10 +00:00
parent 7ee84bffd9
commit 929738af88
4 changed files with 30 additions and 74 deletions

View file

@ -1,23 +0,0 @@
[Unit]
Description=Prometheus
After=network-online.target
Requires=local-fs.target
After=local-fs.target
[Service]
Type=simple
Environment="GOMAXPROCS={{ ansible_processor_vcpus|default(ansible_processor_count) }}"
User=prometheus
Group=prometheus
UMask=007
ExecReload=/bin/kill -HUP $MAINPID
ExecStart=/usr/local/sbin/prometheus \
--config.file=/srv/prometheus/prometheus.yml \
--log.level=info \
--storage.tsdb.path=/srv/prometheus/data \
--storage.tsdb.retention.time=365d \
--web.console.libraries=/usr/local/share/prometheus/console_libraries
Restart=always
[Install]
WantedBy=multi-user.target

View file

@ -1,3 +1,4 @@
--- ---
dependencies: dependencies:
- {role: epel_repo}
- {role: nginx} - {role: nginx}

View file

@ -14,43 +14,18 @@
shell: /sbin/nologin shell: /sbin/nologin
uid: 305 uid: 305
- name: Extract package - name: Install packages
ansible.builtin.unarchive: ansible.builtin.package:
src: >- name: golang-github-prometheus
{{ state: installed
"https://github.com/prometheus/prometheus/releases/download/v" +
prometheus_version + "/prometheus-" + prometheus_version +
".linux-amd64.tar.gz"
}}
dest: /usr/local/src
owner: root
group: "{{ ansible_wheel }}"
remote_src: true
- name: Copy binaries - name: Create data directory
ansible.builtin.copy:
dest: "/usr/local/sbin/{{ item }}"
src: >-
/usr/local/src/prometheus-{{ prometheus_version }}.linux-amd64/{{ item }}
mode: "0755"
owner: root
group: "{{ ansible_wheel }}"
remote_src: true
notify: Restart prometheus
with_items:
- promtool
- prometheus
- name: Create data directories
ansible.builtin.file: ansible.builtin.file:
path: "{{ item }}" path: /export/prometheus
state: directory state: directory
mode: "0750" mode: "0770"
owner: root owner: root
group: prometheus group: prometheus
with_items:
- /export/prometheus
- /export/prometheus/node.d
- name: Link data directory - name: Link data directory
ansible.builtin.file: ansible.builtin.file:
@ -61,26 +36,38 @@
group: "{{ ansible_wheel }}" group: "{{ ansible_wheel }}"
follow: false follow: false
- name: Create database directory - name: Configure startup options
ansible.builtin.file: ansible.builtin.lineinfile:
path: /srv/prometheus/data path: /etc/default/prometheus
state: directory regexp: "^ARGS="
mode: "0770" line: >-
owner: root ARGS="--config.file=/etc/prometheus/prometheus.yml
group: prometheus --log.level=info
--storage.tsdb.path=/srv/prometheus
--storage.tsdb.retention.time=365d
--web.console.libraries=/usr/local/share/prometheus/console_libraries"
notify: Restart prometheus
- name: Create configuration - name: Create configuration
ansible.builtin.template: ansible.builtin.template:
dest: /srv/prometheus/prometheus.yml dest: /etc/prometheus/prometheus.yml
src: prometheus.yml.j2 src: prometheus.yml.j2
mode: "0640" mode: "0640"
owner: root owner: root
group: prometheus group: prometheus
notify: Restart prometheus notify: Restart prometheus
- name: Create host config directory
ansible.builtin.file:
path: /etc/prometheus/node.d
state: directory
mode: "0750"
owner: root
group: prometheus
- name: Create host configs - name: Create host configs
ansible.builtin.template: ansible.builtin.template:
dest: "/srv/prometheus/node.d/{{ item }}.json" dest: "/etc/prometheus/node.d/{{ item }}.json"
src: node.json.j2 src: node.json.j2
mode: "0640" mode: "0640"
owner: root owner: root
@ -88,15 +75,6 @@
notify: Restart prometheus notify: Restart prometheus
with_items: "{{ groups['all'] }}" with_items: "{{ groups['all'] }}"
- name: Create service file
ansible.builtin.copy:
dest: /etc/systemd/system/prometheus.service
src: prometheus.service
mode: "0644"
owner: root
group: "{{ ansible_wheel }}"
notify: Restart prometheus
- name: Enable service - name: Enable service
ansible.builtin.service: ansible.builtin.service:
name: prometheus name: prometheus

View file

@ -13,4 +13,4 @@ scrape_configs:
cert_file: "{{ tls_certs }}/{{ inventory_hostname }}.crt" cert_file: "{{ tls_certs }}/{{ inventory_hostname }}.crt"
file_sd_configs: file_sd_configs:
- files: - files:
- /srv/prometheus/node.d/*.json - /etc/prometheus/node.d/*.json