Skip to content

Commit f319622

Browse files
committed
first commit
0 parents  commit f319622

34 files changed

+2388
-0
lines changed

.gitignore

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
cover_db
2+
META.yml
3+
Makefile
4+
blib
5+
inc
6+
pm_to_blib
7+
MANIFEST
8+
Makefile.old
9+
nytprof.out
10+
MANIFEST.bak
11+
*.sw[po]
12+
*~

Changes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
0.01 Wed Apr 21 12:35:12 2010
2+
- in development

Makefile.PL

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
use inc::Module::Install;
2+
name 'CloudForecast';
3+
all_from 'lib/CloudForecast.pm';
4+
5+
tests 't/*.t';
6+
author_tests 'xt';
7+
8+
test_requires 'Test::More';
9+
10+
requires 'Class::Data::Inheritable';
11+
requires 'Class::Accessor::Fast';
12+
requires 'Data::Section::Simple';
13+
requires 'UNIVERSAL::require';
14+
requires 'Path::Class';
15+
requires 'URI::Escape';
16+
requires 'Scalar::Util';
17+
requires 'Plack', 0.9931;
18+
requires 'Router::Simple';
19+
requires 'Text::MicroTemplate';
20+
requires 'Gearman::Client', 1.10;
21+
reuiress 'Gearman::Server';
22+
requries 'Parallel::Prefork';
23+
requires 'YAML', 0.71;
24+
#requires 'RRDs'; $ yum install rrdtool-perl
25+
26+
requires 'LWP::UserAgent';
27+
#requires 'SNMP'; $ yum install net-snmp-perl
28+
requires 'DBI';
29+
30+
#auto_set_repository;
31+
auto_include;
32+
WriteAll;

README

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CloudForecast - server resource monitoring framework
2+
3+
WARNING: Alpha quality code
4+
5+
#
6+
CF_DEBUG=1 ./cloudforecast_radar -c cloudforecast.yaml -l server_list.yaml
7+
8+
# fetcher worker
9+
CF_DEBUG=1 ./cf_fetcher_worker -c cloudforecast.yaml -l server_list.yaml
10+
11+
# rrd update worker
12+
CF_DEBUG=1 ./cf_updater_worker -c cloudforecast.yaml -l server_list.yaml
13+
14+
# web server
15+
CF_DEBUG=1 ./cloudforecast_web -p 5000 -c cloudforecast.yaml -l server_list.yaml
16+

cf_fetcher_worker

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/perl
2+
3+
use strict;
4+
use warnings;
5+
use FindBin;
6+
use lib "$FindBin::Bin/lib";
7+
use lib "$FindBin::Bin/site-lib";
8+
use CloudForecast::Gearman;
9+
use CloudForecast::ConfigLoader;
10+
use Getopt::Long;
11+
12+
my $root_dir = $FindBin::Bin;
13+
my $config_yaml = $root_dir . '/cloudforecast.yaml';
14+
my $server_list_yaml = $root_dir . '/server_list.yaml';
15+
16+
my $max_workers = 4;
17+
my $max_requests_per_child = 100;
18+
19+
GetOptions(
20+
'c|config=s' => \$config_yaml,
21+
'l|server-list=s' => \$server_list_yaml,
22+
'max-workers=i' => \$max_workers,
23+
'max-request-per-child=i' => \$max_requests_per_child,
24+
);
25+
26+
die 'config not found' unless $config_yaml;
27+
die 'server_list not found' unless $server_list_yaml;
28+
29+
my $configloader = CloudForecast::ConfigLoader->new({
30+
root_dir => $root_dir,
31+
global_config => $config_yaml,
32+
server_list => $server_list_yaml,
33+
});
34+
$configloader->load_all();
35+
my $global_config = $configloader->global_config;
36+
37+
die 'gearman is disabled' unless $global_config->{gearman_enable};
38+
39+
40+
my $gearman = CloudForecast::Gearman->new({
41+
host => $global_config->{gearman_server}->{host},
42+
port => $global_config->{gearman_server}->{port},
43+
});
44+
45+
$gearman->fetcher_worker($global_config, $max_workers, $max_requests_per_child);
46+

