/
c3mc-agent-network-check-once
executable file
·82 lines (61 loc) · 2.66 KB
/
c3mc-agent-network-check-once
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/data/Software/mydan/perl/bin/perl -I/data/Software/mydan/Connector/lib
use strict;
use warnings;
$|++;
use MYDB;
use Time::HiRes qw( time );
my ( $ip, $show ) = @ARGV;
die "ip err" unless $ip && $ip =~ /^\d+\.\d+\.\d+\.\d+$/;
sub call
{
my $cmd = shift @_;
my %re = ( error => '', usetime => 0 );
my $time = time;
my $x = `$cmd`;
chomp $x;
$re{usetime} = time - $time;
$re{error} = "err:$x" unless $x && $x =~ /ok$/;
$re{error} =~ s/'/"/g;
return \%re;
}
sub run
{
my %re = (
tcp_error => '',
tcp_speed_push => '0',
tcp_speed_pull => '0',
udp_error => '',
udp_speed => '0',
);
my $x = call( "/data/Software/mydan/dan/tools/rcall --verbose --timeout 15 -r '$ip' exec 'echo ok' 2>&1" );
return \%re if $re{tcp_error} = $x->{error};
my $tempfile = "/tmp/openc3-network-check-temp";
return \%re if system "dd if=/dev/urandom of=$tempfile bs=1024 count=1024 2>/dev/null";
$x = call( "/data/Software/mydan/dan/tools/rcall --verbose --timeout 15 -r '$ip' dump $tempfile" );
$re{tcp_speed_push} = $x->{usetime} ? int (( 1 / $x->{usetime} ) * 1024 ) : 0;
$x = call("/data/Software/mydan/dan/tools/rcall --verbose --timeout 15 -r '$ip' exec 'dd if=/dev/urandom of=$tempfile bs=1024 count=1024 2>/dev/null && echo ok' 2>&1");
$x = call( "/data/Software/mydan/dan/tools/load --verbose --timeout 15 --host $ip --sp $tempfile && echo ok" );
$re{tcp_speed_pull} = $x->{usetime} ? int (( 1 / $x->{usetime} ) * 1024 ) : 0;
my $temppath = "/data/glusterfs/ci_repo/0";
system "mkdir -p '$temppath'" unless -d $temppath;
return \%re if system "dd if=/dev/urandom of=$temppath/v001 bs=1024 count=1024 2>/dev/null";
$x = call( "TIMEOUT=60 NODE=test.env FLOWID=0 VERSION=v001 /data/Software/mydan/JOB/buildin/tsunamiudp $ip 2>/dev/null" );
return \%re if $re{udp_error} = $x->{error};
$re{udp_speed} = $x->{usetime} ? int (( 1 / $x->{usetime} ) * 1024 ) : 0;
return \%re;
}
my $x = run();
if( $show )
{
map{ $x->{$_} =~ s/\s/_/g; $x->{$_} =~ s/\n/\\n/g; }keys %$x;
print "$ip: tcp_error:$x->{tcp_error} tcp_speed_push:$x->{tcp_speed_push}k/s tcp_speed_pull:$x->{tcp_speed_pull}k/s udp_error:$x->{udp_error} udp_speed:$x->{udp_speed}k/s\n";
exit;
}
my $db = MYDB->new( "/data/Software/mydan/AGENT/conf/conn", delayedconnection => 1 );
eval{
$db->execute(
"replace into `openc3_agent_node_network_check` (`node`,`tcp_error`,`tcp_speed`,`udp_error`,`udp_speed`) " .
"values('$ip','$x->{tcp_error}','$x->{tcp_speed_push}k/s / $x->{tcp_speed_pull}k/s','$x->{udp_error}','$x->{udp_speed}k/s')"
);
};
die "err: $@" if $@;