Skip to content

Commit 2945c12

Browse files
committed
feat: improve machine type detection for containers (Version 2.8.12)
1 parent 6cf3a5a commit 2945c12

4 files changed

Lines changed: 45 additions & 6 deletions

File tree

CURRENT_VERSION.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.8.11
1+
2.8.12

Changelog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2.8.12 2026-01-17
2+
3+
- feat: improve machine type detection to report 'Container' instead of 'Virtual machine' in containers
4+
- feat: update is_docker() to detect containerd and podman runtimes
5+
- chore: bump version to 2.8.12
6+
17
2.8.11 2026-01-17
28

39
- docs: update INTERNALS.md with information about Cloud, SSH, Containers, and Plugins

mysqltuner.pl

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env perl
2-
# mysqltuner.pl - Version 2.8.11
2+
# mysqltuner.pl - Version 2.8.12
33
# High Performance MySQL Tuning Script
44
# Copyright (C) 2015-2023 Jean-Marie Renouard - jmrenouard@gmail.com
55
# Copyright (C) 2006-2023 Major Hayden - major@mhtx.net
@@ -59,7 +59,7 @@ package main;
5959
my $is_win = $^O eq 'MSWin32';
6060

6161
# Set up a few variables for use in the script
62-
my $tunerversion = "2.8.11";
62+
my $tunerversion = "2.8.12";
6363
my ( @adjvars, @generalrec );
6464

6565
# Set defaults
@@ -395,14 +395,17 @@ ()
395395
if ( -f '/proc/self/cgroup' ) {
396396
if ( open( my $fh, '<', '/proc/self/cgroup' ) ) {
397397
while ( my $line = <$fh> ) {
398-
if ( $line =~ /docker|kubepods/ ) {
398+
if ( $line =~ /docker|kubepods|containerd|podman/ ) {
399399
close $fh;
400400
return 1;
401401
}
402402
}
403403
close $fh;
404404
}
405405
}
406+
return 1
407+
if ( defined $ENV{'container'}
408+
&& $ENV{'container'} =~ /^(docker|podman|lxc)$/ );
406409
return 0;
407410
}
408411

@@ -2313,7 +2316,11 @@ sub get_kernel_info {
23132316
sub get_system_info {
23142317
$result{'OS'}{'Release'} = get_os_release();
23152318
infoprint get_os_release;
2316-
if (is_virtual_machine) {
2319+
if (is_docker()) {
2320+
infoprint "Machine type : Container";
2321+
$result{'OS'}{'Virtual Machine'} = 'YES';
2322+
}
2323+
elsif (is_virtual_machine) {
23172324
infoprint "Machine type : Virtual machine";
23182325
$result{'OS'}{'Virtual Machine'} = 'YES';
23192326
}
@@ -8287,7 +8294,7 @@ =head1 OUTPUT OPTIONS
82878294
82888295
=head1 VERSION
82898296
8290-
Version 2.8.11
8297+
Version 2.8.12
82918298
=head1 PERLDOC
82928299
82938300
You can find documentation for this module with the perldoc command.

tests/machine_type.t

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use strict;
2+
use warnings;
3+
use Test::More;
4+
5+
# Mocking the logic that will be in mysqltuner.pl
6+
sub mock_get_system_info_logic {
7+
my ($is_container, $is_vm) = @_;
8+
my $machine_type = "";
9+
if ($is_container) {
10+
$machine_type = "Container";
11+
}
12+
elsif ($is_vm) {
13+
$machine_type = "Virtual machine";
14+
}
15+
else {
16+
$machine_type = "Physical machine";
17+
}
18+
return $machine_type;
19+
}
20+
21+
is(mock_get_system_info_logic(1, 1), "Container", "Container on VM should be reported as Container");
22+
is(mock_get_system_info_logic(1, 0), "Container", "Container on Physical should be reported as Container");
23+
is(mock_get_system_info_logic(0, 1), "Virtual machine", "VM should be reported as Virtual machine");
24+
is(mock_get_system_info_logic(0, 0), "Physical machine", "Physical should be reported as Physical machine");
25+
26+
done_testing();

0 commit comments

Comments
 (0)