From 41a1d0bac395d5eec395d0d12a1dc6c29ee5312f Mon Sep 17 00:00:00 2001 From: Tobias Hachmer Date: Sun, 31 Dec 2017 12:40:00 +0100 Subject: [PATCH] Add role service-vnstat --- playbooks/gateways.yml | 1 + roles/service-vnstat/README.md | 15 ++ roles/service-vnstat/handlers/main.yml | 5 + roles/service-vnstat/tasks/main.yml | 23 +++ roles/service-vnstat/templates/vnstat.conf.j2 | 152 ++++++++++++++++++ 5 files changed, 196 insertions(+) create mode 100644 roles/service-vnstat/README.md create mode 100644 roles/service-vnstat/handlers/main.yml create mode 100644 roles/service-vnstat/tasks/main.yml create mode 100644 roles/service-vnstat/templates/vnstat.conf.j2 diff --git a/playbooks/gateways.yml b/playbooks/gateways.yml index 8adeeb0..fcefd39 100755 --- a/playbooks/gateways.yml +++ b/playbooks/gateways.yml @@ -32,3 +32,4 @@ - service-bird-ffrl - service-bind-slave - service-respondd + - service-vnstat diff --git a/roles/service-vnstat/README.md b/roles/service-vnstat/README.md new file mode 100644 index 0000000..72f0107 --- /dev/null +++ b/roles/service-vnstat/README.md @@ -0,0 +1,15 @@ +# Ansible role service-vnstat + +Diese Ansible role installiert und konfiguriert den vnstat daemon. + +- schreibt vnstat.conf + +## Benötigte Variablen + +- Variable `ansible_default_ipv4.interface` (Setup) + +## ToDo + +- Liste mit Interfaces erstellen +- Nginx vHost für vnstati Images +- Script erstellen (systemd timer), das zyklisch vnstati Images erzeugt diff --git a/roles/service-vnstat/handlers/main.yml b/roles/service-vnstat/handlers/main.yml new file mode 100644 index 0000000..5d20cff --- /dev/null +++ b/roles/service-vnstat/handlers/main.yml @@ -0,0 +1,5 @@ +--- +- name: restart systemd unit vnstat + systemd: + name: vnstat + state: restarted diff --git a/roles/service-vnstat/tasks/main.yml b/roles/service-vnstat/tasks/main.yml new file mode 100644 index 0000000..69b19f4 --- /dev/null +++ b/roles/service-vnstat/tasks/main.yml @@ -0,0 +1,23 @@ +--- +- name: install vnstat packages + package: + name: "{{ item }}" + state: present + with_items: + - vnstat + - vnstati + +- name: write vnstat.conf + template: + src: vnstat.conf.j2 + dest: /etc/vnstat.conf + mode: 0644 + owner: root + group: vnstat + notify: restart systemd unit vnstat + +- name: enable and start systemd unit vnstat + systemd: + name: vnstat + enabled: yes + state: started diff --git a/roles/service-vnstat/templates/vnstat.conf.j2 b/roles/service-vnstat/templates/vnstat.conf.j2 new file mode 100644 index 0000000..9a3ab41 --- /dev/null +++ b/roles/service-vnstat/templates/vnstat.conf.j2 @@ -0,0 +1,152 @@ +# +# {{ ansible_managed }} +# +# vnStat 1.15 config file +## + +# default interface +Interface "{{ ansible_default_ipv4.interface }}" + +# location of the database directory +DatabaseDir "/var/lib/vnstat" + +# locale (LC_ALL) ("-" = use system locale) +Locale "-" + +# on which day should months change +MonthRotate 1 + +# date output formats for -d, -m, -t and -w +# see 'man date' for control codes +DayFormat "%x" +MonthFormat "%b '%y" +TopFormat "%x" + +# characters used for visuals +RXCharacter "%" +TXCharacter ":" +RXHourCharacter "r" +TXHourCharacter "t" + +# how units are prefixed when traffic is shown +# 0 = IEC standard prefixes (KiB/MiB/GiB/TiB) +# 1 = old style binary prefixes (KB/MB/GB/TB) +UnitMode 0 + +# output style +# 0 = minimal & narrow, 1 = bar column visible +# 2 = same as 1 except rate in summary and weekly +# 3 = rate column visible +OutputStyle 3 + +# used rate unit (0 = bytes, 1 = bits) +RateUnit 1 + +# try to detect interface maximum bandwidth, 0 = disable feature +# MaxBandwidth will be used as fallback value when enabled +BandwidthDetection 1 + +# maximum bandwidth (Mbit) for all interfaces, 0 = disable feature +# (unless interface specific limit is given) +MaxBandwidth 1000 + +# interface specific limits +# example 8Mbit limit for eth0 (remove # to activate): +#MaxBWeth0 8 + +# how many seconds should sampling for -tr take by default +Sampletime 5 + +# default query mode +# 0 = normal, 1 = days, 2 = months, 3 = top10 +# 4 = exportdb, 5 = short, 6 = weeks, 7 = hours +QueryMode 0 + +# filesystem disk space check (1 = enabled, 0 = disabled) +CheckDiskSpace 1 + +# database file locking (1 = enabled, 0 = disabled) +UseFileLocking 1 + +# how much the boot time can variate between updates (seconds) +BootVariation 15 + +# log days without traffic to daily list (1 = enabled, 0 = disabled) +TrafficlessDays 1 + + +# vnstatd +## + +# switch to given user when started as root (leave empty to disable) +DaemonUser "" + +# switch to given user when started as root (leave empty to disable) +DaemonGroup "" + +# how often (in seconds) interface data is updated +UpdateInterval 30 + +# how often (in seconds) interface status changes are checked +PollInterval 5 + +# how often (in minutes) data is saved to file +SaveInterval 5 + +# how often (in minutes) data is saved when all interface are offline +OfflineSaveInterval 30 + +# how often (in minutes) bandwidth detection is redone when +# BandwidthDetection is enabled (0 = disabled) +BandwidthDetectionInterval 5 + +# force data save when interface status changes (1 = enabled, 0 = disabled) +SaveOnStatusChange 1 + +# enable / disable logging (0 = disabled, 1 = logfile, 2 = syslog) +UseLogging 2 + +# create dirs if needed (1 = enabled, 0 = disabled) +CreateDirs 1 + +# update ownership of files if needed (1 = enabled, 0 = disabled) +UpdateFileOwner 1 + +# file used for logging if UseLogging is set to 1 +LogFile "/var/log/vnstat/vnstat.log" + +# file used as daemon pid / lock file +PidFile "/var/run/vnstat/vnstat.pid" + + +# vnstati +## + +# title timestamp format +HeaderFormat "%x %H:%M" + +# show hours with rate (1 = enabled, 0 = disabled) +HourlyRate 1 + +# show rate in summary (1 = enabled, 0 = disabled) +SummaryRate 1 + +# layout of summary (1 = with monthly, 0 = without monthly) +SummaryLayout 1 + +# transparent background (1 = enabled, 0 = disabled) +TransparentBg 0 + +# image colors +CBackground "FFFFFF" +CEdge "AEAEAE" +CHeader "606060" +CHeaderTitle "FFFFFF" +CHeaderDate "FFFFFF" +CText "000000" +CLine "B0B0B0" +CLineL "-" +CRx "92CF00" +CTx "606060" +CRxD "-" +CTxD "-"