* Started work on parsing the gathered DRBD data.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 4 years ago
parent 4d5ec72026
commit 4e843baa17
  1. 112
      scancore-agents/scan-drbd/scan-drbd
  2. 4
      scancore-agents/scan-drbd/scan-drbd.sql
  3. 13
      tools/test.pl

@ -94,6 +94,8 @@ if (not gather_data($anvil))
$anvil->nice_exit({exit_code => 2}); $anvil->nice_exit({exit_code => 2});
} }
find_changes($anvil);
# Update the database # Update the database
$anvil->Database->insert_or_update_updated({updated_by => $THIS_FILE}); $anvil->Database->insert_or_update_updated({updated_by => $THIS_FILE});
@ -106,6 +108,82 @@ $anvil->nice_exit({exit_code => 0});
# Functions # # Functions #
############################################################################################################# #############################################################################################################
sub find_changes
{
my ($anvil) = @_;
#print Dumper $anvil->data->{new};
print __LINE__."; new::scan_drbd:\n";
foreach my $option (sort {$a cmp $b} keys %{$anvil->data->{new}{scan_drbd}})
{
next if $option eq "scan_drbd_common_xml";
print __LINE__."; - ".$option.": [".$anvil->data->{new}{scan_drbd}{$option}."]\n";
}
print __LINE__."; Resources:\n";
foreach my $resource (sort {$a cmp $b} keys %{$anvil->data->{new}{resource}})
{
print __LINE__."; - ".$resource."\n";
foreach my $option (sort {$a cmp $b} keys %{$anvil->data->{new}{resource}{$resource}})
{
next if $option eq "volume";
next if $option eq "peer";
next if $option eq "xml";
print __LINE__."; |- ".$option.": [".$anvil->data->{new}{resource}{$resource}{$option}."]\n";
}
foreach my $peer (sort {$a cmp $b} keys %{$anvil->data->{new}{resource}{$resource}{peer}})
{
print __LINE__."; |- peer: [".$peer."]\n";
foreach my $option (sort {$a cmp $b} keys %{$anvil->data->{new}{resource}{$resource}{peer}{$peer}})
{
print __LINE__."; | |- ".$option.": [".$anvil->data->{new}{resource}{$resource}{peer}{$peer}{$option}."]\n";
}
}
foreach my $volume (sort {$a cmp $b} keys %{$anvil->data->{new}{resource}{$resource}{volume}})
{
print __LINE__."; |- volume: [".$volume."]\n";
foreach my $option (sort {$a cmp $b} keys %{$anvil->data->{new}{resource}{$resource}{volume}{$volume}})
{
next if $option eq "peer";
print __LINE__."; | |- ".$option.": [".$anvil->data->{new}{resource}{$resource}{volume}{$volume}{$option}."]\n";
foreach my $peer (sort {$a cmp $b} keys %{$anvil->data->{new}{resource}{$resource}{volume}{$volume}{peer}})
{
print __LINE__."; | | |- ".$peer.";\n";
foreach my $peer_option (sort {$a cmp $b} keys %{$anvil->data->{new}{resource}{$resource}{volume}{$volume}{peer}{$peer}})
{
print __LINE__."; | | | |- ".$peer_option.": [".$anvil->data->{new}{resource}{$resource}{volume}{$volume}{peer}{$peer}{$peer_option}."]\n";
if (($peer_option eq "out_of_sync_size") &&
($anvil->data->{new}{resource}{$resource}{volume}{$volume}{peer}{$peer}{$peer_option}) &&
($anvil->data->{new}{resource}{$resource}{volume}{$volume}{peer}{$peer}{connection_state} =~ /sync/))
{
my $resource_size = $anvil->data->{new}{resource}{$resource}{volume}{$volume}{size};
my $say_res_size = $anvil->Convert->bytes_to_human_readable({'bytes' => $resource_size});
my $bytes_to_sync = $anvil->data->{new}{resource}{$resource}{volume}{$volume}{peer}{$peer}{$peer_option};
my $say_to_sync = $anvil->Convert->bytes_to_human_readable({'bytes' => $bytes_to_sync});
my $bytes_in_sync = $resource_size - $bytes_to_sync;
my $say_in_sync = $anvil->Convert->bytes_to_human_readable({'bytes' => $bytes_in_sync});
my $percent_complete = $anvil->Convert->round({
number => (($bytes_in_sync / $resource_size) * 100),
places => 2,
});
### NOTE: So, if we're a node and the peer is Sync'ing from DR, we'll see the OOS drop and can calculate the % sync change, but we don't see the ETA.
### Also, it appears to be random which peer a node decides to sync from.
### So what we'll need to do when generating the JSON for the UI is to see which peers are SyncSource and SyncTarget and pull the ETA from them.
# print __LINE__."; Resource size: [".$say_res_size." (".$resource_size.")]\n";
# print __LINE__."; Bytes in Sync: [".$say_in_sync." (".$bytes_in_sync.")]\n";
# print __LINE__."; Bytes to Sync: [".$say_to_sync." (".$bytes_to_sync.")]\n";
print __LINE__."; | | | | \\- Sync'ed: [".$percent_complete."%] (".$say_in_sync." of ".$say_res_size." sync'ed, ".$say_to_sync." remaining)\n";
}
}
}
}
}
}
return(0);
}
sub gather_data sub gather_data
{ {
my ($anvil) = @_; my ($anvil) = @_;
@ -203,7 +281,7 @@ sub gather_data
's2:conf_file' => $conf_file, 's2:conf_file' => $conf_file,
}}); }});
$anvil->data->{new}{resource}{$resource}{xml} = $name; $anvil->data->{new}{resource}{$resource}{xml} = $name->toString;
$anvil->data->{new}{resource}{$resource}{up} = 0; $anvil->data->{new}{resource}{$resource}{up} = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
"new::resource::${resource}::xml" => $anvil->data->{new}{resource}{$resource}{xml}, "new::resource::${resource}::xml" => $anvil->data->{new}{resource}{$resource}{xml},
@ -253,10 +331,16 @@ sub gather_data
"s2:new::resource::${resource}::peer::${peer}::tcp_port" => $anvil->data->{new}{resource}{$resource}{peer}{$peer}{tcp_port}, "s2:new::resource::${resource}::peer::${peer}::tcp_port" => $anvil->data->{new}{resource}{$resource}{peer}{$peer}{tcp_port},
}}); }});
if (not exists $anvil->data->{new}{resource}{$resource}{peer}{$peer}{protocol})
# Setup some default values. {
$anvil->data->{new}{resource}{$resource}{peer}{$peer}{protocol} = "unknown"; $anvil->data->{new}{resource}{$resource}{peer}{$peer}{protocol} = "unknown";
$anvil->data->{new}{resource}{$resource}{peer}{$peer}{fencing} = "unknown"; $anvil->data->{new}{resource}{$resource}{peer}{$peer}{fencing} = "unknown";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"s1:new::resource::${resource}::peer::${peer}::protocol" => $anvil->data->{new}{resource}{$resource}{peer}{$peer}{protocol},
"s2:new::resource::${resource}::peer::${peer}::fencing" => $anvil->data->{new}{resource}{$resource}{peer}{$peer}{fencing},
}});
}
foreach my $volume (sort {$a cmp $b} keys %{$anvil->data->{new}{resource}{$resource}{volume}}) foreach my $volume (sort {$a cmp $b} keys %{$anvil->data->{new}{resource}{$resource}{volume}})
{ {
$anvil->data->{new}{resource}{$resource}{volume}{$volume}{peer}{$peer}{connection_state} = "disconnected"; $anvil->data->{new}{resource}{$resource}{volume}{$volume}{peer}{$peer}{connection_state} = "disconnected";
@ -352,11 +436,11 @@ sub gather_data
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { file_body => $file_body }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { file_body => $file_body }});
foreach my $line (split/\n/, $file_body) foreach my $line (split/\n/, $file_body)
{ {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { line => $line }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { line => $line }});
if ($line =~ /cs:(.*?) /) if ($line =~ /cs:(.*?) /)
{ {
$anvil->data->{new}{resource}{$resource}{volume}{$volume}{peer}{$peer}{connection_state} = $1; $anvil->data->{new}{resource}{$resource}{volume}{$volume}{peer}{$peer}{connection_state} = lc($1);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"new::resource::${resource}::volume::${volume}::peer::${peer}::connection_state" => $anvil->data->{new}{resource}{$resource}{volume}{$volume}{peer}{$peer}{connection_state}, "new::resource::${resource}::volume::${volume}::peer::${peer}::connection_state" => $anvil->data->{new}{resource}{$resource}{volume}{$volume}{peer}{$peer}{connection_state},
}}); }});
@ -390,8 +474,8 @@ sub gather_data
} }
if ($line =~ /ds:(.*?)\/(.*?) /) if ($line =~ /ds:(.*?)\/(.*?) /)
{ {
$anvil->data->{new}{resource}{$resource}{volume}{$volume}{peer}{$peer}{local_disk_state} = $1; $anvil->data->{new}{resource}{$resource}{volume}{$volume}{peer}{$peer}{local_disk_state} = lc($1);
$anvil->data->{new}{resource}{$resource}{volume}{$volume}{peer}{$peer}{peer_disk_state} = $2; $anvil->data->{new}{resource}{$resource}{volume}{$volume}{peer}{$peer}{peer_disk_state} = lc($2);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"new::resource::${resource}::volume::${volume}::peer::${peer}::local_disk_state" => $anvil->data->{new}{resource}{$resource}{volume}{$volume}{peer}{$peer}{local_disk_state}, "new::resource::${resource}::volume::${volume}::peer::${peer}::local_disk_state" => $anvil->data->{new}{resource}{$resource}{volume}{$volume}{peer}{$peer}{local_disk_state},
"new::resource::${resource}::volume::${volume}::peer::${peer}::peer_disk_state" => $anvil->data->{new}{resource}{$resource}{volume}{$volume}{peer}{$peer}{peer_disk_state}, "new::resource::${resource}::volume::${volume}::peer::${peer}::peer_disk_state" => $anvil->data->{new}{resource}{$resource}{volume}{$volume}{peer}{$peer}{peer_disk_state},
@ -399,9 +483,9 @@ sub gather_data
} }
if ($line =~ /oos:(\d+)/) if ($line =~ /oos:(\d+)/)
{ {
$anvil->data->{new}{resource}{$resource}{volume}{$volume}{peer}{$peer}{out_of_sync_size} = $1; $anvil->data->{new}{resource}{$resource}{volume}{$volume}{peer}{$peer}{out_of_sync_size} = $1 * 1024;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"new::resource::${resource}::volume::${volume}::peer::${peer}::out_of_sync_size" => $anvil->data->{new}{resource}{$resource}{volume}{$volume}{peer}{$peer}{out_of_sync_size}, "new::resource::${resource}::volume::${volume}::peer::${peer}::out_of_sync_size" => $anvil->data->{new}{resource}{$resource}{volume}{$volume}{peer}{$peer}{out_of_sync_size}." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $anvil->data->{new}{resource}{$resource}{volume}{$volume}{peer}{$peer}{out_of_sync_size}}).")",
}}); }});
} }
=cut =cut
@ -420,14 +504,16 @@ sub gather_data
act_log: used:0/1237 hits:0 misses:0 starving:0 locked:0 changed:0 act_log: used:0/1237 hits:0 misses:0 starving:0 locked:0 changed:0
blocked on activity log: 0/0/0 blocked on activity log: 0/0/0
=cut =cut
if ($line =~ /sync'ed: (.*?\%)/) if ($line =~ /sync'ed:\s+(\d.*\%)/)
{ {
$progress .= $1; $progress .= $1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { progress => $progress }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { progress => $progress }});
} }
if ($line =~ /speed: (.*?) \(/) if ($line =~ /speed: (.*?) \(/)
{ {
$anvil->data->{new}{resource}{$resource}{volume}{$volume}{peer}{$peer}{replication_speed} = ($1 * 1024); $anvil->data->{new}{resource}{$resource}{volume}{$volume}{peer}{$peer}{replication_speed} = $1;
$anvil->data->{new}{resource}{$resource}{volume}{$volume}{peer}{$peer}{replication_speed} =~ s/,//g;
$anvil->data->{new}{resource}{$resource}{volume}{$volume}{peer}{$peer}{replication_speed} *= 1024;
$anvil->data->{new}{scan_drbd}{scan_drbd_total_sync_speed} += $anvil->data->{new}{resource}{$resource}{volume}{$volume}{peer}{$peer}{replication_speed}; $anvil->data->{new}{scan_drbd}{scan_drbd_total_sync_speed} += $anvil->data->{new}{resource}{$resource}{volume}{$volume}{peer}{$peer}{replication_speed};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
@ -447,9 +533,9 @@ sub gather_data
's3:seconds' => $seconds, 's3:seconds' => $seconds,
}}); }});
$anvil->data->{new}{resource}{$resource}{volume}{$volume}{peer}{$peer}{estimated_time_to_sync} = (($hours ** 3600) + ($minutes ** 60) + $seconds); $anvil->data->{new}{resource}{$resource}{volume}{$volume}{peer}{$peer}{estimated_time_to_sync} = (($hours * 3600) + ($minutes * 60) + $seconds);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"new::resource::${resource}::volume::${volume}::peer::${peer}::estimated_time_to_sync" => $anvil->data->{new}{resource}{$resource}{volume}{$volume}{peer}{$peer}{estimated_time_to_sync}." (".$anvil->Convert->time({'time' => $anvil->data->{new}{resource}{$resource}{volume}{$volume}{peer}{$peer}{estimated_time_to_sync}, long => 1}).")", "new::resource::${resource}::volume::${volume}::peer::${peer}::estimated_time_to_sync" => $anvil->data->{new}{resource}{$resource}{volume}{$volume}{peer}{$peer}{estimated_time_to_sync}." (".$anvil->Convert->time({'time' => $anvil->data->{new}{resource}{$resource}{volume}{$volume}{peer}{$peer}{estimated_time_to_sync}, long => 1, translate => 1}).")",
}}); }});
} }
} }