cf_updater_worker

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/perl
2+
3+
use strict;
4+
use warnings;
5+
use FindBin;
6+
use lib "$FindBin::Bin/lib";
7+
use lib "$FindBin::Bin/site-lib";
8+
use CloudForecast::Gearman;
9+
use CloudForecast::ConfigLoader;
10+
use Getopt::Long;
11+
12+
my $root_dir = $FindBin::Bin;
13+
my $config_yaml = $root_dir . '/cloudforecast.yaml';
14+
my $server_list_yaml = $root_dir . '/server_list.yaml';
15+
16+
my $max_workers = 4;
17+
my $max_requests_per_child = 100;
18+
19+
GetOptions(
20+
'c|config=s' => \$config_yaml,
21+
'l|server-list=s' => \$server_list_yaml,
22+
'max-workers=i' => \$max_workers,
23+
'max-request-per-child=i' => \$max_requests_per_child,
24+
);
25+
26+
die 'config not found' unless $config_yaml;
27+
die 'server_list not found' unless $server_list_yaml;
28+
29+
my $configloader = CloudForecast::ConfigLoader->new({
30+
root_dir => $root_dir,
31+
global_config => $config_yaml,
32+
server_list => $server_list_yaml,
33+
});
34+
$configloader->load_all();
35+
my $global_config = $configloader->global_config;
36+
37+
die 'gearman is disabled' unless $global_config->{gearman_enable};
38+
39+
my $gearman = CloudForecast::Gearman->new({
40+
host => $global_config->{gearman_server}->{host},
41+
port => $global_config->{gearman_server}->{port},
42+
});
43+
44+
$gearman->updater_worker($global_config, $max_workers, $max_requests_per_child);
45+
46+
47+
48+

cloudforecast_radar

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/perl
2+
3+
use strict;
4+
use warnings;
5+
use FindBin;
6+
use lib "$FindBin::Bin/lib";
7+
use lib "$FindBin::Bin/site-lib";
8+
use Getopt::Long;
9+
use CloudForecast::Radar;
10+
11+
my $root_dir = $FindBin::Bin;
12+
my $config = $root_dir . '/cloudforecast.yaml';
13+
my $server_list = $root_dir .'/server_list.yaml';
14+
15+
GetOptions(
16+
'c|config=s' => \$config,
17+
'l|server-list=s' => \$server_list,
18+
);
19+
20+
die 'config not found' unless $config;
21+
die 'server_list not found' unless $server_list;
22+
23+
my $radar = CloudForecast::Radar->new({
24+
root_dir => $root_dir,
25+
global_config => $config,
26+
server_list => $server_list,
27+
});
28+
$radar->run;
29+
30+
31+
32+
33+

cloudforecast_sample.yaml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
config:
3+
gearman_enable: 1
4+
gearman_server:
5+
host: localhost
6+
port: 7004
7+
data_dir: data
8+
host_config_dir: host_config
9+
10+
component_config:
11+
SNMP:
12+
community: public
13+
version: 2
14+
MySQL:
15+
user: root
16+
password: ""
17+

cloudforecast_web

