-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmstore
executable file
·68 lines (53 loc) · 1.62 KB
/
mstore
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
#!/bin/env perl
# name: mstore
# date: 20110515
# author: jason thomas <jason@lithiumfox.com>
# purpose: take results of measure(site analytics utility), parse and insert into mysql backend
use strict;
use DBI;
my $ns = "";
my $host = "";
my $time = time;
export_results($time,$host,parse_results(measure($ns, $host)));
sub measure {
my ($ns, $host) = @_;
my $measure_cmd = "/home/jason/bin/measure";
my @measure = ($measure_cmd, "-h", $host, "-p", "80" ,"-u", "/", $ns, $host);
open(STDERR, ">/dev/null");
my @results = `@measure`;
close (STDERR);
return @results;
}
sub parse_results {
my (@results) = @_;
my @captureMatrix;
foreach (@results){
my @capture = ( $_ =~ m/([\d\.]+)\s(?:ms|Bytes)/g);
if (@capture == "6"){
push @captureMatrix, [@capture];
}
}
return @captureMatrix;
}
sub export_results {
my ($time, $host, @capture) = @_;
my %db = (
username => "",
password => "",
dbname => "",
dbtable => "",
mysqlhost => "",
);
my $dbh = DBI->connect(
"DBI:mysql:database=$db{dbname};host=$db{mysqlhost}",
$db{username},
$db{password},
{'RaiseError'=> 1}
);
for my $i ( 0 .. $#capture){
my $insert = sprintf("INSERT INTO $db{dbtable} VALUES (FROM_UNIXTIME($time), $i, '$host', $capture[$i][0], $capture[$i][1], $capture[$i][2], $capture[$i][3], $capture[$i][4], $capture[$i][5])");
eval {$dbh->do($insert)};
print "Inserting to $db{dbtable} failed: $@\n" if $@;
}
$dbh->disconnect();
}