@ -67,6 +67,7 @@ CREATE TABLE scan_drbd_resources (
scan_drbd_resource_uuid uuid not null primary key, scan_drbd_resource_uuid uuid not null primary key,
scan_drbd_resource_host_uuid uuid not null, scan_drbd_resource_host_uuid uuid not null,
scan_drbd_resource_name text not null, -- The name of the resource. scan_drbd_resource_name text not null, -- The name of the resource.
scan_drbd_resource_up boolean not null, -- This indicates if the resource is up on this host.
scan_drbd_resource_xml text not null, -- This is the raw <common> section of 'drbd_resourceadm dump-xml'. scan_drbd_resource_xml text not null, -- This is the raw <common> section of 'drbd_resourceadm dump-xml'.
modified_date timestamp with time zone not null, modified_date timestamp with time zone not null,
@ -79,6 +80,7 @@ CREATE TABLE history.scan_drbd_resources (
scan_drbd_resource_uuid uuid, scan_drbd_resource_uuid uuid,
scan_drbd_resource_host_uuid uuid, scan_drbd_resource_host_uuid uuid,
scan_drbd_resource_name text, scan_drbd_resource_name text,
scan_drbd_resource_up boolean,
scan_drbd_resource_xml text, scan_drbd_resource_xml text,
modified_date timestamp with time zone not null modified_date timestamp with time zone not null
); );
@ -94,12 +96,14 @@ BEGIN
(scan_drbd_resource_uuid, (scan_drbd_resource_uuid,
scan_drbd_resource_host_uuid, scan_drbd_resource_host_uuid,
scan_drbd_resource_name, scan_drbd_resource_name,
scan_drbd_resource_up,
scan_drbd_resource_xml, scan_drbd_resource_xml,
modified_date) modified_date)
VALUES VALUES
(history_scan_drbd_resources.scan_drbd_resource_uuid, (history_scan_drbd_resources.scan_drbd_resource_uuid,
history_scan_drbd_resources.scan_drbd_resource_host_uuid, history_scan_drbd_resources.scan_drbd_resource_host_uuid,
history_scan_drbd_resources.scan_drbd_resource_name, history_scan_drbd_resources.scan_drbd_resource_name,
history_scan_drbd_resources.scan_drbd_resource_up,
history_scan_drbd_resources.scan_drbd_resource_xml, history_scan_drbd_resources.scan_drbd_resource_xml,
history_scan_drbd_resources.modified_date); history_scan_drbd_resources.modified_date);
RETURN NULL; RETURN NULL;

@ -23,7 +23,16 @@ $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "
$anvil->Get->switches; $anvil->Get->switches;
# Connect to the database(s). # Connect to the database(s).
$anvil->Database->connect; #$anvil->Database->connect;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0132"}); #$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0132"});
my $hours = 0;
my $minutes = 3;
my $seconds = 24;
print "Hours: [".$hours."], minutes: [".$minutes."], seconds: [".$seconds."]\n";
my $estimated_time_to_sync = (($hours * 3600) + ($minutes * 60) + $seconds);
print "ETA: [".$estimated_time_to_sync."] (".$anvil->Convert->time({'time' => $estimated_time_to_sync}).")\n";
$anvil->nice_exit({exit_code => 0}); $anvil->nice_exit({exit_code => 0});

Loading…
Cancel
Save