Introduction to
 CloudForecast
   Yokohama.pm #6.x


      @kazeburo
•
• @kazeburo
• 2010 5
• 2010 6
• Web
CloudForecast

•

•
• perl        rrdtool         sysadmin
                         (by tokuhirom)
•
•
(1)
(1)


• ping
(1)


• ping
• HTTP,SSH
(1)


• ping
• HTTP,SSH
•            Disk
(2)

•
•
•
    • Nagios
    • monit
(1)
(1)



•
(1)



•
• CPU
(2)
•
•
•
    •   Cacti
    •   munin
    •   Ganglia
    •   CloudForecast
CloudForecast

•

• YAML
•         Web

• Perl!
CPAN
•   Plack + Starlet
•   Gearman
•   Parallel::Prefork
•   DBI DBD::SQLite

•   YAML::Syck
•   Text::Xslate
•   Data::Section::Simple
•   local::lib
• RRDTool RRDs.pm
• SNMP.pm
• Shirahata(WAF)
CloudForecast                  1




                RRD

    Radar                Web

                SQLite
CloudForecast                  1



(1)




                      RRD

          Radar                Web

                      SQLite
CloudForecast                  1



(1)




                      RRD

          Radar                Web

                      SQLite

            (2)
CloudForecast                        1



(1)




                      RRD

          Radar                      Web

                      SQLite

            (2)                (3)
CloudForecast                        1



(1)




                      RRD

          Radar                      Web

                      SQLite

            (2)                (3)
CloudForecast               2



         fetcher
         worker



                   RRD
         update
Radar                       Web
         worker
                   SQLite
CloudForecast                   2

                   Gearman
                   Worker


         fetcher
         worker



                        RRD
         update
Radar                           Web
         worker
                       SQLite
CloudForecast                  2

                  Gearman
                  Worker




                       RRD
         update
Radar                          Web
         worker
                      SQLite
1


# ubuntu
$ sudo apt-get install librrds-perl libsnmp-perl

# CentOS rrdtool   EPEL
$ sudo yum install net-snmp-perl
$ sudo yum install rrdtool-perl
2

$ git clone git://github.com/kazeburo/cloudforecast.git
$ cd cloudforecast
$ cpanm -l extlib --installdeps .
$ ls
Changes                   cloudforecast_web
Makefile.PL               docs
README                    host_config
cf_devstarter             htdocs
cf_fetcher_worker         lib
cf_updater_worker         server_list_sample.yaml
cloudforecast_radar       t
cloudforecast_sample.yaml
#
$ cp cloudforecast_sample.yaml cloudforecast.yaml

#
$ cp server_list_sample.yaml server_list.yaml
(server_list.yaml)

--- #LOCALHOST
servers:
  - config: basic.yaml
    hosts:
      - 127.0.0.1 server1 my great localhost

--- #My Servers
servers:
  - config: basic.yaml
    hosts:
             ....
(server_list.yaml)

--- #LOCALHOST
servers:
  - config: basic.yaml
    hosts:
      - 127.0.0.1 server1 my great localhost

--- #My Servers
servers:
  - config: basic.yaml
    hosts:
             ....
(server_list.yaml)

--- #LOCALHOST
servers:
  - config: basic.yaml
    hosts:
      - 127.0.0.1 server1 my great localhost

--- #My Servers
servers:
  - config: basic.yaml
    hosts:
             ....
(server_list.yaml)

--- #LOCALHOST
servers:
  - config: basic.yaml
    hosts:
      - 127.0.0.1 server1 my great localhost

--- #My Servers
      IP
servers:
  - config: basic.yaml
    hosts:
             ....
(server_list.yaml)

--- #LOCALHOST
servers:
  - config: basic.yaml
    hosts:
      - 127.0.0.1 server1 my great localhost

--- #My Servers
      IP
servers:
  - config: basic.yaml
    hosts:
             ....
(server_list.yaml)

--- #LOCALHOST
servers:
  - config: basic.yaml
    hosts:
      - 127.0.0.1 server1 my great localhost

--- #My Servers
      IP
servers:
  - config: basic.yaml
    hosts:
             ....
(basic.yaml)

---
component_config:
resources:
  - basic
  - traffic:eth0




      basic = eth0   CPU    TCP
(basic.yaml)

---
component_config:
resources:
  - basic
  - traffic:eth0




      basic = eth0   CPU    TCP
(basic.yaml)

---
component_config:
resources:
  - basic
  - traffic:eth0




      basic = eth0   CPU    TCP
•   Basic(CPU       TCP   )

•   Traffic
•   Disk Usage
•   DiskIO Count
•   Apache Status
•   Nginx Status
•   Squid
•   Mysql
•   Innodb
$ perldoc CloudForecast::Data::
$ perldoc CloudForecast::Data::
CloudForecast
  http://blog.nomadscafe.jp/2010/07/cloudforecast-1.html
#
$ ./cloudforecast_radar -c cloudforecast.yaml 
                        -l server_list.yaml

# Web
$ ./cloudforecast_web -p 5000 -c cloudforecast.yaml 
                      -l server_list.yaml
