/
c3mc-mon-mysql-v3-exportercheck
executable file
·57 lines (41 loc) · 1.22 KB
/
c3mc-mon-mysql-v3-exportercheck
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
#!/data/Software/mydan/perl/bin/perl
use strict;
use warnings;
$|++;
use YAML::XS;
=head1 SYNOPSIS
$0
=cut
my @x = `docker ps|grep openc3-mysqld-exporter-v3-`;
chomp @x;
my $envpath = "/data/open-c3-data/mysqld-exporter-v3/uuidenv";
system "mkdir -p $envpath" unless -d $envpath;
sub getds
{
my $uuid = shift;
system "docker exec $uuid env > $envpath/$uuid" unless -f "$envpath/$uuid";
my $x = '';
my @x = `cat $envpath/$uuid`;
chomp @x;
map{
my @xx = split /=/, $_;
$x = $xx[1];
}
grep{
/DATA_SOURCE_NAME/
}@x;
$x=~ s/\r//;
return $x;
}
for ( @x )
{
next unless $_ =~ /^([a-zA-Z0-9]{12}).+openc3-mysqld-exporter-v3-([a-z0-9][a-z0-9\-\.]+[a-z0-9])-(\d+)$/;
my ( $addr, $uuid ) = ( "$2:$3", $1 );
my $x = getds( $uuid );
my $conf = eval{ YAML::XS::LoadFile "/data/open-c3-data/mysqld-exporter-v3/cache/$addr"; };
warn "load cache $addr fail: $@" if $@;
next unless $conf && ref $conf eq 'HASH';
$conf->{password} =~ s/@/%40/g if defined $conf->{password};
$conf->{password} =~ s/:/%3a/g if defined $conf->{password};
system "docker kill $uuid" if $x ne "$conf->{user}:$conf->{password}@($conf->{ip}:$conf->{port})/";
}