5 ## Include script that sets two variables that can be used to evaluate actual memory
6 ## usage in NDB data nodes
9 ## $ndb_node_id - The node ID to get the memory usage for, can be a number of the node, or 'ALL',
10 ## which returns the average useage over all nodes. ALL is the default value.
12 ## Returned variables:
13 ## $MTR_NDB_DATA_USAGE_PERCENTAGE - The percentage of data memory used on all nodes
14 ## $MTR_NDB_INDEX_USAGE_PERCENTAGE - The percentage of index memory used on all nodes
16 ## Values are read from ndb_mgm REPORT MemoryUsage
18 ## Example output from ALL REPORT MemoryUsage
19 ## ndb_mgm -e "ALL REPORT MemoryUsage"
20 ## Connected to Management Server at: localhost:16660
21 ## Node 1: Data usage is 85%(548 32K pages of total 640)
22 ## Node 1: Index usage is 86%(138 8K pages of total 160)
23 ## Node 2: Data usage is 85%(548 32K pages of total 640)
24 ## Node 2: Index usage is 86%(138 8K pages of total 160)
33 my $vardir = $ENV{MYSQLTEST_VARDIR} or die
"Need MYSQLTEST_VARDIR";
34 my $ndb_connectstring = $ENV{NDB_CONNECTSTRING} or die
"Need NDB_CONNECTSTRING";
35 my $ndb_mgm = $ENV{NDB_MGM} or die
"Need NDB_MGM";
38 my $ndb_node_id = $ENV{ndb_node_id} ||
'ALL';
40 my $cmd =
"$ndb_mgm --ndb-connectstring='$ndb_connectstring' -e \"$ndb_node_id REPORT MemoryUsage\"";
41 # print "Calling ndb_mgm: '$cmd'\n";
45 foreach my $line (split(
"\n", $output)) {
47 next
if ($line =~ m/^,+$/g);
49 if ($line =~ m/Node (\d+): (Index|
Data) usage is \d+%\((\d+) (\d+)K pages of total (\d+)\)/g) {
56 if (!defined $memory->{$type}) {
59 if (!defined $memory->{$type}->{$node_id}) {
60 $memory->{$type}->{$node_id} = {};
62 $memory->{$type}->{$node_id}->{
'used'} = $used;
63 $memory->{$type}->{$node_id}->{
'total'} = $total;
64 $memory->{$type}->{$node_id}->{
'size'} = $size;
68 sub usage_percentage {
75 foreach my $node (keys %{$mem->{$type}}) {
76 $used += $mem->{$type}->{$node}->{
'used'};
77 $total += $mem->{$type}->{$node}->{
'total'};
79 die
"Parsing error - not able to detect total number of pages, output: '$output'" if ($total == 0);
80 return sprintf(
"%.2f", $used * 100 / $total);
83 my $num_nodes = scalar(keys %{$memory->{
Data}});
84 my $data_usage_percentage = usage_percentage(
'Data', $memory);
85 my $index_usage_percentage = usage_percentage(
'Index', $memory);
87 my $file_name =
"$vardir/tmp/ndb_memory_usage_result.inc";
88 my $F = IO::File->new($file_name,
'w') or die
"Could not open '$file_name' for writing";
89 print $F
"--let \$MTR_NDB_DATA_USAGE_PERCENTAGE= $data_usage_percentage\n";
90 print $F
"--let \$MTR_NDB_INDEX_USAGE_PERCENTAGE= $index_usage_percentage\n";
95 --source $MYSQLTEST_VARDIR/tmp/ndb_memory_usage_result.inc