Web   (   )
Web   (   )
http://blog.nomadscafe.jp/2010/07/cloudforecast-2.html
•
•
•
•
•
•
# site-lib
$ mkdir -p site-lib/CloudForecast/Data
Gearman Worker


gearman        worker process


    http://blog.nomadscafe.jp/2010/07/gearman-worker-process.html
% ./gearman-starter.pl --max-prcess 8 -s 127.0.0.1:7004 
   --scoreboard-dir /var/run/worker --port 7005 MyWorker

% telnet localhost 7005
Trying 127.0.0.1...
System: gearman_servers: 127.0.0.1:7004 class: MyWorker
BusyWorkers: 0
IdleWorkers: 8
--
pid       Status Counter Comment
1630           . 0
1631           . 0
1632           . 0
1633           . 0
1634           . 0
1635           . 0
1636           . 0
1637           . 0
% ./gearman-starter.pl --max-prcess 8 -s 127.0.0.1:7004 
   --scoreboard-dir /var/run/worker --port 7005 MyWorker

% telnet localhost 7005
Trying 127.0.0.1...
System: gearman_servers: 127.0.0.1:7004 class: MyWorker
BusyWorkers: 0
IdleWorkers: 8
--
pid       Status Counter Comment
1630           . 0
1631           . 0
1632           . 0
1633           . 0
1634           . 0
1635           . 0
1636           . 0
1637           . 0
•
•
package CloudForecast::Data::Gearmanstarter;

use CloudForecast::Data -base;
use IO::Socket::INET;

=pod
  host_config)
    resources:
      - gearmanstarter[:port]

  eg)
    - gearmanstarter   #         9000
    - gearmanstarter:9005 #      port
=cut
rrds map { [$_,'GAUGE'] } qw/busy idle/;

# rrds ‘key’, ‘TYPE’ or rrds [‘key’,‘TYPE’], []..
•   COUNTER
    •
    •
    •   ) Traffic (   octet )

•   GAUGE
    •
    •
    •   )
(1)



graphs 'status' => 'worker status';

# graphs ‘key1’ => ‘label’;
# graphs ‘key2’ => ‘the great graph’;
(2)
graphs 'status' => 'worker status';
..

__DATA__
@@ status
DEF:my1=<%RRD%>:busy:AVERAGE
DEF:my2=<%RRD%>:idle:AVERAGE
AREA:my1#00C000:Busy
GPRINT:my1:LAST:Cur: %4.1lf
GPRINT:my1:AVERAGE:Ave: %4.1lf
GPRINT:my1:MAX:Max: %4.1lf
GPRINT:my1:MIN:Min: %4.1lfc
STACK:my2#0000C0:Idle
GPRINT:my2:LAST:Cur: %4.1lf
GPRINT:my2:AVERAGE:Ave: %4.1lf
GPRINT:my2:MAX:Max: %4.1lf
GPRINT:my2:MIN:Min: %4.1lfc
(2)
      graphs 'status' => 'worker status';
      ..
key
      __DATA__
      @@ status
      DEF:my1=<%RRD%>:busy:AVERAGE
      DEF:my2=<%RRD%>:idle:AVERAGE
      AREA:my1#00C000:Busy
      GPRINT:my1:LAST:Cur: %4.1lf
      GPRINT:my1:AVERAGE:Ave: %4.1lf
      GPRINT:my1:MAX:Max: %4.1lf
      GPRINT:my1:MIN:Min: %4.1lfc
      STACK:my2#0000C0:Idle
      GPRINT:my2:LAST:Cur: %4.1lf
      GPRINT:my2:AVERAGE:Ave: %4.1lf
      GPRINT:my2:MAX:Max: %4.1lf
      GPRINT:my2:MIN:Min: %4.1lfc
fetcher {
    my $c = shift;
    my $host = $c->address;
    my $port = $c->args->[0] || 9000;
    my $sock = IO::Socket::INET->new(
        PeerAddr => $host,
        PeerPort => $port,
        Proto    => 'tcp',
    );
    my $raw_stats;
    $sock->sysread( $raw_stats, 8192 );
    my ($busy, $idle);
    foreach my $line ( split /[rn]+/, $raw_stats ) {
        if ( $line =~ /^Busy.+: (d+)/ ) {
            $busy = $1;
        }
        if ( $line =~ /^Idle.+: (d+)/ ) {
            $idle = $1;
        }
    }
    return [$busy,$idle];
};
fetcher {
    my $c = shift;
    my $host = $c->address;
    my $port = $c->args->[0] || 9000;
    my $sock = IO::Socket::INET->new(
        PeerAddr => $host,
        PeerPort => $port,
        Proto    => 'tcp',
    );
    my $raw_stats;
    $sock->sysread( $raw_stats, 8192 );
    my ($busy, $idle);
    foreach my $line ( split /[rn]+/, $raw_stats ) {
        if ( $line =~ /^Busy.+: (d+)/ ) {
            $busy = $1;
        }
        if ( $line =~ /^Idle.+: (d+)/ ) {
            $idle = $1;
        }
    }
    return [$busy,$idle];
};
•
IDLE

       BUSY
TODO/Plan


• Web
• RRD   SQLite

•
• CloudForecast   Perl



•
•
Introduction to cloudforecast

Introduction to cloudforecast