403Webshell
Server IP : 104.21.38.3  /  Your IP : 172.70.208.30
Web Server : Apache
System : Linux krdc-ubuntu-s-2vcpu-4gb-amd-blr1-01.localdomain 5.15.0-142-generic #152-Ubuntu SMP Mon May 19 10:54:31 UTC 2025 x86_64
User : www ( 1000)
PHP Version : 7.4.33
Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /www/server/mysql/src/mysql-test/suite/ndb/include/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /www/server/mysql/src/mysql-test/suite/ndb/include/memory_usage.inc
--perl
##
## NDB Memory Usage
##
## Include script that sets two variables that can be used to evaluate actual memory
## usage in NDB data nodes
##
## Parameters:
##   $ndb_node_id - The node ID to get the memory usage for, can be a number of the node, or 'ALL',
##                  which returns the average useage over all nodes. ALL is the default value.
##
## Returned variables:
##   $MTR_NDB_DATA_USAGE_PERCENTAGE  - The percentage of data memory used on all nodes
##   $MTR_NDB_INDEX_USAGE_PERCENTAGE - The percentage of index memory used on all nodes
##
## Values are read from ndb_mgm REPORT MemoryUsage
##
## Example output from ALL REPORT MemoryUsage
## ndb_mgm -e "ALL REPORT MemoryUsage"
## Connected to Management Server at: localhost:16660
## Node 1: Data usage is 85%(548 32K pages of total 640)
## Node 1: Index usage is 86%(138 8K pages of total 160)
## Node 2: Data usage is 85%(548 32K pages of total 640)
## Node 2: Index usage is 86%(138 8K pages of total 160)

use strict;

use IO::File;

#
# Set up paths
#
my $vardir = $ENV{MYSQLTEST_VARDIR} or die "Need MYSQLTEST_VARDIR";
my $ndb_connectstring = $ENV{NDB_CONNECTSTRING} or die "Need NDB_CONNECTSTRING";
my $ndb_mgm = $ENV{NDB_MGM} or die "Need NDB_MGM";

# Input parameters
my $ndb_node_id = $ENV{ndb_node_id} || 'ALL';

my $cmd = "$ndb_mgm --ndb-connectstring='$ndb_connectstring' -e \"$ndb_node_id REPORT MemoryUsage\"";
# print "Calling ndb_mgm: '$cmd'\n";
my $output = `$cmd`;

my $memory = {};
foreach my $line (split("\n", $output)) {
    # Skip empty lines
    next if ($line =~ m/^,+$/g);

    if ($line =~ m/Node (\d+): (Index|Data) usage is \d+%\((\d+) (\d+)K pages of total (\d+)\)/g) {
        my $node_id = $1;
        my $type = lc($2);
        my $used = $3;
        my $size = $4;
        my $total = $5;

        if (!defined $memory->{$type}) {
            $memory->{$type} = {}
        }
        if (!defined $memory->{$type}->{$node_id}) {
            $memory->{$type}->{$node_id} = {};
        }
        $memory->{$type}->{$node_id}->{'used'} = $used;
        $memory->{$type}->{$node_id}->{'total'} = $total;
        $memory->{$type}->{$node_id}->{'size'} = $size;
    }
}

sub usage_percentage {
    my $type = lc(shift);
    my $mem  = shift;

    my $used = 0;
    my $total = 0;

    foreach my $node (keys %{$mem->{$type}}) {
        $used  += $mem->{$type}->{$node}->{'used'};
        $total += $mem->{$type}->{$node}->{'total'};
    }
    die "Parsing error - not able to detect total number of pages, output: '$output'" if ($total == 0);
    return sprintf("%.2f", $used * 100 / $total);
}

my $num_nodes = scalar(keys %{$memory->{Data}});
my $data_usage_percentage = usage_percentage('Data', $memory);
my $index_usage_percentage = usage_percentage('Index', $memory);

my $file_name = "$vardir/tmp/ndb_memory_usage_result.inc";
my $F = IO::File->new($file_name, 'w') or die "Could not open '$file_name' for writing";
print $F "--let \$MTR_NDB_DATA_USAGE_PERCENTAGE= $data_usage_percentage\n";
print $F "--let \$MTR_NDB_INDEX_USAGE_PERCENTAGE= $index_usage_percentage\n";
$F->close();

EOF

--source $MYSQLTEST_VARDIR/tmp/ndb_memory_usage_result.inc

Youez - 2016 - github.com/yon3zu
LinuXploit