Incus Logwatch

Log-Analyse für Incus.

Konfiguration

sudo nano /etc/logwatch/conf/services/incus.conf
# Incus Service
Title = "Incus Container Logs"
LogFile = syslog
*OnlyService = incus
*ApplyStdDate = "ISO 8601"

Logwatch-Regeln

sudo nano /etc/logwatch/scripts/services/incus
#!/usr/bin/perl
# Incus Logwatch Script

use strict;
use warnings;

my ($line, $service, $message);
my %container_stats;
my %error_count;
my %warning_count;

while (defined($line = <STDIN>)) {
    chomp $line;

    if ($line =~ /incus\[\d+\]: (\w+) (\w+): (.*)/) {
        $service = $1;
        $message = $3;

        if ($message =~ /Started|Created/) {
            $container_stats{'started'}++;
        }
        elsif ($message =~ /Stopped|Deleted/) {
            $container_stats{'stopped'}++;
        }
        elsif ($message =~ /Error|Failed/) {
            $error_count{$service}++;
        }
        elsif ($message =~ /Warning/) {
            $warning_count{$service}++;
        }
    }
}

print "\n=== Incus Container Statistics ===\n";
print "Containers Started: " . ($container_stats{'started'} || 0) . "\n";
print "Containers Stopped: " . ($container_stats{'stopped'} || 0) . "\n";

if (%error_count) {
    print "\n=== Errors ===\n";
    foreach my $service (keys %error_count) {
        print "$service: $error_count{$service} errors\n";
    }
}

if (%warning_count) {
    print "\n=== Warnings ===\n";
    foreach my $service (keys %warning_count) {
        print "$service: $warning_count{$service} warnings\n";
    }
}
sudo chmod +x /etc/logwatch/scripts/services/incus

Test

sudo logwatch --service incus --detail Med --range yesterday

Zurück zur Container-Übersicht