+173
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
#!/usr/bin/perl
2+
3+
use FindBin;
4+
use lib "$FindBin::Bin/lib";
5+
use lib "$FindBin::Bin/site-lib";
6+
use CloudForecast::Web -base;
7+
use CloudForecast::ConfigLoader;
8+
use CloudForecast::Host;
9+
use Getopt::Long;
10+
11+
my $root_dir = $FindBin::Bin;
12+
my $config_yaml = $root_dir . '/cloudforecast.yaml';
13+
my $server_list_yaml = $root_dir . '/server_list.yaml';
14+
15+
my @argv = @ARGV;
16+
Getopt::Long::Configure("no_ignore_case", "pass_through");
17+
GetOptions(
18+
'c|config=s' => \$config_yaml,
19+
'l|server-list=s' => \$server_list_yaml,
20+
);
21+
22+
die 'config not found' unless $config_yaml;
23+
die 'server_list not found' unless $server_list_yaml;
24+
25+
my $configloader = CloudForecast::ConfigLoader->new({
26+
root_dir => $root_dir,
27+
global_config => $config_yaml,
28+
server_list => $server_list_yaml,
29+
});
30+
$configloader->load_all();
31+
32+
my $global_config = $configloader->global_config;
33+
my $server_list = $configloader->server_list;
34+
my $all_hosts = $configloader->all_hosts;
35+
36+
my $page_title = $server_list_yaml;
37+
$page_title =~ s!^(.+)/!!;
38+
$page_title =~ s!\.[^.]+$!!;
39+
40+
sub get_host {
41+
my $host = shift;
42+
my $host_instance = CloudForecast::Host->new({
43+
address => $host->{address},
44+
hostname => $host->{hostname},
45+
details => $host->{details},
46+
resources => $host->{resources},
47+
component_config => $host->{component_config},
48+
global_config => $global_config,
49+
});
50+
$host_instance;
51+
}
52+
53+
get '/' => sub {
54+
my $req = shift;
55+
my $p = shift;
56+
return render('index.mt');
57+
};
58+
59+
get '/server' => sub {
60+
my $req = shift;
61+
62+
my $address = $req->param('address');
63+
return [ 404, [], ['Address Not Found'] ] unless $address;
64+
65+
my $host = $all_hosts->{$address};
66+
return [ 404, [], ['Host Not Found'] ] unless $host;
67+
68+
my $host_instance = get_host($host);
69+
my @graph_list = $host_instance->list_graph;
70+
71+
return render('server.mt');
72+
};
73+
74+
get '/graph' => sub {
75+
my $req = shift;
76+
77+
my $address = $req->param('address');
78+
return [ 404, [], ['Address Not Found'] ] unless $address;
79+
my $resource = $req->param('resource');
80+
return [ 404, [], ['Resource Not Found'] ] unless $resource;
81+
my $key = $req->param('key');
82+
return [ 404, [], ['Graph type key Not Found'] ] unless $key;
83+
84+
my $span = $req->param('span') || 'd';
85+
my $host = $all_hosts->{$address};
86+
return [ 404, [], ['Host Not Found'] ] unless $host;
87+
88+
my $host_instance = get_host($host);
89+
my ($img,$err) = $host_instance->draw_graph($resource,$key, $span);
90+
91+
return [ 500, [], ['Internal Server Error', $err] ] unless $img;
92+
return [ 200, ['Content-Type','image/png'], [$img] ];
93+
};
94+
95+
get '/default.css' => sub {
96+
my $req = shift;
97+
return [ 200, ['Content-Type','text/css'], [render('css.mt')] ];
98+
};
99+
100+
101+
run_server(@argv);
102+
103+
__DATA__
104+
@@ index.mt
105+
<html>
106+
<head>
107+
<title>CloudForecast Server List</title>
108+
<link rel="stylesheet" type="text/css" href="/default.css" />
109+
</head>
110+
<body>
111+
<h1 class="title"><?= $page_title ?> </h1>
112+
113+
<ul>
114+
<? my $i=0 ?>
115+
<? for my $server ( @$server_list ) { ?>
116+
<li><a href="#group-<?= $i ?>"><?= $server->{title} ?></a></li>
117+
<? $i++ } ?>
118+
</ul>
119+
120+
<hr>
121+
122+
<ul>
123+
<? my $k=0 ?>
124+
<? for my $server ( @$server_list ) { ?>
125+
<li id="group-<?= $k ?>"><?= $server->{title} ?></li>
126+
<ul>
127+
<? for my $host ( @{$server->{hosts}} ) { ?>
128+
<li><a href="/server?address=<?= $host->{address} ?>"><?= $host->{address} ?></a> <strong><?= $host->{hostname} ?></strong> <span class="details"><?= $host->{details} ?></a></li>
129+
<? } ?>
130+
</ul>
131+
<? $k++ } ?>
132+
</ul>
133+
134+
</body>
135+
</html>
136+
137+
@@ server.mt
138+
<html>
139+
<head>
140+
<title>CloudForecast Server List</title>
141+
<link rel="stylesheet" type="text/css" href="/default.css" />
142+
</head>
143+
<body>
144+
<h1 class="title"><?= $page_title ?> </h1>
145+
<h2><span class="address"><?= $host->{address} ?></span> <strong><?= $host->{hostname} ?></strong> <span class="details"><?= $host->{details} ?></a></h2>
146+
147+
<? for my $resource ( @graph_list ) { ?>
148+
<h4><?= $resource->{resource_class} ?></h4>
149+
<? for my $graph ( @{$resource->{graphs}} ) { ?>
150+
<nobr />
151+
<? for my $term ( qw/d w m y/ ) { ?>
152+
<img src="/graph?span=<?= $term ?>&amp;address=<?= $host->{address} ?>&amp;resource=<?= $resource->{resource} ?>&amp;key=<?= $graph ?>" />
153+
<? } ?>
154+
<br />
155+
<? } ?>
156+
<? } ?>
157+
158+
</body>
159+
</html>
160+
161+
162+
@@ css.mt
163+
164+
a { color: #5555cc;}
165+
a:link { color: #5555cc;}
166+
a:visited { color: #555599;}
167+
a:active { color: #999999; }
168+
a:hover { color: #999999; }
169+
170+
ol, ul{
171+
list-style-position:inside;
172+
}
173+

host_config/basic.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
components_config:
3+
resources:
4+
- traffic:3:eth1
5+
- basic

0 commit comments

Comments
 (0)