Skip to content

Commit f4d1139

Browse files
DanielElghjfcoz
authored andcommitted
Try to detect hypervisor using systemd-detect-virt. Falls back to dmesg if unsuccessfull (#38)
Closes #29 Closes #37
1 parent 7d21e80 commit f4d1139

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

postgresqltuner.pl

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
exit 1;
5757
}
5858

59-
my $script_version="1.0.0";
59+
my $script_version="1.0.1";
6060
my $script_name="postgresqltuner.pl";
6161
my $min_s=60;
6262
my $hour_s=60*$min_s;
@@ -297,23 +297,30 @@ sub usage {
297297
# Hardware
298298
my $hypervisor=undef;
299299
if ($os->{name} ne 'darwin') {
300-
my @dmesg=os_cmd("dmesg");
301-
foreach my $line (@dmesg) {
302-
if ($line =~ /vmware/i) {
303-
$hypervisor='VMware';
304-
last;
305-
} elsif ($line =~ /kvm/i) {
306-
$hypervisor='KVM';
307-
last;
308-
} elsif ($line =~ /xen/i) {
309-
$hypervisor='XEN';
310-
last;
311-
} elsif ($line =~ /vbox/i) {
312-
$hypervisor='VirtualBox';
313-
last;
314-
} elsif ($line =~ /hyper-v/i) {
315-
$hypervisor='Hyper-V';
316-
last;
300+
my $systemd = os_cmd('systemd-detect-virt --vm');
301+
if (defined($systemd)) {
302+
if ($systemd =~ m/(\S+)/) {
303+
$hypervisor = $1 if ($1 ne 'none');
304+
}
305+
} else {
306+
my @dmesg=os_cmd("dmesg");
307+
foreach my $line (@dmesg) {
308+
if ($line =~ /vmware/i) {
309+
$hypervisor='VMware';
310+
last;
311+
} elsif ($line =~ /kvm/i) {
312+
$hypervisor='KVM';
313+
last;
314+
} elsif ($line =~ /xen/i) {
315+
$hypervisor='XEN';
316+
last;
317+
} elsif ($line =~ /vbox/i) {
318+
$hypervisor='VirtualBox';
319+
last;
320+
} elsif ($line =~ /hyper-v/i) {
321+
$hypervisor='Hyper-V';
322+
last;
323+
}
317324
}
318325
}
319326
}

0 commit comments

Comments
 (0)