diff --git a/bundles/vnstat/files/vnstat.conf b/bundles/vnstat/files/vnstat.conf new file mode 100644 index 0000000..26d6896 --- /dev/null +++ b/bundles/vnstat/files/vnstat.conf @@ -0,0 +1,61 @@ +Interface "${interface}" +DatabaseDir "/var/lib/vnstat" +Locale "-" +MonthRotate 1 +DayFormat "%Y-%m-%d" +MonthFormat "%Y-%m" +TopFormat "%Y-%m-%d" +RXCharacter "%" +TXCharacter ":" +RXHourCharacter "r" +TXHourCharacter "t" +UnitMode 0 +RateUnitMode 1 +OutputStyle 3 +RateUnit 1 +DefaultDecimals 2 +HourlyDecimals 1 +HourlySelectionStyle 2 +BandwidthDetection 0 +MaxBandwidth ${bandwidth} +SampleTime 5 +QueryMode 2 +CheckDiskSpace 1 +UseFileLocking 1 +BootVariation 5 +TrafficlessDays 1 + +# vnstatd +DaemonUser "" +DaemonGroup "" +TimeSyncWait 5 +UpdateInterval 10 +PollInterval 5 +SaveInterval 5 +OfflineSaveInterval 15 +BandwidthDetectionInterval 30 +SaveOnStatusChange 1 +UseLogging 2 +CreateDirs 1 +UpdateFileOwner 1 +PidFile "/var/run/vnstat/vnstat.pid" + +# vnstati +HeaderFormat "%Y-%m-%d %H:%M" +HourlyRate 1 +SummaryRate 1 +SummaryLayout 1 +TransparentBg 0 +CBackground "FFFFFF" +CEdge "AEAEAE" +CHeader "606060" +CHeaderTitle "FFFFFF" +CHeaderDate "FFFFFF" +CText "000000" +CLine "B0B0B0" +CLineL "-" +CRx "92CF00" +CTx "606060" +CRxD "-" +CTxD "-" + diff --git a/bundles/vnstat/items.py b/bundles/vnstat/items.py new file mode 100644 index 0000000..bb3662c --- /dev/null +++ b/bundles/vnstat/items.py @@ -0,0 +1,18 @@ +files = { + '/etc/vnstat.conf': { + 'content_type': 'mako', + 'context': node.metadata['vnstat'], + 'triggers': { + 'svc_systemd:vnstat:restart', + }, + }, +} + +svc_systemd = { + 'vnstat': { + 'needs': { + 'pkg_apt:vnstat', + 'file:/etc/vnstat.conf', + }, + }, +} diff --git a/bundles/vnstat/metadata.py b/bundles/vnstat/metadata.py new file mode 100644 index 0000000..efd0ae0 --- /dev/null +++ b/bundles/vnstat/metadata.py @@ -0,0 +1,25 @@ +defaults = { + 'apt': { + 'packages': { + 'vnstat': {}, + 'vnstati': {}, + }, + }, + 'vnstat': { + 'bandwidth': '1000', + }, +} + + +@metadata_reactor +def get_default_interface(metadata): + interfaces = sorted(metadata.get('interfaces', {}).keys()) + + if len(interfaces): + return { + 'vnstat': { + 'interface': interfaces[0], + }, + } + + return {} diff --git a/nodes/home/router.py b/nodes/home/router.py index 4809ad3..26230f8 100644 --- a/nodes/home/router.py +++ b/nodes/home/router.py @@ -8,6 +8,7 @@ nodes['home.router'] = { 'pppd', 'radvd', 'dhcpd', + 'vnstat', 'wide-dhcp6c', }, 'groups': set(), @@ -105,6 +106,9 @@ nodes['home.router'] = { }, }, }, + 'vnstat': { + 'interface': 'enp1s0.100', + }, 'vm': { 'cpu': 2, 'ram': 2,