このようなことがありますか?
#!/usr/bin/perl
use strict;
use warnings;
use DBI;
my $user = "root";
my $pass = "password";
my $db = "information_schema";
my $dbh = DBI->connect("DBI:mysql:$db", $user, $pass)
or die "Connection error: $DBI::errstr\n";
my $sql = "show processlist";
my $sth = $dbh->prepare($sql);
$sth->execute() or die "SQL error: $DBI::errstr\n";
my %user;
while (my @row = $sth->fetchrow_array()) {
$user{$row[1]}++;
}
print "MySQL - Logged in users\n";
print "=" x 15, "\n";
for my $x (keys %user) {
print "$x - $user{$x} connections\n";
}
結果:
MySQL - Logged in users
===============
ndoutils - 6 connections
root - 1 connections
nagiosql - 5 connections
私のニーズに合わせて修正しました。これは非常に役に立ちました。 – Charles