]> err.no Git - varnish/commitdiff
A mojor update to the web GUI, unfortunately all done in one go. Nevertheless, here...
authorpetter <petter@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Wed, 18 Feb 2009 15:36:25 +0000 (15:36 +0000)
committerpetter <petter@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Wed, 18 Feb 2009 15:36:25 +0000 (15:36 +0000)
- the GUI now uses a sqlite3 database for storage, so all configuratons are stored
- aggregated statistics for groups
- graphs on demand for raw data
- CSV export of stat data
- 'Restricted mode' to get a web GUI which prevent you from doing changes
- logging of changes performed in the GUI
- generall minor improvements in the GUI

Additional perl module dependencies are Algorithm::Diff and DBD::Sqlite3

A proper documentation will appear on the wiki in a couple of days to describe all that can be done with the web GUI.

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3786 d4fa192b-c00b-0410-8231-f00ffab90ce4

21 files changed:
varnish-tools/webgui/README
varnish-tools/webgui/Varnish/DB.pm [new file with mode: 0644]
varnish-tools/webgui/Varnish/DB_Data.pm [new file with mode: 0644]
varnish-tools/webgui/Varnish/Group.pm [new file with mode: 0644]
varnish-tools/webgui/Varnish/Management.pm
varnish-tools/webgui/Varnish/Node.pm
varnish-tools/webgui/Varnish/NodeManager.pm
varnish-tools/webgui/Varnish/RequestHandler.pm
varnish-tools/webgui/Varnish/Statistics.pm
varnish-tools/webgui/Varnish/Util.pm
varnish-tools/webgui/create_db_data.pl [new file with mode: 0755]
varnish-tools/webgui/css/web.css
varnish-tools/webgui/start.pl
varnish-tools/webgui/templates/configure_parameters.tmpl
varnish-tools/webgui/templates/edit_vcl.tmpl
varnish-tools/webgui/templates/management_console.tmpl
varnish-tools/webgui/templates/master.tmpl
varnish-tools/webgui/templates/node_management.tmpl
varnish-tools/webgui/templates/view_stats.tmpl
varnish-tools/webgui/templates/view_stats_csv.tmpl [new file with mode: 0644]
varnish-tools/webgui/varnish_webgui.sql [new file with mode: 0644]

index f0da2ab20149910166e219586adebd7baeca019a..f5af23888d965e87228950433b8f1720fa9b071a 100644 (file)
@@ -1,28 +1,15 @@
-Web GUI for Varnish, very limited christmas edition
-===================================================
-
-This is a preview of the upcoming web GUI for Varnish, which will be released with version 2.1 It has most of the features intended for the final version, but a number of things are still missing, so it is just inteded to get feedback. The following known things are _not_ implemented
- - saving of state: if the web server goes down, the information is lost.
- - smart data collection: it stores ALL the polled data with the given poll intervlal. It does not truncate data used for the hour, day, week and month graph. So eventually you will go out of memory. 
- - simple configuration: currently, you must edit the start.pl script by hand to set the configuration, and edit Varnish/RequestHandler.pl to add graphs and summary statistics. 
- - security: there is no form for access control or security implemented.
-
-So I wouldn't use it for anything with 'prod' in its name, but as a preview of what is to come. It should be noted that when adding nodes to an existing group, all the parameters and VCL of that node are replaced with the default parameters and VCL of the group. So if you add more nodes to a group, be aware of this.
-
-Any feedback is most welcome, so just post it to varnish-misc@projects.linpro.no.
-
-So what can you actually do with this thing?
-
+Web GUI for Varnish
+===================
 
 Overview
 --------
 
 The web GUI is written in Perl and runs in its own server container, so a web server is not required, only the necessary Perl modules. The GUI consists of five sections: 'View stats', 'Configure parameters', 'Edit VCL', 'Node management' and 'Management console'. As the names might suggest, the GUI let you
 
-- view statistics from the Varnish nodes
-- configure the parameters of the Varnish nodes and clusters
-- edit the VCL for each cluster, which will be shared between all the nodes
-- perform node management, like adding clusters and nodes, get the state of the nodes and backend healths
+- view statistics and graphs from the Varnish nodes
+- configure the parameters of the Varnish nodes and groups
+- edit the VCL for each group, which will be shared between all the nodes, and the standalone nodes
+- perform node management, like adding groups and nodes, get the state of the nodes and backend healths, starting groups and nodes, stopping etc.
 - get access to the management console of each node
 
 Requirements
@@ -34,6 +21,9 @@ The web GUI is written in Perl, and uses some modules that might not be installe
 - HTML::Template (libhtml-template-perl)
 - GD::Graph (libgd-graph-perl) 
 - LWP::UserAgent (libwww-perl)
+- Algorithm::Diff (libalgorithm-diff-perl)
+- DBD::Sqlite3 (libdbd-sqlite3-perl)
+
 
 The name in the paranthesis are the package name on a standard Ubuntu system. The rest of the modules should be pretty standard.
 
@@ -44,12 +34,13 @@ $ /opt/varnish/sbin/varnishd -a :80 -b :8080 -T :9003
 Configuration
 -------------
 
-The configuration is done directly in the Perl code for this very limited christmas edition, but will be more userfriendly in the final version. As this version doesn't save your state, e.g. the nodes and clusters added, I would recommend adding this in the start.pl. The files needing customisation are
+The configuration is done directly in start.pl, which let you set listening port, names of log files and database files etc. It is all well documented in the file.
+
+Before using it, you must create a sqlite3 database. This can be done by issuing
 
-- start.pl: early in the file you'll see '# Configuration starts here', and this is where to set the config. It is all commented, so should be fairly straight forward.
-- Varnish/RequestHandler.pl: this is the main enging of the whole web GUI, including the parts creating the summary stats and graphs. This is well documented in the code, so look at line 380 for adding values to the summary statistics and 826 for adding custom graphs (and removing the dummy 'Missing graph').
+$ sqlite3 varnish.db < varnish_webgui.sql
 
-That is configuration for this version. Remember that when creating and editing VCLs, the information is stored on the node, so if the web server is restarted, the nodes will still have the VCLs (unless they are restarted too, of course).
+Change varnish.db to the name of the file you set in the config file.
 
 Starting it
 -----------
@@ -62,17 +53,17 @@ The GUI
 View stats
 ----------
 
-In 'View stats' you will see statistics gathered from the nodes. The 'Summary statistics' is/will be customisable (see Configuration) and shows the most important statistics. If you want to see all the statistics from the Varnish nodes you turn 'Raw statistics' on. If you want the page to be refreshed automatically in order to follow the graph 'live', you can turn 'Auto refresh' on. The refresh rate is the same as the rate the statistics are collected from the nodes.
+In 'View stats' you will see graphs and statistics gathered from the groups and nodes. The 'Summary statistics' shows the most important statistics, but if you want to see all the statistics from the Varnish nodes you turn 'Raw statistics' on. If you want the page to be refreshed automatically in order to follow the graph 'live', you can turn 'Auto refresh' on. The refresh rate is the same as the rate the statistics are collected from the nodes. If you want to export the raw data as CSV, use the 'Raw data as CSV' link.
 
 Configure parameters
 --------------------
 
-'Configure' parameters let you configure the parameters for a group (cluster) or a single node. For this version, the parameters for the groups are a copy of the parameters of the first node added to the group, so if a group has not been populated, it will not contain any values. Changing a value in a group will change the same value of all the nodes in that group. Changing a value for node only changes that node, naturally. 
+'Configure' parameters let you configure the parameters for a group or a single node. Changing a value in a group will change the same value of all the nodes in that group. Changing a value for node only changes that node, naturally. 
 
 Edit VCL
 --------
 
-'Edit VCL' lets you edit the VCL of the group, and any changes made here will be reflected on all the nodes of the group. You can add, edit, save and discard VCLs as well as making a VCL active. It discards without warning (isn't baby safe yet), so be carefull.
+'Edit VCL' lets you edit the VCL of a group or standalone node, and any changes made here will be reflected on all the nodes of the group. You can add, edit, save and discard VCLs as well as making a VCL active.
 
 A note about the editor: it is a simple text are, with <tab> giving you an indent as expected. If you save a VCL with error, the errors are listed and you can click on the 'Line X Pos Y' information in the error list to jump to that position in the editor.
 
@@ -86,9 +77,7 @@ From 'Node management' you can manage groups and nodes. It will let you add, rem
 
  If a health probe is defined in the VCL, a list of backend healths for the running VCL is shown as well.
 
- Since this version does not let you save the configuration, it is recommended that you add groups and nodes in the stat.pl file as explained in Configuration.
-
- WARNING: as noted earlier, adding nodes to a group will replace that nodes parameter and VCL.
+WARNING: Adding nodes to a group, or changing the group of a node,  will replace that nodes parameter and VCL.
 
 Management console
 ------------------
@@ -96,12 +85,3 @@ Management console
 'Management console' gives you access to the management console of each node. The input field has magical tab completion for the CLI commands and a command history accessable by arrow up/down. In addition to the standard CLI commands, 'cls' can be issued to clear the console.
 
 The color and size of the console can be changed, but this information is unfortunately not stored when switching nodes.
-
-
-Road ahead
-==========
-
-This is a sneak preview of the web GUI for 2.1, and as such is not complete. It is mostly feature complete (minus things mentioned in the start of this file), so any comments on what is working, what is lacking etc. is most appreciated. Please use the varnish-misc@projects.linpro.no mailing list for discussion.
-
-
-Merry christmas!
diff --git a/varnish-tools/webgui/Varnish/DB.pm b/varnish-tools/webgui/Varnish/DB.pm
new file mode 100644 (file)
index 0000000..3f3f1fc
--- /dev/null
@@ -0,0 +1,388 @@
+package Varnish::DB;
+
+use strict;
+use warnings;
+
+use DBI;
+use Varnish::Util;
+use Varnish::Node;
+use Varnish::Group;
+use Varnish::DB_Data;
+
+{
+       my $dbh;
+       my $stat_type_id_from_name_ref;
+       my %stat_field_exist;
+       my %parameter_field;
+       
+       sub handle_error {
+               my ($error, $handler) = @_;
+
+               $dbh->disconnect();
+               $dbh =  DBI->connect("dbi:SQLite:dbname=test.db", '', '', 
+                       { AutoCommit => 0, PrintError => 1, HandleError => \&handle_error } );
+               sleep(1);
+       }
+
+       sub init {
+               my ($self, $db_filename, $username, $password) = @_;
+
+               $dbh =  DBI->connect("dbi:SQLite:dbname=$db_filename", '', '', 
+                       { AutoCommit => 0, PrintError => 1});
+               
+               %parameter_field = %{Varnish::DB_Data::get_parameter_field()};
+               %stat_field_exist = %{Varnish::DB_Data::get_stat_field_exist()};
+       }
+
+
+       sub add_stat {
+               my ($self, $node, $stat_ref, $timestamp) = @_;
+
+               $timestamp ||= time();
+
+               my @field_values; 
+               my $fields = "time, node_id, has_data";
+               my $values = "?, ?, ?";
+               my $has_data;
+               if ($stat_ref) {
+                       $has_data = 1;
+                       my @stat_fields = keys %{$stat_ref};
+                       for my $stat_field (@stat_fields) {
+                               my $db_field = get_db_friendly_name($stat_field);
+                               if ($stat_field_exist{$db_field}) {
+                                       $fields .= ", $db_field";
+                                       $values .= ", ?";
+                                       my $value = $stat_ref->{$stat_field};
+                                       push @field_values, $value;
+                               }
+                               else {
+                                       print STDERR "Field $db_field does not exist in the stat table. Please update schema\n";
+                               }
+                       }
+               }
+               else {
+                       $has_data = 0;
+               }
+               my $sql = "INSERT INTO stat($fields) VALUES($values)";
+               my $sth = $dbh->prepare($sql);
+               $sth->execute($timestamp, $node->get_id(), $has_data, @field_values);
+               $sth->finish();
+               $dbh->commit();
+       }
+
+       sub get_stat_data {
+               my ($self, $unit, $after_timestamp) = @_;
+
+               my $sql;
+               if (ref($unit) eq "Varnish::Node") {
+                       $sql = "SELECT time, has_data";
+                       my @stat_fields = keys %stat_field_exist;
+                       for my $stat_field (@stat_fields) {
+                               $sql .=", $stat_field";
+                       }
+                       $sql .= " FROM stat WHERE node_id = ? AND time > ? ORDER BY time ASC";
+               }
+               else {
+                       $sql = "SELECT time, SUM(has_data) as has_data";
+                       my @stat_fields = keys %stat_field_exist;
+                       for my $stat_field (@stat_fields) {
+                               $sql .=", SUM($stat_field) AS $stat_field";
+                       }
+                       $sql .= " FROM stat WHERE node_id IN (SELECT id FROM node WHERE group_id = ?) AND time >= ? GROUP BY time ORDER BY time ASC";
+               }
+
+               return $dbh->selectall_arrayref($sql, {Slice => {}}, $unit->get_id(), $after_timestamp);
+       }
+
+       sub add_node {
+               my ($self, $node) = @_;
+
+               my $fields = "name, address, port, group_id, management_port";
+               my $sql = "INSERT INTO node($fields) VALUES(?, ?, ?, ?, ?)";
+               $dbh->do($sql, undef,
+                       $node->get_name(),
+                       $node->get_address(),
+                       $node->get_port(),
+                       $node->get_group_id(),
+                       $node->get_management_port());
+               $dbh->commit();
+               
+               $node->set_id($dbh->func('last_insert_rowid'));
+       }
+
+       sub update_node {
+               my ($self, $node) = @_;
+       
+               my $sql = 
+                       "UPDATE node SET name = ?, address = ?, port = ?, group_id = ?, "
+                       . "management_port = ? where id = ?";
+               $dbh->do($sql, undef, $node->get_name, $node->get_address(), $node->get_port(),
+                       $node->get_group_id(), $node->get_management_port(),
+                       $node->get_id());
+               $dbh->commit();
+       }
+
+       sub remove_node {
+               my ($self, $node, $commit) = @_;
+               
+               $commit = 1 if (!defined($commit));
+
+               my $sql = "DELETE FROM node WHERE id = ?";
+               my $sth = $dbh->prepare($sql);
+               $sth->execute($node->get_id());
+
+               $sql = "DELETE FROM parameters WHERE node_id = ?";
+               $sth = $dbh->prepare($sql);
+               $sth->execute($node->get_id());
+       
+               if ($commit) {
+                       $dbh->commit();
+               }
+       }
+
+       sub add_group {
+               my ($self, $group) = @_;
+
+               my $sql = "INSERT INTO node_group(name) VALUES(?)";
+               $dbh->do($sql, undef, $group->get_name());
+               my $id = $dbh->func('last_insert_rowid');
+               $group->set_id($id);
+
+               $sql = "INSERT INTO parameters(group_id) VALUES(?)";
+               $dbh->do($sql, undef, $id);
+               update_parameters($self, $id, \%parameter_field);
+               
+               $dbh->commit();
+       }
+
+       sub update_group {
+               my ($self, $group, $active_vcl) = @_;
+
+               my $sql = "UPDATE node_group SET name = ?, active_vcl = ? WHERE id = ?";
+               $dbh->do($sql, undef, $group->get_name(), $group->get_active_vcl(), $group->get_id());
+               
+               $dbh->commit();
+       }
+
+       sub remove_group {
+               my ($self, $group) = @_;
+
+               my $sql = "DELETE FROM node_group WHERE id = ?";
+               my $sth = $dbh->prepare($sql);
+               $sth->execute($group->get_id());
+
+               $sql = "DELETE FROM parameters WHERE group_id = ?";
+               $sth = $dbh->prepare($sql);
+               $sth->execute($group->get_id());
+
+               # sqlite doesn't support cascading delete, so we must do it
+               $sql = "SELECT id FROM node WHERE group_id = ?";
+               my $nodes_ref = get_nodes($self, { group_id => $group->get_id()});
+               for my $node (@$nodes_ref) {
+                       remove_node($self, $node, 1);
+               }
+
+               $dbh->commit();
+       }
+
+       sub _create_criteria_sql {
+               my ($criteria_ref) = @_;
+
+               my @values;
+               my $sql = "";
+               if ($criteria_ref) {
+                       my @criterias = keys %$criteria_ref;
+                       for my $criteria (@criterias) {
+                               if ($sql eq "") {
+                                       $sql = " WHERE";
+                               }
+                               else {
+                                       $sql .= " AND";
+                               }
+                               my $value = $criteria_ref->{$criteria};
+                               $sql .= " $criteria = ?";
+                               push @values, $value;
+                       }
+               }
+
+               return ($sql, @values);
+       }
+
+       sub get_groups {
+               my ($self, $criteria_ref) = @_;
+
+               my @values;
+               my $sql = "SELECT * FROM node_group"; 
+               if ($criteria_ref) {
+                       my $criteria_sql;
+                       ($criteria_sql, @values) = _create_criteria_sql($criteria_ref);
+                       $sql .= $criteria_sql;
+               }
+               my $group_rows_ref = $dbh->selectall_arrayref($sql, {Slice => {}}, @values);
+               my @groups = map { Varnish::Group->new($_) } @$group_rows_ref;
+
+               return \@groups;
+       }
+
+       sub get_nodes {
+               my ($self, $criteria_ref) = @_;
+               my @values;
+               my $sql = "SELECT * FROM node"; 
+               if ($criteria_ref) {
+                       my $criteria_sql;
+                       ($criteria_sql, @values) = _create_criteria_sql($criteria_ref);
+                       $sql .= $criteria_sql;
+               }
+
+               my $node_rows_ref = $dbh->selectall_arrayref($sql, {Slice => {}}, @values);
+               my @nodes = map { Varnish::Node->new($_) } @$node_rows_ref;
+
+               return \@nodes;
+       }
+
+
+       sub _clean_up_parameters {
+               my ($parameter_ref) = @_;
+
+               # rename 'child_user' and 'child_group' to the proper 'user' and 'group' names
+               $parameter_ref->{'user'} = $parameter_ref->{'child_user'};
+               delete $parameter_ref->{'child_user'};
+               $parameter_ref->{'group'} = $parameter_ref->{'child_group'};
+               delete $parameter_ref->{'child_group'};
+               delete $parameter_ref->{'id'};
+               delete $parameter_ref->{'group_id'};
+               delete $parameter_ref->{'node_id'};
+
+               return $parameter_ref;
+       }
+
+
+       sub get_group_parameters {
+               my ($self, $group) = @_;
+
+               my $sql = "SELECT * FROM parameters WHERE group_id = ?";
+               my $parameters_ref = $dbh->selectrow_hashref($sql, undef, $group->get_id());
+
+               return _clean_up_parameters($parameters_ref);
+       }
+
+
+       sub get_node_parameters {
+               my ($self, $node) = @_;
+
+               my $sql = "SELECT * FROM parameters WHERE node_id = ?";
+               my $parameters_ref = $dbh->selectrow_hashref($sql, undef, $node->get_id());
+
+               # rename 'child_user' and 'child_group' to the proper 'user' and 'group' names
+               $parameters_ref->{'user'} = $parameters_ref->{'child_user'};
+               delete $parameters_ref->{'child_user'};
+               $parameters_ref->{'group'} = $parameters_ref->{'child_group'};
+               delete $parameters_ref->{'child_group'};
+               delete $parameters_ref->{'id'};
+               delete $parameters_ref->{'group_id'};
+               delete $parameters_ref->{'node_id'};
+
+               return _clean_up_parameters($parameters_ref);
+       }
+
+       sub update_parameters {
+               my ($self, $group_id, $parameter_ref) = @_;
+
+               my @parameters = keys %{$parameter_ref};
+               my @values;
+               my $first = 1;
+               my $sql = "UPDATE parameters SET";
+               for my $parameter (@parameters) {
+                       if (!$first) {
+                               $sql .= ", ";
+                       }
+                       else {
+                               $first = 0;
+                       }
+                       if ($parameter eq 'user' || $parameter eq 'group') {
+                               $sql .= " child_$parameter = ?";
+                       }
+                       elsif ($parameter_field{$parameter}) {
+                               $sql .= " $parameter = ?";
+                       }
+                       else {
+                               print STDERR "Field $parameter does not exist in the stat table. Please update schema\n";
+                               next;
+                       }
+                       push @values, $parameter_ref->{$parameter}->{'value'};
+               }
+               $sql .= " WHERE id = ?";
+               $dbh->do($sql, undef, @values, $group_id);
+       }
+
+       sub get_parameter_info {
+               my ($self) = @_;
+
+               return $dbh->selectall_hashref("SELECT * FROM parameter_info", 1);
+       }
+
+       sub get_vcl_infos {
+               my ($self, $group_id) = @_;
+               
+               my $sql = "SELECT name FROM vcl WHERE group_id = ?";
+               my $vcl_infos_ref = $dbh->selectall_arrayref($sql, {Slice => {}}, $group_id);
+               $sql = "SELECT active_vcl FROM node_group WHERE id = ?";
+               my ($active_vcl) = $dbh->selectrow_array($sql, undef, $group_id);
+               if (defined($active_vcl)) {
+                       for my $vcl_info (@$vcl_infos_ref) {
+                               $vcl_info->{'active'} = ($vcl_info->{'name'} eq $active_vcl);
+                       }
+               }
+               
+               return $vcl_infos_ref;
+       }
+
+
+       sub get_vcl {
+               my ($self, $group_id, $name) = @_;
+               
+               my $sql = "SELECT vcl FROM vcl WHERE group_id = ? AND name = ?";
+               my ($vcl) = $dbh->selectrow_array($sql, undef, $group_id, $name);
+
+               return $vcl;
+       }
+
+       sub update_vcl {
+               my ($self, $group_id, $name, $vcl) = @_;
+
+               my $sql = "UPDATE vcl SET vcl = ? WHERE group_id = ? AND name = ?";
+
+               return $dbh->do($sql, undef, $vcl, $group_id, $name);
+       }
+
+       sub discard_vcl {
+               my ($self, $group_id, $name) = @_;
+
+               my $sql = "DELETE FROM vcl WHERE  name = ? and group_id = ?";
+
+               return $dbh->do($sql, undef, $name, $group_id);
+       }
+
+       sub add_vcl {
+               my ($self, $group_id, $name, $vcl) = @_;
+
+               my $sql = "INSERT INTO vcl(group_id, name, vcl) VALUES(?, ?, ?)";
+               $dbh->do($sql, undef, $group_id, $name, $vcl);
+               my $vcl_id = $dbh->func('last_insert_rowid');
+       }
+
+       sub clean_up {
+               my ($self) = @_;
+
+               # 604800 is the number of seconds in a week
+               my $timestamp_limit = time()- 604800;
+               my $sql = "DELETE FROM stat WHERE time < ?";
+               $dbh->do($sql, undef, $timestamp_limit);
+       }
+
+       sub finish {
+               $dbh->disconnect();
+       }
+}
+
+1;
diff --git a/varnish-tools/webgui/Varnish/DB_Data.pm b/varnish-tools/webgui/Varnish/DB_Data.pm
new file mode 100644 (file)
index 0000000..b86786b
--- /dev/null
@@ -0,0 +1,149 @@
+# This file was auto generated Wed Feb 18 15:58:37 2009 by create_db_files.pl
+# DO NOT EDIT BUT RERUN THE SCRIPT!
+package Varnish::DB_Data;
+
+my %parameter_field = (
+'accept_fd_holdoff' => {value => '50'},
+'auto_restart' => {value => 'on'},
+'backend_http11' => {value => 'on'},
+'between_bytes_timeout' => {value => '60.000000'},
+'cache_vbe_conns' => {value => 'off'},
+'cc_command' => {value => '"exec cc -fpic -shared -Wl,-x -o %o %s"'},
+'cli_banner' => {value => 'on'},
+'cli_buffer' => {value => '8192'},
+'cli_timeout' => {value => '5'},
+'client_http11' => {value => 'off'},
+'clock_skew' => {value => '10'},
+'connect_timeout' => {value => '0.400000'},
+'default_grace' => {value => '10'},
+'default_ttl' => {value => '120'},
+'diag_bitmap' => {value => '0x0'},
+'err_ttl' => {value => '0'},
+'esi_syntax' => {value => '0'},
+'fetch_chunksize' => {value => '128'},
+'first_byte_timeout' => {value => '60.000000'},
+'group' => {value => 'nogroup'},
+'listen_address' => {value => ':80'},
+'listen_depth' => {value => '1024'},
+'log_hashstring' => {value => 'off'},
+'log_local_address' => {value => 'off'},
+'lru_interval' => {value => '2'},
+'max_esi_includes' => {value => '5'},
+'max_restarts' => {value => '4'},
+'obj_workspace' => {value => '8192'},
+'overflow_max' => {value => '100'},
+'ping_interval' => {value => '3'},
+'pipe_timeout' => {value => '60'},
+'prefer_ipv6' => {value => 'off'},
+'purge_dups' => {value => 'off'},
+'purge_hash' => {value => 'off'},
+'rush_exponent' => {value => '3'},
+'send_timeout' => {value => '600'},
+'sess_timeout' => {value => '5'},
+'sess_workspace' => {value => '16384'},
+'session_linger' => {value => '0'},
+'shm_reclen' => {value => '255'},
+'shm_workspace' => {value => '8192'},
+'srcaddr_hash' => {value => '1049'},
+'srcaddr_ttl' => {value => '30'},
+'thread_pool_add_delay' => {value => '20'},
+'thread_pool_add_threshold' => {value => '2'},
+'thread_pool_fail_delay' => {value => '200'},
+'thread_pool_max' => {value => '500'},
+'thread_pool_min' => {value => '5'},
+'thread_pool_purge_delay' => {value => '1000'},
+'thread_pool_timeout' => {value => '300'},
+'thread_pools' => {value => '2'},
+'user' => {value => 'nobody'},
+'vcl_trace' => {value => 'off'},
+'waiter' => {value => 'default'},
+);
+my %stat_field_exist = ('session_pipeline' => 1,
+'shm_mtx_contention' => 1,
+'n_overflowed_work_requests' => 1,
+'backend_connections_failures' => 1,
+'n_worker_threads_limited' => 1,
+'sma_outstanding_bytes' => 1,
+'backend_connections_too_many' => 1,
+'shm_cycles_through_buffer' => 1,
+'esi_parse_errors__unlock_' => 1,
+'total_pipe' => 1,
+'n_worker_threads_created' => 1,
+'objects_sent_with_write' => 1,
+'backend_connections_success' => 1,
+'n_dropped_work_requests' => 1,
+'objects_overflowing_workspace' => 1,
+'sms_outstanding_bytes' => 1,
+'client_requests_received' => 1,
+'n_objects_on_deathrow' => 1,
+'n_total_active_purges' => 1,
+'backend_requests_made' => 1,
+'bytes_allocated' => 1,
+'outstanding_allocations' => 1,
+'objects_esi_parsed__unlock_' => 1,
+'n_struct_vbe_conn' => 1,
+'cache_hits_for_pass' => 1,
+'n_lru_saved_objects' => 1,
+'cache_hits' => 1,
+'sma_outstanding_allocations' => 1,
+'total_pass' => 1,
+'backend_connections_reuses' => 1,
+'backend_connections_not_attempted' => 1,
+'shm_flushes_due_to_overflow' => 1,
+'n_duplicate_purges_removed' => 1,
+'n_new_purges_added' => 1,
+'session_closed' => 1,
+'cache_misses' => 1,
+'n_struct_srcaddr' => 1,
+'sms_allocator_requests' => 1,
+'session_herd' => 1,
+'n_worker_threads_not_created' => 1,
+'n_vcl_discarded' => 1,
+'hcb_lookups_without_lock' => 1,
+'n_worker_threads' => 1,
+'n_lru_nuked_objects' => 1,
+'n_queued_work_requests' => 1,
+'total_sessions' => 1,
+'total_header_bytes' => 1,
+'n_objects_tested' => 1,
+'n_active_struct_srcaddr' => 1,
+'bytes_free' => 1,
+'n_vcl_total' => 1,
+'n_backends' => 1,
+'sma_bytes_free' => 1,
+'total_body_bytes' => 1,
+'shm_records' => 1,
+'n_vcl_available' => 1,
+'sma_bytes_allocated' => 1,
+'objects_sent_with_sendfile' => 1,
+'hcb_lookups_with_lock' => 1,
+'n_struct_sess_mem' => 1,
+'client_connections_accepted' => 1,
+'n_struct_bereq' => 1,
+'sms_bytes_freed' => 1,
+'sms_outstanding_allocations' => 1,
+'sms_bytes_allocated' => 1,
+'n_small_free_smf' => 1,
+'n_struct_objecthead' => 1,
+'total_fetch' => 1,
+'sma_allocator_requests' => 1,
+'backend_connections_recycles' => 1,
+'backend_connections_unused' => 1,
+'shm_writes' => 1,
+'n_struct_object' => 1,
+'total_requests' => 1,
+'hcb_inserts' => 1,
+'n_lru_moved_objects' => 1,
+'n_struct_sess' => 1,
+'allocator_requests' => 1,
+'n_regexps_tested_against' => 1,
+'n_expired_objects' => 1,
+'http_header_overflows' => 1,
+'n_struct_smf' => 1,
+'n_old_purges_deleted' => 1,
+'n_large_free_smf' => 1,
+'session_read_ahead' => 1,
+'session_linger' => 1,
+);
+sub get_parameter_field() { return \%parameter_field; }sub get_stat_field_exist() { return \%stat_field_exist; }
+1;
diff --git a/varnish-tools/webgui/Varnish/Group.pm b/varnish-tools/webgui/Varnish/Group.pm
new file mode 100644 (file)
index 0000000..e592dec
--- /dev/null
@@ -0,0 +1,234 @@
+package Varnish::Group;
+
+use strict;
+
+use Varnish::DB;
+use Varnish::Util;
+
+{
+       my %id_of;
+       my %name_of;
+       my %active_vcl_of;
+
+       my $parameter_info_ref;
+       
+       sub new {
+               my ($class, $arg_ref) = @_;
+
+               my $new_object = bless \do{ my $anon_scalar; }, $class;
+
+               $id_of{$new_object} = $arg_ref->{'id'};
+               $name_of{$new_object} = $arg_ref->{'name'};
+               $active_vcl_of{$new_object} = $arg_ref->{'active_vcl'};
+
+               return $new_object;
+       }
+
+       sub get_id {
+               my ($self) = @_;
+
+               return $id_of{$self};
+       }
+
+       sub get_name {
+               my ($self) = @_;
+
+               return $name_of{$self};
+       }
+
+       sub get_active_vcl {
+               my ($self) = @_;
+
+               return $active_vcl_of{$self};
+       }
+
+       sub get_parameters {
+               my ($self) = @_;
+
+               if (!$parameter_info_ref) {
+                       $parameter_info_ref = Varnish::DB->get_parameter_info();
+               }
+               my $parameter_ref = Varnish::DB->get_group_parameters($self);
+               while (my ($parameter, $value) = each(%$parameter_ref)) {
+                       $parameter_ref->{$parameter} = {
+                               value           => $value,
+                               unit            => $parameter_info_ref->{$parameter}->{'unit'},
+                               description     => $parameter_info_ref->{$parameter}->{'description'},
+                       };
+               }
+               
+               return $parameter_ref;
+       }
+
+       sub update_parameters {
+               my ($self, $parameter_ref) = @_;
+               
+               Varnish::DB->update_parameters($id_of{$self}, $parameter_ref);
+       
+               my $nodes_ref = Varnish::NodeManager->get_nodes($self);
+               for my $node (@$nodes_ref) {
+                       $node->update_parameters($parameter_ref);
+               }
+       }
+
+       sub set_id {
+               my ($self, $id) = @_;
+
+               $id_of{$self} = $id;
+       }
+
+       sub set_name {
+               my ($self, $name) = @_;
+
+               $name_of{$self} = $name;
+       }
+
+       sub get_vcl_infos {
+               my ($self) = @_;
+               
+               return Varnish::DB->get_vcl_infos($id_of{$self});
+       }
+
+       sub get_vcl {
+               my ($self, $name) = @_;
+
+               return Varnish::DB->get_vcl($id_of{$self}, $name);
+       }
+
+       sub save_vcl {
+               my ($self, $name, $vcl) = @_;
+       
+               my $vcl_error;
+               my $error = "";
+               my $nodes_ref = Varnish::NodeManager->get_nodes($self);
+               for my $node (@$nodes_ref) {
+                       my $management = $node->get_management();
+                       if ($management) {
+                               if (!$management->set_vcl($name, $vcl)) {
+                                       $vcl_error ||= get_error();
+                               }
+                       }
+                       else {
+                               $error .= "Could not get the management console for " . $node->get_name() . "\n"; 
+                       }
+               }
+               if ($vcl_error) {
+                       $error .= "VCL compilation errors:\n$vcl_error\n";
+               }
+               else {
+                       if (Varnish::DB->update_vcl($id_of{$self}, $name, $vcl) == 0 ) {
+                               Varnish::DB->add_vcl($id_of{$self}, $name, $vcl);
+                       }
+               }
+
+               if ($error) {
+                       return set_error($error);
+               }
+               else {
+                       return no_error();
+               }
+       }
+
+       sub make_vcl_active {
+               my ($self, $name) = @_;
+       
+               my $error = "";
+               my $nodes_ref = Varnish::NodeManager->get_nodes($self);
+               for my $node (@$nodes_ref) {
+                       my $management = $node->get_management();
+                       if ($management) {
+                               if (!$management->make_vcl_active($name)) {
+                                       $error .= get_error();
+                               }
+                       }
+                       else {
+                               $error .= "Could not get the management console for " . $node->get_name() . "\n"; 
+                       }
+               }
+
+               $active_vcl_of{$self} = $name;
+               if (Varnish::DB->update_group($self) == 0 ) {
+                       $error .= "$name is not a valid VCL\n";
+               }
+
+               if ($error) {
+                       return set_error($error);
+               }
+               else {
+                       return no_error();
+               }
+       }
+
+       sub discard_vcl {
+               my ($self, $name) = @_;
+       
+               my $error = "";
+               my $nodes_ref = Varnish::NodeManager->get_nodes($self);
+               for my $node (@$nodes_ref) {
+                       my $management = $node->get_management();
+                       if ($management) {
+                               if (!$management->discard_vcl($name)) {
+                                       $error .= get_error();
+                               }
+                       }
+                       else {
+                               $error .= "Could not get the management console for " . $node->get_name() . "\n"; 
+                       }
+               }
+               if (Varnish::DB->discard_vcl($id_of{$self}, $name) == 0 ) {
+                       $error .= "$name is not a valid VCL\n";
+               }
+
+               if ($error) {
+                       return set_error($error);
+               }
+               else {
+                       return no_error();
+               }
+       }
+
+       sub start {
+               my ($self) = @_;
+
+               my $error = "";
+               my $nodes_ref = Varnish::NodeManager->get_nodes($self);
+               for my $node (@$nodes_ref) {
+                       if (!$node->is_running()) {
+                               if (!$node->start()) {
+                                       $error .= get_error();
+                               }
+                       }
+               }
+               
+               if ($error) {
+                       return set_error($error);
+               }
+               else {
+                       return no_error();
+               }
+       }
+
+       sub stop {
+               my ($self) = @_;
+
+               my $error = "";
+               my $nodes_ref = Varnish::NodeManager->get_nodes($self);
+               for my $node (@$nodes_ref) {
+                       if ($node->is_running()) {
+                               if (!$node->stop()) {
+                                       $error .= get_error();
+                               }
+                       }
+               }
+               
+               if ($error) {
+                       return set_error($error);
+               }
+               else {
+                       return no_error();
+               }
+       }
+
+}
+
+1;
index 1ce373df39a496f23520c6819001be4b306f0e06..7574a4d621c62bbc2654aaff7efa6a2b8e820791 100644 (file)
@@ -4,11 +4,11 @@ use strict;
 use IO::Socket::INET;
 use Exporter;
 use List::Util qw(first);
+use Varnish::Util qw(set_error get_error no_error);
 
 {
        my %hostname_of;
        my %port_of;
-       my %error_of;
        my %socket_of;
 
        sub new {
@@ -18,11 +18,27 @@ use List::Util qw(first);
 
                $hostname_of{$new_object} = $hostname;
                $port_of{$new_object} = $port;
-               $error_of{$new_object} = "";
 
                return $new_object;
        }
 
+       sub _read_cli_response {
+               my ($socket) = @_;
+
+               my ($status_code, $response_size) = <$socket> =~ m/^(\d+) (\d+)/;
+               my $response;
+               my $remaining_bytes = $response_size;
+               while ($remaining_bytes > 0 ) {
+                       my $data;
+                       my $read = read $socket, $data, $remaining_bytes;
+                       $response .= $data;
+                       $remaining_bytes -= $read;
+               }
+               my $eat_newline = <$socket>;
+
+               return ($status_code, $response);
+       }
+
        sub _send_command {
                my ($self, $command) = @_;
 
@@ -33,22 +49,13 @@ use List::Util qw(first);
                                        PeerAddr => $hostname_of{$self}
                                        );
                        return ("666", "Could not connect to node") if (!$socket);
+# skip the banner
+                       _read_cli_response($socket);
                        $socket_of{$self} = $socket;
                }
                my $socket = $socket_of{$self};
-               
                print $socket "$command\n";
-               my ($status_code, $response_size) = <$socket> =~ m/^(\d+) (\d+)/;
-               my $response;
-               my $remaining_bytes = $response_size;
-               while ($remaining_bytes > 0 ) {
-                       my $data;
-                       my $read = read $socket, $data, $remaining_bytes;
-                       $response .= $data;
-                       $remaining_bytes -= $read;
-               }
-               my $eat_newline = <$socket>;
-               return ($status_code, $response);
+               return _read_cli_response($socket);
        }
 
        sub send_command {
@@ -56,8 +63,8 @@ use List::Util qw(first);
        
                my ($status_code, $response) = _send_command($self, $command);
 
-               return no_error($self, $response) if $status_code eq "200";
-               return set_error($self, $response);
+               return no_error($response) if $status_code eq "200";
+               return set_error($response);
        }
 
        sub get_parameters {
@@ -67,17 +74,23 @@ use List::Util qw(first);
                my $current_param;
 
                my ($status_code, $response) = _send_command($self, "param.show -l");
-               return set_error($self, $response) if ($status_code ne "200");
+               return set_error($response) if ($status_code ne "200");
                for my $line (split( '\n', $response)) {
 
-                       if ($line =~ /^(\w+)\s+(\w+) (.*)$/) {
+                       if ($line =~ /^(\w+)\s+(.*?)(?: \[(.*)\])?$/) {
+                               my $value = $2;
+                               my $unit = $3;
+                               $current_param = $1;
+
+                               if ($current_param eq "user" || $current_param eq "group" 
+                                       || $current_param eq "waiter") {
+                                       ($value) = split(/ /, $value);
+                               }
                                my %param_info = (
-                                               value   => $2,
-                                               unit    => $3
+                                               value   => $value,
+                                               unit    => $unit
                                                );
-
-                               $current_param = $1;
-                               $param{$1} = \%param_info;
+                               $param{$current_param} = \%param_info;
                        }
                        elsif ($line =~ /^\s+(.+)$/) {
 # The first comment line contains no . and describes the default value.
@@ -98,8 +111,8 @@ use List::Util qw(first);
 
                my ($status_code, $response) = _send_command($self, "param.show $parameter");
 
-               return no_error($self, $1) if ($response =~ /^(?:\w+)\s+(\w+)/);
-               return set_error($self, $response);
+               return no_error($1) if ($response =~ /^(?:\w+)\s+(\w+)/);
+               return set_error($response);
        }
 
        sub set_parameter {
@@ -108,29 +121,27 @@ use List::Util qw(first);
                my ($status_code, $response) = _send_command($self, "param.set $parameter $value");
 
                return no_error($self) if ($status_code eq "200");
-               return set_error($self, $response);
+               return set_error($response);
        }
 
-       sub get_vcl_names {
+       sub get_vcl_infos {
                my ($self) = @_;
 
                my ($status_code, $response) = _send_command($self, "vcl.list");
-               return set_error($self, $response) if ($status_code ne "200");
+               return set_error($response) if ($status_code ne "200");
 
-               my @vcl_infos = ($response =~ /^(\w+)\s+\d+\s+(\w+)$/gm);
+               my @vcl_infos = ($response =~ /^(\w+)\s+(?:\d+|N\/A)\s+(\w+)$/gm);
                my $vcl_names_ref = [];
-               my $active_vcl_name = "";
                while (my ($status, $name) = splice @vcl_infos, 0, 2) {
                        next if ($status eq "discarded");
-
-                       if ($status eq "active") {
-                               $active_vcl_name = $name;
-                       }
-                       push @$vcl_names_ref, $name;
+                       
+                       push @$vcl_names_ref, {
+                               name    =>      $name,
+                               active  =>      $status eq "active",
+                       };
                }
 
-               unshift @$vcl_names_ref, $active_vcl_name;
-               return no_error($self, $vcl_names_ref) if ($status_code eq "200");
+               return no_error($vcl_names_ref) if ($status_code eq "200");
        }
        
        sub get_vcl {
@@ -138,8 +149,8 @@ use List::Util qw(first);
 
                my ($status_code, $response) = _send_command($self, "vcl.show $vcl_name");
 
-               return no_error($self, $response) if ($status_code eq "200");
-               return set_error($self, $response);
+               return no_error($response) if ($status_code eq "200");
+               return set_error($response);
        }
 
        sub set_vcl {
@@ -149,37 +160,36 @@ use List::Util qw(first);
                $vcl =~ s/\n/\\n/g;
 
                my $need_restart = 0;
-               my ($active_vcl_name, @vcl_names) = @{get_vcl_names($self)};
-               my $editing_active_vcl = $vcl_name eq $active_vcl_name;
+               my $vcl_info = first { $_->{'name'} eq $vcl_name } @{get_vcl_infos($self)};
 
                # try to compile the new vcl
                my ($status_code, $response) = _send_command($self, "vcl.inline _new_vcl \"$vcl\"");
                if ($status_code ne "200") {
                        _send_command($self, "vcl.discard _new_vcl");
-                       return set_error($self, $response);
+                       return set_error($response);
                }
 
-               if ($editing_active_vcl) {
+               if ($vcl_info && $vcl_info->{'active'}) {
                        ($status_code, $response) = _send_command($self, "vcl.use _new_vcl");
                }
 
-               if (grep { $_ eq $vcl_name } @vcl_names) {
+               if ($vcl_info) {
                        ($status_code, $response) = _send_command($self, "vcl.discard $vcl_name");
                        if ($status_code ne "200") {
                                _send_command($self, "vcl.use $vcl_name");
                                _send_command($self, "vcl.discard _new_vcl");
-                               return set_error($self, $response);
+                               return set_error($response);
                        }
                }
                ($status_code, $response) = _send_command($self, "vcl.inline $vcl_name \"$vcl\"");
 
-               if ($editing_active_vcl) {
+               if ($vcl_info && $vcl_info->{'active'}) {
                        ($status_code, $response) = _send_command($self, "vcl.use $vcl_name");
                }
                _send_command($self, "vcl.discard _new_vcl");
 
                return no_error($self) if ($status_code eq "200");
-               return set_error($self, $response);
+               return set_error($response);
        }
 
        sub discard_vcl {
@@ -188,7 +198,7 @@ use List::Util qw(first);
                my ($status_code, $response) = _send_command($self, "vcl.discard $vcl_name");
 
                return no_error($self) if ($status_code eq "200");
-               return set_error($self, $response);
+               return set_error($response);
        }
 
        sub make_vcl_active {
@@ -197,7 +207,7 @@ use List::Util qw(first);
                my ($status_code, $response) = _send_command($self, "vcl.use $vcl_name");
 
                return no_error($self) if ($status_code eq "200");
-               return set_error($self, $response);
+               return set_error($response);
        }
 
        sub get_stats {
@@ -209,9 +219,8 @@ use List::Util qw(first);
                                                                /^\s*(\d+)\s+(.*?)$/;
                                                                $2 => $1
                                                        } split /\n/, $response;
-
-               return no_error($self, \%stat_counter) if ($status_code eq "200");
-               return set_error($self, $response);
+               return no_error(\%stat_counter) if ($status_code eq "200");
+               return set_error($response);
        }
 
        sub ping {
@@ -220,7 +229,7 @@ use List::Util qw(first);
                my ($status_code, $response) = _send_command($self, "stats");
 
                return no_error($self) if ($status_code eq "200");
-               return set_error($self, $response);
+               return set_error($response);
        }
 
        sub start {
@@ -229,7 +238,7 @@ use List::Util qw(first);
                my ($status_code, $response) = _send_command($self, "start");
 
                return no_error($self) if ($status_code eq "200");
-               return set_error($self, $response);
+               return set_error($response);
        }
 
        sub stop {
@@ -238,29 +247,7 @@ use List::Util qw(first);
                my ($status_code, $response) = _send_command($self, "stop");
 
                return no_error($self) if ($status_code eq "200");
-               return set_error($self, $response);
-       }
-
-       sub set_error {
-               my ($self, $error) = @_;
-
-               $error_of{$self} = $error;
-
-               return;
-       }
-
-       sub get_error {
-               my ($self) = @_;
-
-               return $error_of{$self};
-       }
-
-       sub no_error {
-               my ($self, $return_value) = @_;
-
-               $error_of{$self} = "";
-
-               return defined($return_value) ? $return_value : 1;
+               return set_error($response);
        }
 
        sub close {
@@ -275,11 +262,11 @@ use List::Util qw(first);
                my ($self) = @_;
 
                my ($status_code, $response) = _send_command($self, "debug.health");
-               return set_error($self, $response) if ($status_code ne "200");
+               return set_error($response) if ($status_code ne "200");
                
                my %backend_health = ($response =~ /^Backend (\w+) is (\w+)$/gm);
 
-               return no_error($self, \%backend_health);
+               return no_error(\%backend_health);
        }
 }
 
index b42160d31cf6d556911e009ecae190ffbafc998c..6109e6f2d2114b85bbbcb606366a96d356b76f92 100644 (file)
@@ -3,41 +3,53 @@ package Varnish::Node;
 use strict;
 use LWP::UserAgent;
 use Varnish::Management;
+use Varnish::Util;
+use Varnish::DB;
 
 {
        my %name_of;
        my %address_of;
        my %port_of;
-       my %group_of;
+       my %group_id_of;
        my %management_of;
        my %management_port_of;
-       my %is_master_of;
-       my %node_id_of;
-
-       my $next_node_id = 1;
+       my %id_of;
 
        sub new {
                my ($class, $arg_ref) = @_;
 
                my $new_object = bless \do{ my $anon_scalar; }, $class;
 
+               $id_of{$new_object} = $arg_ref->{'id'};
                $name_of{$new_object} = $arg_ref->{'name'};
                $address_of{$new_object} = $arg_ref->{'address'};
                $port_of{$new_object} = $arg_ref->{'port'};
-               $group_of{$new_object} = $arg_ref->{'group'};
+
+               if ($arg_ref->{'group_id'}) {
+                       $group_id_of{$new_object} = $arg_ref->{'group_id'};
+               }
+               elsif ($arg_ref->{'group'}) {
+                       $group_id_of{$new_object} = Varnish::DB->get_group_id($arg_ref->{'group'});
+               }
+               else {
+                       $group_id_of{$new_object} = 0;
+               }
                $management_port_of{$new_object} = $arg_ref->{'management_port'};
                $management_of{$new_object} = Varnish::Management->new($arg_ref->{'address'}, 
                                                                                                                           $arg_ref->{'management_port'});
-               $is_master_of{$new_object} = 0;
-               $node_id_of{$new_object} = $next_node_id++;
-
                return $new_object;
        }
 
+       sub DESTROY {
+               my ($self) = @_;
+
+               $management_of{$self}->close();
+       }
+
        sub get_id {
                my ($self) = @_;
 
-               return $node_id_of{$self};
+               return $id_of{$self};
        }
 
        sub get_name {
@@ -46,11 +58,23 @@ use Varnish::Management;
                return $name_of{$self};
        }
 
+       sub set_name {
+               my ($self, $name) = @_;
+
+               $name_of{$self} = $name;
+       }
+
        sub get_address {
                my ($self) = @_;
 
                return $address_of{$self};
        }
+       
+       sub set_address {
+               my ($self, $address) = @_;
+
+               $address_of{$self} = $address;
+       }
 
        sub get_port {
                my ($self) = @_;
@@ -58,10 +82,22 @@ use Varnish::Management;
                return $port_of{$self};
        }
 
-       sub get_group {
+       sub set_port {
+               my ($self, $port) = @_;
+
+               $port_of{$self} = $port;
+       }
+
+       sub get_group_id {
                my ($self) = @_;
 
-               return $group_of{$self};
+               return $group_id_of{$self};
+       }
+
+       sub set_group_id {
+               my ($self, $group_id) = @_;
+
+               $group_id_of{$self} = $group_id;
        }
 
        sub get_management {
@@ -76,16 +112,16 @@ use Varnish::Management;
                return $management_port_of{$self};
        }
 
-       sub is_master {
-               my ($self) = @_;
+       sub set_management_port {
+               my ($self, $management_port) = @_;
 
-               return $is_master_of{$self};
+               $management_port_of{$self} = $management_port;
        }
 
-       sub set_master {
-               my ($self, $master) = @_;
+       sub set_id {
+               my ($self, $id) = @_;
 
-               $is_master_of{$self} = $master;
+               $id_of{$self} = $id;
        }
 
        sub is_running_ok {
@@ -123,6 +159,95 @@ use Varnish::Management;
                        return 0;
                }
        }
+
+       sub get_parameters {
+               my ($self) = @_;
+
+               return get_management($self)->get_parameters();
+       }
+
+       sub update_parameters {
+               my ($self, $parameter_ref) = @_;
+               
+               my @parameters = keys %$parameter_ref;
+               my $management = get_management($self);
+               for my $parameter (@parameters) {
+                       $management->set_parameter($parameter, $parameter_ref->{$parameter}->{'value'});
+#                      $management->set_parameter($parameter, $parameter_ref->{$parameter});
+               }
+       }
+
+       sub start {
+               my ($self) = @_;
+
+               my $management = get_management($self);
+               if ($management->start()) {
+                       return no_error();
+               }
+               else {
+                       return set_error(get_error());
+               }
+       }
+
+       sub stop {
+               my ($self) = @_;
+
+               my $management = get_management($self);
+               if ($management->stop()) {
+                       return no_error();
+               }
+               else {
+                       return set_error(get_error());
+               }
+       }
+
+       sub get_backend_health {
+               my ($self) = @_;
+               
+               my $management = get_management($self);
+               
+               return $management->get_backend_health();
+       }
+
+       sub get_vcl_infos {
+               my ($self) = @_;
+
+               my $management = get_management($self);
+               
+               return $management->get_vcl_infos();
+       }
+
+       sub get_vcl {
+               my ($self, $name) = @_;
+
+               my $management = get_management($self);
+               
+               return $management->get_vcl($name);
+       }
+
+       sub save_vcl {
+               my ($self, $name, $vcl) = @_;
+
+               my $management = get_management($self);
+               
+               return $management->set_vcl($name, $vcl);
+       }
+
+       sub make_vcl_active {
+               my ($self, $name) = @_;
+
+               my $management = get_management($self);
+               
+               return $management->make_vcl_active($name);
+       }
+
+       sub discard_vcl {
+               my ($self, $name) = @_;
+
+               my $management = get_management($self);
+               
+               return $management->discard_vcl($name);
+       }
 }
 
 1;
index 4878f82dd9e47381b514633cd75a5bfe07da7dba..1bd315bcdc31f0f6ef32fbe24dd4ba15e98c3ea6 100644 (file)
@@ -2,220 +2,155 @@ package Varnish::NodeManager;
 use strict;
 use warnings;
 use Varnish::Node;
+use Varnish::Group;
+use Varnish::Util qw(set_error no_error get_error);
 use List::Util qw(first);
 
 {
-       my @groups = ();
-       my @nodes = ();
-       my %group_parameters = ();
-
        my $error = "";
 
-       sub add_node {
-               my ($self, $node) = @_;
+       sub _clone_unit {
+               my ($master, $slave) = @_;
 
-               my $group = $node->get_group();
-               if (! grep { $_->get_group eq $group } @nodes ) {
-                       $node->set_master(1);
-                       my %node_parameters = %{$node->get_management()->get_parameters()};
-                       while (my ($parameter, $value) = each %node_parameters) {
-                               $group_parameters{$group}->{$parameter} = $value;
-                       }
+               my $parameter_ref = $master->get_parameters();
+               $slave->update_parameters($parameter_ref);
+       
+               my $master_vcl_infos_ref = $master->get_vcl_infos();
+               for my $vcl_info (@$master_vcl_infos_ref) {
+                       my $name = $vcl_info->{'name'};
+                       $vcl_info->{'vcl'} = $master->get_vcl($name);
                }
-               else {
-# inherit the VCL and the parameters of the group
-                       my %group_parameters = %{$group_parameters{$group}};
-                       my $management = $node->get_management();
-                       while (my ($parameter, $value) = each %group_parameters) {
-                               $management->set_parameter($parameter, $value->{'value'});
-                       }
 
-                       my $vcl_names_ref = $management->get_vcl_names();
-                       my $active_vcl_name;
-                       my @vcl_names;
-                       if ($vcl_names_ref) {
-                               @vcl_names = @{$vcl_names_ref};
-                               $active_vcl_name = shift @vcl_names;
+               my $previous_active_vcl;
+               my $vcl_infos_ref = $slave->get_vcl_infos();
+               for my $vcl_info (@$vcl_infos_ref) {
+                       my $name = $vcl_info->{'name'};
+                       if ($vcl_info->{'active'}) {
+                               $previous_active_vcl = $name;
+                       }
+                       else {
+                               $slave->discard_vcl($name);
                        }
+               }
 
-                       for my $vcl_name (@vcl_names) {
-                               if ($vcl_name ne $active_vcl_name) {
-                                       $management->discard_vcl($vcl_name);
+               for my $vcl_info (@$master_vcl_infos_ref) {
+                       my $name = $vcl_info->{'name'};
+                       my $vcl = $vcl_info->{'vcl'};
+                       $slave->save_vcl($name, $vcl);
+                       if ($vcl_info->{'active'}) {
+                               $slave->make_vcl_active($name);
+                               if ($previous_active_vcl) {
+                                       $slave->discard_vcl($previous_active_vcl);
                                }
                        }
-               
-                       my $discard_active_vcl = 1;
-                       my $group_master = first {
-                                                                       $_->get_group() eq $group
-                                                                       && $_->is_master()
-                                                               } @nodes;
-                       my $master_management = $group_master->get_management();
-                       my $master_active_vcl_name;
-                       my @master_vcl_names;
-                       my $master_vcl_names_ref = $group_master->get_management()->get_vcl_names();
-                       if ($master_vcl_names_ref) {
-                               @master_vcl_names = @{$master_vcl_names_ref};
-                               $master_active_vcl_name = shift @master_vcl_names;
-                       }
+               }
+       }
 
-                       for my $vcl_name (@master_vcl_names) {
-                               my $vcl = $master_management->get_vcl($vcl_name); 
-                               $management->set_vcl($vcl_name, $vcl);
+       sub add_node {
+               my ($self, $node, $use_as_group_defaults) = @_;
 
-                               if ($vcl_name eq $master_active_vcl_name) {
-                                       $management->make_vcl_active($vcl_name);
-                               }
-                               if ($vcl_name eq $active_vcl_name) {
-                                       $discard_active_vcl = 0;
-                               }
-                       }
+               my $management = $node->get_management();
+               if (!$management->ping()) {
+                       return set_error($self, "Could not connect to management port: "
+                                                                       . get_error());
+               }
+               Varnish::DB->add_node($node);
 
-                       if ($discard_active_vcl) {
-                               $management->discard_vcl($active_vcl_name);
+               my $group_id = $node->get_group_id();
+               if ($group_id > 0) {
+                       my $group = get_group($self, $group_id);
+                       if ($use_as_group_defaults) {
+                               _clone_unit($node, $group);
+                       }
+                       else {
+                               _clone_unit($group, $node);
                        }
                }
 
-               push @nodes, $node;
+               return no_error();
        }
 
        sub remove_node {
                my ($self, $node) = @_;
 
-               if ($node) {
-                       @nodes = grep { $_ != $node } @nodes;
-
-                       if ($node->is_master()) {
-                               my $new_master = first {
-                                                                       $_->is_master
-                                                                       && $_->get_group() eq $node->get_group()
-                                                                } @nodes;
-                               if ($new_master) {
-                                       $new_master->set_master(1);
-                               }
-                       }
-               }
+               Varnish::DB->remove_node($node);
        }
 
        sub get_node {
                my ($self, $node_id) = @_;
                
-               my $node = first {
-                                               $_->get_id() == $node_id
-                                       } @nodes;
+               my ($node) = @{Varnish::DB->get_nodes({id => $node_id})};
 
                return $node;
        }
 
        sub add_group {
-               my ($self, $name) = @_;
+               my ($self, $group) = @_;
 
-               push @groups, $name;
+               Varnish::DB->add_group($group);
        }
 
        sub remove_group {
-               my ($self, $name) = @_;
-
-               @groups = grep { $_ ne $name } @groups;
-               my @nodes_to_remove = grep { $_->get_group() eq $name } @nodes;
-               for my $node (@nodes_to_remove) {
-                       remove_node($self, $node);
-               }
-       }
-
-       sub get_groups {
-
-               return @groups;
-       }
-
-       sub get_nodes {
-
-               return @nodes;
-       }
-
-       sub get_nodes_for_group {
                my ($self, $group) = @_;
 
-               return grep { $_->get_group() eq $group } @nodes;
+               Varnish::DB->remove_group($group);
        }
 
-       sub get_group_masters {
-               my ($self) = @_;
+       sub get_group {
+               my ($self, $group_id) = @_;
+               
+               my ($group) = @{Varnish::DB->get_groups({id => $group_id})};
 
-               return grep { $_->is_master() } @nodes;
+               return $group;
        }
 
-       sub load {
 
+       sub get_groups {
 
+               return Varnish::DB->get_groups();
        }
 
-       sub save {
-               my ($self) = @_;
-
+       sub get_nodes {
+               my ($self, $group) = @_;
+               
+               if (defined($group)) {
+                       return Varnish::DB->get_nodes({group_id => $group->get_id()});
+               }
+               else {
+                       return Varnish::DB->get_nodes();
+               }
        }
 
-       sub quit {
-               my ($self) = @_;
-
-               for my $node (@nodes) {
-                       my $management = $node->get_management();
-                       if ($management) {
-                               $management->close();
+       sub get_group_name {
+               my ($self, $group_id) = @_;
+       
+               if ($group_id > 0) {
+                       my $group = get_group($self, $group_id);
+                       if ($group) {
+                               return $group->get_name();
                        }
                }
-               
-               save($self);
-       }
-
-       sub set_error {
-               my ($self, $new_error) = @_;
-
-               $error = $new_error;
-
-               return;
-       }
-
-       sub get_error {
-               my ($self) = @_;
-
-               return $error;
-       }
-
-       sub no_error {
-               my ($self, $return_value) = @_;
-
-               $error = "";
-
-               return defined($return_value) ? $return_value : 1;
+               return '';
        }
 
-       sub set_group_parameter {
-               my ($self, $group, $parameter, $value) = @_;
-
-               my $error;
-
-               $group_parameters{$group}->{$parameter}->{'value'} = $value;
-               my @nodes_in_group = grep { $_->get_group() eq $group } @nodes;
-               for my $node (@nodes_in_group) {
-                       my $management = $node->get_management();
-                       if (!$management->set_parameter($parameter, $value)) {
-                               $error .= $management->get_error() . "\n";
-                       }
-               }
+       sub update_node {
+               my ($self, $node) = @_;
 
-               if ($error) {
-                       return set_error($self, $error);
-               }
-               else {
-                       return no_error();
+               my $current = get_node($self, $node->get_id());
+               if ($current->get_group_id() != $node->get_group_id()
+                       && $node->get_group_id() > 0) {
+                       my $group = get_group($self, $node->get_group_id());
+                       _clone_unit($group, $node);
                }
+               Varnish::DB->update_node($node);
        }
 
-       sub get_group_parameters {
+       sub update_group {
                my ($self, $group) = @_;
 
-               return $group_parameters{$group};
+               Varnish::DB->update_group($group);
        }
+
 }
 
 1;
index 3730d8cdf9bf10e9661c0f06f3d468a0f4bb0b5f..2139526436ac6ca2fc88ad4ffbed482a360ba8b6 100644 (file)
@@ -9,8 +9,8 @@ use Varnish::Management;
 use Varnish::NodeManager;
 use Varnish::Node;
 use Varnish::Statistics;
-use URI::Escape;
 use GD::Graph::lines;
+use GD qw(gdTinyFont);
 use POSIX qw(strftime);
 use List::Util qw(first);
 use Socket;
@@ -34,6 +34,7 @@ use Socket;
                my $server_hostname = gethostbyaddr(inet_aton($server_ip), AF_INET);
                $master_tmpl_var_of{$new_object}->{'server_host'} = $server_hostname;
                $master_tmpl_var_of{$new_object}->{'server_port'} = $connection->sockport();
+               $master_tmpl_var_of{$new_object}->{'restricted'} = get_config_value('restricted');
 
                return $new_object;
        }
@@ -63,8 +64,7 @@ use Socket;
                my %parameter = ();
                for my $pair (split /&/,$$content_ref) {
                        my ($key,$value) = split /=/,$pair;     
-                       $value = uri_unescape($value);
-                       $value =~ s/\+/ /g;
+                       $value = url_decode($value);
                        $parameter{$key} = $value;
                }
 
@@ -87,14 +87,18 @@ use Socket;
                my $content_template;
                my $response_content;
                my %request_parameter = _parse_request_parameters(\$content);
-
-#              while (my ($k, $v) = each %request_parameter) {
-#                      print "$k => $v\n";
-#              }
                
+               if (0) {
+                       while (my ($k, $v) = each %request_parameter) {
+                               print "$k => $v\n";
+                       }
+                       print "\n\n";
+               }
+
                my $param;
+               my $use_master_template;
                if ($operation eq 'view_stats' || $operation eq '') {
-                       ($content_template, $param) = view_stats(\%request_parameter);
+                       ($content_template, $param, $use_master_template) = view_stats(\%request_parameter);
                }
                elsif ($operation eq 'configure_parameters') {
                        ($content_template, $param) = configure_parameters(\%request_parameter);
@@ -125,22 +129,43 @@ use Socket;
                else {
                        return;
                }
+
+               $response_header_ref_of{$self}->{'Connection'} = "Close";
+               $use_master_template = 
+                       defined($use_master_template) ? $use_master_template : 1;
                
                if ($content_template) {
-                       my $template_text = read_file("templates/master.tmpl");
-                       $template_text =~ s/CONTENT_TEMPLATE/$content_template/;
-
-                       my $template = HTML::Template->new_scalar_ref(  \$template_text,
-                                       die_on_bad_params => 0);
+                       my %template_options = 
+                               (die_on_bad_params => 0, global_vars => 1, loop_context_vars => 1);
+                       if ($use_master_template) {
+                               my $template_text = read_file("templates/master.tmpl");
+                               $template_text =~ s/CONTENT_TEMPLATE/$content_template/;
+
+                               my $template = HTML::Template->new_scalar_ref(  \$template_text,
+                                               %template_options);
+
+                               my $tmpl_var = $master_tmpl_var_of{$self};
+                               if ($param) {
+                                       while (my ($parameter, $value) = each %{$param}) {
+                                               $tmpl_var->{$parameter} = $value;
+                                       }
+                               }
+                               $template->param($tmpl_var);
+                               $response_content = $template->output;
+                       }
+                       else {
+                               my $template = HTML::Template->new_file("templates/$content_template",
+                                               %template_options);
 
-                       my $tmpl_var = $master_tmpl_var_of{$self};
-                       if ($param) {
-                               while (my ($parameter, $value) = each %{$param}) {
-                                       $tmpl_var->{$parameter} = $value;
+                               my $tmpl_var = $master_tmpl_var_of{$self};
+                               if ($param) {
+                                       while (my ($parameter, $value) = each %{$param}) {
+                                               $tmpl_var->{$parameter} = $value;
+                                       }
                                }
+                               $template->param($tmpl_var);
+                               $response_content = $template->output;
                        }
-                       $template->param($tmpl_var);
-                       $response_content = $template->output;
                }
                $response_content_ref_of{$self} = \$response_content;
        }
@@ -151,7 +176,8 @@ use Socket;
                my %param = %{$parameter_ref};
                $param{'vcl'} ||= "";
                $param{'operation'} ||= "load";
-               $param{'group_name'} ||= "";
+               $param{'unit_id'} ||= "";
+               $param{'is_node'} ||= "";
                $param{'vcl_name'} ||= "";
                $param{'new_vcl_name'} ||= "";
 
@@ -162,32 +188,29 @@ use Socket;
                $tmpl_var{'vcl_name'} = $param{'vcl_name'};
                $tmpl_var{'status'} = "";
                $tmpl_var{'vcl_infos'} = [];
-               $tmpl_var{'group_infos'} = [];
+               $tmpl_var{'info_infos'} = [];
                $tmpl_var{'vcl_error'} = "";
                $tmpl_var{'vcl'} = "";
                
                my $successfull_save = 0;
                my $editing_new_vcl = 0;
 
-               my @group_masters = Varnish::NodeManager->get_group_masters();
                if ($param{'operation'} eq "make_active") {
-                       my $group_master = first { 
-                               $_->get_group() eq $param{'group_name'};
-                       } @group_masters;
-
-                       if ($group_master) {
-                               my $management = $group_master->get_management();
-                               if ($management->make_vcl_active($param{'vcl_name'})) {
-                                       my @nodes = Varnish::NodeManager->get_nodes();
-                                       for my $node (@nodes) {
-                                               if ($node != $group_master && $node->get_group() eq $param{'group_name'}) {
-                                                       $node->get_management()->make_vcl_active($param{'vcl_name'});
-                                               }
-                                       }
+                       my $unit;
+                       if ($param{'is_node'}) {
+                               $unit = Varnish::NodeManager->get_node($param{'unit_id'});
+                       }
+                       else {
+                               $unit = Varnish::NodeManager->get_group($param{'unit_id'});
+                       }
+                       if ($unit) {
+                               if ($unit->make_vcl_active($param{'vcl_name'})) {
                                        $tmpl_var{'status'} = "VCL activated successfully";
+                                       log_info("[" . $unit->get_name() . "] [Make VCL active] [" . 
+                                                       $param{'vcl_name'} . "]");
                                }
                                else {
-                                       $tmpl_var{'error'} .= "Error activating configuration:\n" . $management->get_error() . "\n";
+                                       $tmpl_var{'error'} .= "Error activating configuration:\n" . get_error() . "\n";
                                }
                        }
                }
@@ -204,35 +227,32 @@ use Socket;
                        }
                }
                elsif ($param{'operation'} eq 'save') {
-                       my $group_master = first { 
-                               $_->get_group() eq $param{'group_name'}
-                       } @group_masters;
-
-                       if ($group_master && $param{'vcl'} ne "" && $param{'vcl_name'} ne "") {
-                               my $master_management = $group_master->get_management();
-                               if ($master_management->set_vcl($param{'vcl_name'}, $param{'vcl'})) {
-                                       my @nodes = Varnish::NodeManager->get_nodes();
-                                       for my $node (@nodes) {
-                                               if ($node != $group_master && $node->get_group() eq $param{'group_name'}) {
-                                                       my $management = $node->get_management();
-                                                       if (!$management->set_vcl($param{'vcl_name'}, $param{'vcl'})) {
-                                                               $tmpl_var{'error'} .= "Error saving configuration for " . $node->get_name()
-                                                                                                       . ":\n" . $management->get_error() . "\n";
-                                                       }
-                                               }
-                                       }
+                       my $unit;
+                       if ($param{'is_node'}) {
+                               $unit= Varnish::NodeManager->get_node($param{'unit_id'});
+                       }
+                       else {
+                               $unit= Varnish::NodeManager->get_group($param{'unit_id'});
+                       }
+                       if ($unit && $param{'vcl'} ne "" && $param{'vcl_name'} ne "") {
+                               my $existing_vcl = $unit->get_vcl($param{'vcl_name'});
+                               if ($unit->save_vcl($param{'vcl_name'}, $param{'vcl'})) {
+                                       my $diff = diff($existing_vcl, $param{'vcl'});
                                        $successfull_save = 1;
                                        $tmpl_var{'status'} = "VCL saved successfully";
+                                       log_info("[" . $unit->get_name() . "] [Saved VCL] [" . 
+                                                       $param{'vcl_name'} . "] ["
+                                                       . url_encode($diff) . "]");
                                }
                                else {
+                                       $editing_new_vcl = 1;
+                                       $tmpl_var{'vcl'} = $param{'vcl'};
                                        push @{$tmpl_var{'vcl_infos'}}, {
-                                               name            => $param{'vcl_name'},
+                                               name            => $param{'new_vcl_name'},
                                                selected        => 1,
                                                active          => 0
                                        };
-                                       $editing_new_vcl = 1;
-                                       $tmpl_var{'vcl'} = $param{'vcl'};
-                                       my $vcl_error = $master_management->get_error();
+                                       my $vcl_error = get_error();
                                        # it is bad bad bad mixing presentation and code, I know, but sometimes you have to
                                        $vcl_error =~ s/Line (\d+) Pos (\d+)/<a href="javascript:goToPosition($1,$2)">$&<\/a>/g;
                                        $vcl_error =~ s/\n/<br\/>/g;
@@ -241,96 +261,91 @@ use Socket;
                        }
                }
                elsif ($param{'operation'} eq "discard") {
-                       my ($group_master) = grep { 
-                               $_->get_group() eq $param{'group_name'}
-                       } @group_masters;
-                       if ($group_master && $param{'vcl_name'} ne "") {
-                               my $management = $group_master->get_management();
-                               if ($management->discard_vcl($param{'vcl_name'})) {
-                                       my @nodes = Varnish::NodeManager->get_nodes();
-                                       for my $node (@nodes) {
-                                               if ($node != $group_master && $node->get_group() eq $param{'group_name'}) {
-                                                       $node->get_management()->discard_vcl($param{'vcl_name'});
-                                               }
-                                       }
+                       my $unit;
+                       if ($param{'is_node'}) {
+                               $unit= Varnish::NodeManager->get_node($param{'unit_id'});
+                       }
+                       else {
+                               $unit= Varnish::NodeManager->get_group($param{'unit_id'});
+                       }
+                       if ($unit && $param{'vcl_name'} ne "") {
+                               if ($unit->discard_vcl($param{'vcl_name'})) {
 
                                        $tmpl_var{'vcl_name'} = "";
                                        $tmpl_var{'status'} = "VCL discarded successfully";
+                                       log_info("[" . $unit->get_name() . "] [Discarded VCL] [" . 
+                                                       $param{'vcl_name'} . "]");
                                }
                                else {
-                                       $tmpl_var{'error'} .= "Error discarding configuration:\n" . $management->get_error() . "\n";
+                                       $tmpl_var{'error'} .= "Error discarding configuration:\n" . get_error() . "\n";
                                }
                        }
                }
        
-               my $selected_group_master;
-               for my $group_master (@group_masters) {
-                       my %group_info = (
-                                       name            =>      $group_master->get_group(),
-                                       selected        =>      0,
-                                       );
-                       if ($param{'group_name'} eq $group_master->get_group()) {
-                               $group_info{'selected'} = '1';
-                               $selected_group_master = $group_master;
-                       }
-                       push @{$tmpl_var{'group_infos'}}, \%group_info;
-               }
-               if (!$selected_group_master && @group_masters > 0) {
-                       $selected_group_master = $group_masters[0];
-                       $tmpl_var{'group_infos'}->[0]->{'selected'} = 1;
-               }
-
-               if ($selected_group_master) {
-                       my $active_vcl_name;
-                       my @vcl_names;
-                       my $vcl_names_ref = $selected_group_master->get_management()->get_vcl_names();
-                       if ($vcl_names_ref) {
-                               @vcl_names = @{$vcl_names_ref};
-                               $active_vcl_name = shift @vcl_names;
-                               
-                               for my $vcl_name (@vcl_names) {
-                                       my %vcl_info = (
-                                                       name            =>      $vcl_name,
-                                                       selected        =>      0,
-                                                       active          =>      0,      
-                                                       );
-                                       if ($vcl_name eq $tmpl_var{'vcl_name'}) {
-                                               $vcl_info{'selected'} = 1;
-                                               $tmpl_var{'vcl_name'} = $vcl_name;
-                                       }
-                                       if ($vcl_name eq $active_vcl_name) {
-                                               $vcl_info{'active'} = 1;
+               my $groups_ref = Varnish::NodeManager->get_groups();
+               my $nodes_ref = Varnish::NodeManager->get_nodes(Varnish::NodeManager->get_group(0));
+               my $selected_unit;
+               for my $unit (@$groups_ref, @$nodes_ref) {
+                       my $is_node = ref($unit) eq "Varnish::Node";
+                       next if (!$is_node && $unit->get_id() == 0);
+                       
+                       my $selected = 0;
+                       if (!$selected_unit && 
+                               (!$param{'unit_id'}
+                               || ($is_node && $param{'is_node'} && $param{'unit_id'} == $unit->get_id())
+                               || (!$is_node && !$param{'is_node'} && $param{'unit_id'} == $unit->get_id()))) {
+                               $selected_unit = $unit;
+                               $selected = 1;
+                       }
+                       my %unit_info = (
+                                       id                      =>      $unit->get_id(),
+                                       is_node         =>      $is_node,
+                                       name            =>      $unit->get_name(),
+                                       selected        =>      $selected,
+                       );
+                       push @{$tmpl_var{'unit_infos'}}, \%unit_info;
+               }
+               if ($selected_unit) {
+                       my $vcl_infos_ref = $selected_unit->get_vcl_infos();
+                       if ($vcl_infos_ref) {
+                               push @{$tmpl_var{'vcl_infos'}}, @$vcl_infos_ref;
+                               if ($tmpl_var{'vcl_name'}) {
+                                       for my $vcl_info_ref (@{$tmpl_var{'vcl_infos'}}) {
+                                               if ($vcl_info_ref->{'name'} eq $tmpl_var{'vcl_name'}) {
+                                                       $vcl_info_ref->{'selected'} = 1;
+                                               }
                                        }
-                                       push @{$tmpl_var{'vcl_infos'}}, \%vcl_info;
                                }
-                               if ($tmpl_var{'vcl_name'} eq "") {
-                                       FIND_ACTIVE_VCL:
+                               else {
+                                       my $active_found = 0;
+FIND_ACTIVE_VCL:
                                        for my $vcl_info (@{$tmpl_var{'vcl_infos'}}) {
                                                if ($vcl_info->{'active'}) {
                                                        $tmpl_var{'vcl_name'} = $vcl_info->{'name'};
                                                        $vcl_info->{'selected'} = 1;
+                                                       $active_found = 1;
                                                        last FIND_ACTIVE_VCL;
                                                }
                                        }
-                                       if ($tmpl_var{'vcl_name'} eq "") {
-                                               $tmpl_var{'vcl_name'} = $tmpl_var{'vcl_infos'}->[0]->{'name'};
-                                               $tmpl_var{'vcl_infos'}->[0]->{'selected'} = 1;
-                                       }
-                               }
+                                       if (!$active_found && @{$tmpl_var{'vcl_infos'}} > 0) {
+                                               my $vcl_info = $tmpl_var{'vcl_infos'}->[0]; 
 
-                               if (!(($param{'operation'} eq 'save' && !$successfull_save
-                                               || $param{'operation'} eq 'new'))) {
-                                       my $vcl = $selected_group_master->get_management()->get_vcl($tmpl_var{'vcl_name'});
-                                       if ($vcl) {
-                                               $tmpl_var{'vcl'} = $vcl;
-                                       }
-                                       else {
-                                               $tmpl_var{'error'} .= "Error retrieving VCL: " . $selected_group_master->get_management()->get_error() . "\n";
+                                               $tmpl_var{'vcl_name'} = $vcl_info->{'name'};
+                                               $vcl_info->{'selected'} = 1;
                                        }
                                }
                        }
-                       else {
-                               $tmpl_var{'error'} .= "Error retrieving the VCLs: " . $selected_group_master->get_management()->get_error();
+
+                       if ($tmpl_var{'vcl_name'} &&
+                               !(($param{'operation'} eq 'save' && !$successfull_save
+                                       || $param{'operation'} eq 'new'))) {
+                               my $vcl = $selected_unit->get_vcl($tmpl_var{'vcl_name'});
+                               if ($vcl) {
+                                       $tmpl_var{'vcl'} = $vcl;
+                               }
+                               else {
+                                       $tmpl_var{'error'} .= "Error retrieving VCL: " . get_error() . "\n";
+                               }
                        }
                }
 
@@ -339,7 +354,59 @@ use Socket;
 
                return ($template, \%tmpl_var);
        }
+       
+       sub view_stats_csv{
+               my ($show_group, $csv_delim) = @_;
+               $csv_delim ||= ",";
+
+               my $template = "view_stats_csv.tmpl";
+               my %tmpl_var;   
+               $tmpl_var{'rows'} = [];
+               $tmpl_var{'stat_time'} = '';
+               
+               my @stat_names;
+               my $first_row = 1;
+               my $nodes_ref = [];
+               my $groups_ref = [];
+               if ($show_group > 0) {
+                       my $group = Varnish::NodeManager->get_group($show_group);
+                       push @$groups_ref, $group;
+                       $nodes_ref = Varnish::NodeManager->get_nodes($group);
+               }
+               else {
+                       $groups_ref = Varnish::NodeManager->get_groups();
+                       $nodes_ref = Varnish::NodeManager->get_nodes();
+               }
+               for my $unit (@$groups_ref, @$nodes_ref) {
+                       next if (ref($unit) eq "Varnish::Group" && $unit->get_id() == 0);
+                       my ($stat_time, $stat_ref) = Varnish::Statistics->get_last_measure($unit);
+                       if ($first_row) {
+                               @stat_names = keys(%$stat_ref);
+                               my @column_names = map { {value => $_} } @stat_names;
+                               push @{$tmpl_var{'rows'}}, {
+                                       values  => \@column_names,
+                                       unit    => "name",
+                               };
+                               if ($stat_time) {
+                                       $stat_time = strftime("%a %b %e %H:%M:%S %Y", localtime($stat_time));
+                               }
+                               $first_row = 0;
+                       }
+                       my @values = map { {value => $stat_ref->{$_}} } @stat_names;
+                       push @{$tmpl_var{'rows'}}, {
+                               values  => \@values,
+                               unit    => $unit->get_name(),
+                       };
+               }
+       
+               return ($template, \%tmpl_var, 0);
+       }
 
+       sub _get_stat {
+               my ($name, $stat_ref) = @_;
+
+               return $stat_ref->{get_db_friendly_name($name)};
+       }
 
        sub view_stats {
                my ($parameter_ref) = @_;
@@ -349,77 +416,133 @@ use Socket;
                my %param = %{$parameter_ref};
                $param{'view_raw_stats'} ||= 0;
                $param{'auto_refresh'} ||= 0;
+               $param{'show_group'} ||= 0;
+               $param{'csv'} ||= 0;
+
+               if ($param{'csv'}) {
+                       return view_stats_csv($param{'show_group'});
+               }
 
                my %tmpl_var;
-               $tmpl_var{'error'} = "";
-               $tmpl_var{'stat_time'} = 0;
-               $tmpl_var{'node_infos'} = [];
+               $tmpl_var{'error'} = '';
+               $tmpl_var{'stat_time'} = '';
+               $tmpl_var{'unit_infos'} = [];
                $tmpl_var{'summary_stats'} = [];
                $tmpl_var{'raw_stats'} = [];
                $tmpl_var{'auto_refresh'} = $param{'toggle_auto_refresh'} ? 1 - $param{'auto_refresh'} : $param{'auto_refresh'};
                $tmpl_var{'auto_refresh_interval'} = $tmpl_var{'auto_refresh'} ? get_config_value('poll_interval') : 0;
                $tmpl_var{'view_raw_stats'} = $param{'view_raw_stats'};
+               $tmpl_var{'graph_width'} = get_config_value('graph_width');
+               $tmpl_var{'graph_height'} = get_config_value('graph_height');
+               $tmpl_var{'large_graph_width'} = get_config_value('large_graph_width');
+               $tmpl_var{'large_graph_height'} = get_config_value('large_graph_height');
+               $tmpl_var{'show_group'} = $param{'show_group'};
+               $tmpl_var{'group_name'} = '';
 
                my $error = "";
        
-               my ($stat_time, $stat_ref) = Varnish::Statistics->get_last_measure();
-               my @nodes = Varnish::NodeManager->get_nodes();
-
-               if ($stat_time) {
-                       $stat_time = strftime("%a %b %e %H:%M:%S %Y", localtime($stat_time));
-               }
-
                my %summary_stat_list;
                my %raw_stat_list;
-               for my $node (@nodes) {
-                       push @{$tmpl_var{'node_infos'}}, {
-                               name    => $node->get_name(),
+               my $nodes_ref = [];
+               my $groups_ref = [];
+               if ($tmpl_var{'show_group'} > 0) {
+                       my $group = Varnish::NodeManager->get_group($tmpl_var{'show_group'});
+                       push @$groups_ref, $group;
+                       $tmpl_var{'group_name'} = $group->get_name();
+                       $nodes_ref = Varnish::NodeManager->get_nodes($group);
+               }
+               else {
+                       $groups_ref = Varnish::NodeManager->get_groups();
+                       my $standalone_group = Varnish::NodeManager->get_group(0);
+                       $nodes_ref = Varnish::NodeManager->get_nodes($standalone_group);
+               }
+               for my $unit (@$groups_ref, @$nodes_ref) {
+                       my $unit_id;
+                       my $is_node;
+                       if (ref($unit) eq "Varnish::Node") {
+                               $unit_id = $unit->get_id();
+                               $is_node = 1;
+                       }
+                       else {
+                               $unit_id = $unit->get_id();
+                               $is_node = 0;
+                               next if ($unit_id <= 0);
+                       }
+                       my $time_span = 'minute';
+                       my ($stat_time, $stat_ref) = Varnish::Statistics->get_last_measure($unit);
+
+                       next if (!$stat_ref);
+
+                       my $running;
+                       my $all_running;
+                       if ($is_node) {
+                               $running = $all_running = $unit->is_running_ok();
+                       }
+                       else {
+                               my $nodes_ref = Varnish::NodeManager->get_nodes($unit);
+                               my $running_ok = 0;
+                               for my $node (@$nodes_ref) {
+                                       if ($node->is_running_ok()) {
+                                               $running_ok++;
+                                       }
+                               }
+                               $running = $running_ok > 0;
+                               $all_running = $running_ok == @$nodes_ref;
+                       }
+
+
+                       push @{$tmpl_var{'unit_infos'}}, {
+                               name                    => $unit->get_name(),
+                               unit_id                 => $unit_id,
+                               group_id                => ($is_node ? $unit->get_group_id() : $unit_id),
+                               is_node                 => $is_node,
+                               running                 => $running,
+                               all_running     => $all_running,
                        };
 
-                       my $node_stat_ref = $stat_ref->{$node};
-                       my $node_id = $node->get_id();
-                       my $time_span = 'minute';
+                       if (!$tmpl_var{'stat_time'}) {
+                               $tmpl_var{'stat_time'} = strftime("%a %b %e %H:%M:%S %Y", localtime($stat_time));
+                       }
                        
                        # example of adding graph the graph ID must match that of a predefind graph
                        # which is created in generate_graph found around line 826
+                       push @{$summary_stat_list{'Hit ratio since start'}}, {
+                               is_graph        => 1,
+                               unit_id         => $unit_id,
+                               is_node         => $is_node,
+                               graph_id        => 'cache_hit_ratio_since_start',
+                       };
                        push @{$summary_stat_list{'Hit ratio'}}, {
                                is_graph        => 1,
-                               node_id         => $node_id,
+                               unit_id         => $unit_id,
+                               is_node         => $is_node,
                                graph_id        => 'cache_hit_ratio',
                        };
                        push @{$summary_stat_list{'Connect requests'}}, {
                                is_graph        => 1,
-                               node_id         => $node_id,
+                               unit_id         => $unit_id,
+                               is_node         => $is_node,
                                graph_id        => 'connect_rate',
                        };
 
-                       # example of missing graph_id
-                       push @{$summary_stat_list{'Missing graph'}}, {
-                               is_graph        => 1,
-                               node_id         => $node_id,
-                               graph_id        => 'missing_graph',
-                       };
-
                        # to add custom values, just add values by adding it to the list. The 
                        # get_formatted_bytes() function is usefull for displaying byte values
                        # as it will convert to MB, GB etc as needed.
-                       push @{$summary_stat_list{'% of requests served from cache'}}, {
-                               value   => get_formatted_percentage($$node_stat_ref{'Cache hits'} 
-                                                                                                       , $$node_stat_ref{'Client requests received'})
+                       push @{$summary_stat_list{'Hit ratio since start (%)'}}, {
+                               value   => get_formatted_percentage(_get_stat('Cache hits', $stat_ref) 
+                                                                                                       , _get_stat('Client requests received', $stat_ref))
                        };
 
                        # these are examples of adding plain values from the raw stats
-                       push @{$summary_stat_list{'Client connections accepted'}}, {
-                               value   => $$node_stat_ref{'Client connections accepted'}
-                       };
                        push @{$summary_stat_list{'Client requests received'}}, {
-                               value   => $$node_stat_ref{'Client requests received'}
+                               value   => _get_stat('Client requests received', $stat_ref)
                        };
 
                        my $total_bytes_served;
-                       if ($$node_stat_ref{'Total header bytes'} 
-                               && $$node_stat_ref{'Total body bytes'}) {
-                               $total_bytes_served = $$node_stat_ref{'Total header bytes'} + $$node_stat_ref{'Total header bytes'};
+                       my $total_header_bytes = _get_stat('Total header bytes', $stat_ref);
+                       my $total_body_bytes = _get_stat('Total body bytes', $stat_ref);
+                       if (defined($total_header_bytes) && defined($total_body_bytes)) {
+                               $total_bytes_served = $total_header_bytes + $total_body_bytes;
                        }
                        push @{$summary_stat_list{'Total bytes served'}}, {
                                'value' 
@@ -427,44 +550,40 @@ use Socket;
                        };
 
                        if ($param{'view_raw_stats'}) {
-                               while (my ($stat_name, $value) = each %{$node_stat_ref}) {
+                               while (my ($stat_name, $value) = each %{$stat_ref}) {
                                        push @{$raw_stat_list{$stat_name}}, {
                                                value   => $value,
+                                               unit_id => $unit_id,
+                                               is_node => $is_node,
                                        };
                                }
                        }
                }
 
-               my $row = 1;
-               while (my ($stat_name, $values_ref) = each %raw_stat_list) {
+               my @stat_names = sort(keys(%raw_stat_list));
+               for my $stat_name (@stat_names) {
                        push @{$tmpl_var{'raw_stats'}}, {
                                name    => $stat_name,
-                               values  => $values_ref,
-                               odd_row => $row++ % 2,
+                               values  => $raw_stat_list{$stat_name},
                        }
                }
 
-               $row = 1;
-               my $graph_row = 0;
                while (my ($stat_name, $values_ref) = each %summary_stat_list) {
                        if ($values_ref->[0]->{'is_graph'}) {
                                unshift @{$tmpl_var{'summary_stats'}}, {
                                        name    => $stat_name,
                                        values  => $values_ref,
-                                       odd_row => $graph_row++ % 2,
                                }
                        }
                        else {
                                push @{$tmpl_var{'summary_stats'}}, {
                                        name    => $stat_name,
                                        values  => $values_ref,
-                                       odd_row => $row++ % 2,
                                }
                        }
                }
 
                $tmpl_var{'error'} = $error;
-               $tmpl_var{'stat_time'} = $stat_time;
 
                return ($template, \%tmpl_var);
        }
@@ -473,8 +592,8 @@ use Socket;
                my ($parameter_ref) = @_;
 
                my %param = %{$parameter_ref};
-               $param{'node_id'} = $$parameter_ref{'node_id'} || "";
-               $param{'group'} = $$parameter_ref{'group'} || "";
+               $param{'node_id'} = -1 if (!defined($param{'node_id'}));
+               $param{'group_id'} = -1 if (!defined($param{'group_id'}));
 
                my $template = "configure_parameters.tmpl";
                my %tmpl_var;
@@ -486,60 +605,66 @@ use Socket;
                my $unit_parameter_ref = {};
                my $error = "";
 
-               my %changed_parameters;
+               my %changed_parameter;
                while (my ($parameter, $value) = each %$parameter_ref) {
                        if ($parameter =~ /^new_(.*?)$/ &&
                                        $$parameter_ref{"old_$1"} ne $value) {
-                               $changed_parameters{$1} = $value;
+                               
+                               $changed_parameter{$1}->{'old_value'} = $$parameter_ref{"old_$1"};
+                               $changed_parameter{$1}->{'value'} = $value;
                        }
                }
 
-               my @nodes = Varnish::NodeManager->get_nodes();
-               my @groups = Varnish::NodeManager->get_groups();
-               if (%changed_parameters) {
-                       my $node = first { $_->get_id() eq $param{'node_id'} } @nodes;
+               my $nodes_ref = Varnish::NodeManager->get_nodes();
+               my $groups_ref = Varnish::NodeManager->get_groups();
+               if (%changed_parameter) {
+                       my $unit_name;
+                       my $node = Varnish::NodeManager->get_node($param{'node_id'});
                        if ($node) {
-                               my $management = $node->get_management();
-                               while (my ($parameter, $value) = each %changed_parameters) {
-                                       if (!$management->set_parameter($parameter, $value)) {
-                                               $error .= "Could not set parameter $parameter: ". $node->get_management()->get_error() . "\n";
-                                       }
-                               }
+                               $node->update_parameters(\%changed_parameter);
+                               $unit_name = $node->get_name();
                        }
                        else {
-                               my $group = first { $_ eq $param{'group'} } @groups;
-                               if ($group ne "") {
-                                       while (my ($parameter, $value) = each %changed_parameters) {
-                                               if (!Varnish::NodeManager->set_group_parameter($group, $parameter, $value)) {
-                                                       $error .= "Could not set parameter $parameter for group $group: "
-                                                                       . Varnish::NodeManager->get_error()  . "\n";
-                                               }
-                                       }
+                               my $group = Varnish::NodeManager->get_group($param{'group_id'});
+                               if ($group) {
+                                       $unit_name = $group->get_name();
+                                       $group->update_parameters(\%changed_parameter);
                                }
                        }
                        if ($error eq "") {
-                               my @changed_parameters = keys %changed_parameters;
-                               my $status = "Parameter" . (@changed_parameters > 1 ? "s " : " ");
-
-                               $status .= shift @changed_parameters;
+                               my @changed_parameters = keys %changed_parameter;
+                               my $status;
+                               
                                for my $parameter (@changed_parameters) {
-                                       $status .= ", $parameter";
+                                       my $change;
+                                       
+                                       $change .= $changed_parameter{$parameter}->{'old_value'} . ' => ';
+                                       $change .= $changed_parameter{$parameter}->{'value'};
+                                       if ($status) {
+                                               $status .= ", ";
+                                       }
+                                       $status .= "$parameter ($change)";
+                                       log_info("[$unit_name] [Parameter change] [$parameter] [$change]");
                                }
+                               $status = "Parameter" . (@changed_parameters > 1 ? "s " : " ") . $status;
                                $status .= " configured successfully";
+                               
                                $tmpl_var{'status'} = $status;
                        }
                }
 
-               for my $group (@groups) {
+               for my $group (@$groups_ref) {
+                       next if $group->get_id() == 0;
+
                        my %unit_info = (
-                                       name            =>      $group,
-                                       id                      =>      $group,
+                                       id                      =>      $group->get_id(),
+                                       name            =>      $group->get_name(),
                                        is_node         =>      0,
                                        selected        =>      0, 
                        );
-                       if ($group eq $param{'group'}) {
+                       if ($group->get_id() eq $param{'group_id'}) {
                                $unit_info{'selected'} = 1;
-                               $unit_parameter_ref = Varnish::NodeManager->get_group_parameters($group);
+                               $unit_parameter_ref = $group->get_parameters();
                                if (!$unit_parameter_ref) {
                                        $error .= "Could not get parameters for group $group. You need to have added a node to set these.\n";
                                }
@@ -547,7 +672,7 @@ use Socket;
                        push @{$tmpl_var{'unit_infos'}}, \%unit_info;
                }
 
-               for my $node (@nodes) {
+               for my $node (@$nodes_ref) {
                        my %unit_info = (
                                name            =>      $node->get_name(),
                                id                      =>      $node->get_id(),
@@ -556,7 +681,7 @@ use Socket;
                        );
                        if ($node->get_id() eq $param{'node_id'}) {
                                $unit_info{'selected'} = 1;
-                               $unit_parameter_ref = $node->get_management()->get_parameters();
+                               $unit_parameter_ref = $node->get_parameters();
                                if (!$unit_parameter_ref) {
                                        $error .= "Could not get parameters for node " . $node->get_name() . "\n";
                                }
@@ -564,33 +689,39 @@ use Socket;
                        push @{$tmpl_var{'unit_infos'}}, \%unit_info;
                }
 
-               if ($param{'group'} eq "" && $param{'node_id'} eq ""
+               if ($param{'group_id'} < 0 && $param{'node_id'} < 0 
                        && @{$tmpl_var{'unit_infos'}} > 0) {
                        $tmpl_var{'unit_infos'}->[0]->{'selected'} = 1;
-                       my $group = $tmpl_var{'unit_infos'}->[0]->{'name'};
-                       $unit_parameter_ref = Varnish::NodeManager->get_group_parameters($group);
-                       if (!$unit_parameter_ref) {
-                               $error .= "Could not get parameters for group $group\n";
+                       my $id = $tmpl_var{'unit_infos'}->[0]->{'id'};
+                       if ($tmpl_var{'unit_infos'}->[0]->{'is_node'}) {
+                               $unit_parameter_ref = Varnish::NodeManager->get_node($id)->get_parameters();
+                       }
+                       else {
+                               $unit_parameter_ref = Varnish::NodeManager->get_group($id)->get_parameters();
                        }
                }
 
-               my $row = 0;
-               while (my ($parameter, $info) = each %{$unit_parameter_ref} ) {
+               my @parameters = sort(keys(%$unit_parameter_ref));
+               for my $parameter (@parameters) {
+                       my $info = $unit_parameter_ref->{$parameter};
                        my $value = $info->{'value'};
                        my $unit = $info->{'unit'};
-                       my $is_boolean = $unit eq "[bool]";
+                       my $is_boolean = $unit && $unit eq "bool";
                        if ($is_boolean) {
-                               $value = $value eq "on";
+                               $value = $value && $value eq "on";
                                $unit = '';
                        }
-                       
+               
+#                      my $description = $info->{'description'};
+#                      $description =~ s/'/''/g;
+#                      print "INSERT INTO parameter_info(name, unit, description) values('$parameter', '$unit', '$description');\n";
+
                        push @{$tmpl_var{'parameter_infos'}}, {
                                name            => $parameter,
                                value           => $value,
                                unit            => $unit,
                                description     => $info->{'description'},
                                is_boolean      => $is_boolean,
-                               odd_row         => $row++ % 2,
                        };
                }
 
@@ -604,13 +735,16 @@ use Socket;
                my ($parameter_ref) = @_;
 
                my %param = %{$parameter_ref};
-               $param{'node_id'} ||= "";
-               $param{'group'} ||= "";
+               $param{'node_id'} = -1 if (!defined($param{'node_id'}));
+               $param{'group_id'} = -1 if (!defined($param{'group_id'}));
+               $param{'group_name'} ||= "";
                $param{'operation'} ||= "";
                $param{'name'} ||= "";
                $param{'address'} = $$parameter_ref{'address'} || "";
                $param{'port'} ||= "";
                $param{'management_port'} ||= "";
+               $param{'inherit_settings'} ||= "";
+               $param{'edit_node'} ||= -1;
        
                my $template = "node_management.tmpl";
                my %tmpl_var = ();
@@ -618,98 +752,135 @@ use Socket;
                $tmpl_var{'status'} = "";
                $tmpl_var{'add_group'} = 0;
                $tmpl_var{'group_infos'} = [];
-               $tmpl_var{'group'} = $param{'group'} || "";
+               $tmpl_var{'group_id'} = $param{'group_id'};
                $tmpl_var{'node_infos'} = [];
                $tmpl_var{'default_managment_port'} = 9001;
                $tmpl_var{'backend_health_infos'} = [];
+               $tmpl_var{'show_group_controls'} = 1;
+               $tmpl_var{'show_group'} = 0;
+               $tmpl_var{'show_add_node'} = 1;
+               $tmpl_var{'show_node_in_backend_health'} = 1;
+               $tmpl_var{'inherit_settings'} = 0;
+               $tmpl_var{'show_inherit_settings'} = 1;
 
                my $error = "";
                my $status = "";
 
                if ($param{'operation'} eq "add_group") {
-                       if ($param{'group'}) {
-                               Varnish::NodeManager->add_group($param{'group'});
-                                $status .= "Group " . $param{'group'} . " added successfully.";
+                       if ($param{'group_name'}) {
+                               my $new_group = Varnish::Group->new({name => $param{'group_name'}});
+                               Varnish::NodeManager->add_group($new_group);
+                               $tmpl_var{'group_id'} = $new_group->get_id();
+                               $status .= "Group " . $param{'group_name'} . " added successfully.";
+                               log_info("[" . $param{'group_name'} . "] [Added group]");
                        }
                        else {
+                               $tmpl_var{'group_id'} = -2;
                                $tmpl_var{'add_group'} = 1;
                        }
                }
                elsif ($param{'operation'} eq "remove_group") {
-                       if ($param{'group'}) {
-                               Varnish::NodeManager->remove_group($param{'group'});
-                               $status = "Group " . $param{'group'} . " removed successfully";
-                               $tmpl_var{'group'} = "";
+                       if ($param{'group_id'} >= 0) {
+                               my $group = Varnish::NodeManager->get_group($param{'group_id'});
+                               if (Varnish::NodeManager->remove_group($group)) {
+                                       $status = "Group ". $group->get_name() . " removed successfully";
+                                       log_info("[" . $group->get_name() . "] [Removed group]");
+                               }
+                               else {
+                                       $error = "Error removing group " . $group->get_name() . ": " . get_error();
+                               }
+                               $tmpl_var{'group_id'} = -1;
                        }
                }
                elsif ($param{'operation'} eq "start_group") {
-                       my $node_errors = "";
-                       for my $node (Varnish::NodeManager->get_nodes()) {
-                               if ($node->get_group() eq $param{'group'}
-                                               && !$node->is_running()) {
-                                       my $management = $node->get_management();
-                                       if (!$management->start()) {
-                                               $node_errors .= "Could not start " . $node->get_name() . ": " 
-                                                                               . $management->get_error() . ". ";
-                                       }
-                               }
-                       }
-
-                       if ($node_errors eq "") {
-                               $status .= "Group " . $param{'group'} . " started successfully.";
+                       my $group = Varnish::NodeManager->get_group($param{'group_id'});
+                       if ($group->start()) {
+                               $status .= "Group " . $group->get_name() . " started successfully.";
+                               log_info("[" . $group->get_name() . "] [Started group]");
                        }
                        else {
-                               $status .= "Group " . $param{'group'} . " started with errors: $node_errors.";
+                               $status .= "Group " . $group->get_name() . " started with errors: " . get_error();
                        }
                }
                elsif ($param{'operation'} eq "stop_group") {
-                       my $node_errors = "";
-                       for my $node (Varnish::NodeManager->get_nodes()) {
-                               if ($node->get_group() eq $param{'group'} 
-                                               && $node->is_running()) {
-                                       my $management = $node->get_management();
-                                       if (!$management->stop()) {
-                                               $node_errors .= "Could not stop " . $node->get_name() . ": " 
-                                                                               . $management->get_error() . ". ";
-                                       }
-                               }
-                       }
-                       if ($node_errors eq "") {
-                               $status .= "Group " . $param{'group'} . " stopped successfully.";
+                       my $group = Varnish::NodeManager->get_group($param{'group_id'});
+                       if ($group->stop()) {
+                               $status .= "Group " . $group->get_name() . " stopped successfully.";
+                               log_info("[" . $group->get_name() . "] [Stopped group]");
                        }
                        else {
-                               $status .= "Group " . $param{'group'} . " stopped with errors: $node_errors.";
+                               $status .= "Group " . $group->get_name() . " started with errors: " . get_error();
+                       }
+               }
+               elsif ($param{'operation'} eq "rename_group") {
+                       my $group = Varnish::NodeManager->get_group($param{'group_id'});
+                       if ($group && $param{'group_name'}) {
+                               my $old_name = $group->get_name();
+
+                               $group->set_name($param{'group_name'});
+                               Varnish::NodeManager->update_group($group);
+                               log_info("[" . $group->get_name() . "] [Renamed group] [$old_name => "
+                                       . $group->get_name() . "]");
                        }
                }
                elsif ($param{'operation'} eq 'add_node') {
                        if ($param{'name'} && $param{'address'} && $param{'port'} 
-                               && $param{'group'} && $param{'management_port'}) {
+                               && $param{'group_id'} >= 0 && $param{'management_port'}) {
                                my $node = Varnish::Node->new({
                                        name                    => $param{'name'}, 
                                        address                 => $param{'address'},
                                        port                    => $param{'port'}, 
-                                       group                   => $param{'group'}, 
+                                       group_id                => $param{'group_id'}, 
                                        management_port => $param{'management_port'}
                                });
-                               Varnish::NodeManager->add_node($node);
+                               my $inherit_settings = $param{'inherit_settings'} ne "";
+                               Varnish::NodeManager->add_node($node, $inherit_settings);
                                $status .= "Node " . $node->get_name() . " added successfully.";
+                               
+                               log_info("[" . $node->get_name() . "] [Added node]"
+                                       . " [name=" . $node->get_name() . "]"
+                                       . " [address=" . $node->get_address() . "]"
+                                       . " [port=" . $node->get_port() . "]"
+                                       . " [group=" . $param{'group_name'} . "]"
+                                       . " [management_port=" . $node->get_management_port() . "]");
                        }
                        else {
                                $error .= "Not enough information to add node:\n"; 
                                $error .= "Name: " . $param{'name'} . ":\n"; 
                                $error .= "Address: " . $param{'address'} . ":\n"; 
                                $error .= "Port: " . $param{'port'} . ":\n"; 
-                               $error .= "Group: " . $param{'group'} . ":\n"; 
                                $error .= "Management port: " . $param{'management_port'} . ":\n"; 
                        }
                }
+               elsif ($param{'operation'} eq 'update_node') {
+                       my $node = Varnish::NodeManager->get_node($param{'node_id'});
+                       
+                       if ($node) {
+                               $node->set_name($param{'name'});
+                               $node->set_address($param{'address'});
+                               $node->set_port($param{'port'});
+                               $node->set_group_id($param{'node_group_id'});
+                               $node->set_management_port($param{'management_port'});
+                               
+                               Varnish::NodeManager->update_node($node);
+
+                               log_info("[" . $node->get_name() . "] [Updated node]"
+                                       . " [name=" . $node->get_name() . "]"
+                                       . " [address=" . $node->get_address() . "]"
+                                       . " [port=" . $node->get_port() . "]"
+                                       . " [group=" . $param{'group_name'} . "]"
+                                       . " [management_port=" . $node->get_management_port() . "]");
+                       }
+               }
+
                elsif ($param{'operation'} eq "remove_node") {
-                       if ($param{'node_id'}) {
+                       if ($param{'node_id'} >= 0) {
                                my $node = Varnish::NodeManager->get_node($param{'node_id'});
                                if ($node) {
-                                       $tmpl_var{'group'} = $node->get_group();
+                                       $tmpl_var{'group_id'} = $node->get_group_id();
                                        Varnish::NodeManager->remove_node($node);
                                        $status .= "Node " . $node->get_name() . " removed successfully.";
+                                       log_info("[" . $node->get_name() . "] [Removed node]");
                                }
                        }
                        else {
@@ -717,21 +888,18 @@ use Socket;
                        }
                }
                elsif ($param{'operation'} eq "start_node") {
-                       if ($param{'node_id'}) {
+                       if ($param{'node_id'} >= 0) {
                                my $node = Varnish::NodeManager->get_node($param{'node_id'});
                                if ($node) {
-                                       my $management = $node->get_management();
-                                       if ($node->is_running()) {
-                                               $status .= "Node " . $node->get_name() . " already running.";
-                                       }
-                                       elsif ($management->start() ) {
+                                       if ($node->start() ) {
                                                $status .= "Node " . $node->get_name() . " started successfully.";
+                                               log_info("[" . $node->get_name() . "] [Started node]");
                                        }
                                        else {
                                                $error .= "Could not start " . $node->get_name() 
-                                                               . ": " . $management->get_error() . "\n"; 
+                                                               . ": " . get_error() . "\n"; 
                                        }
-                                       $tmpl_var{'group'} = $node->get_group();
+                                       $tmpl_var{'group_id'} = $node->get_group_id();
                                }
                        }
                        else {
@@ -739,22 +907,19 @@ use Socket;
                        }
                }
                elsif ($param{'operation'} eq "stop_node") {
-                       if ($param{'node_id'}) {
+                       if ($param{'node_id'} >= 0) {
                                my $node = Varnish::NodeManager->get_node($param{'node_id'});
                                if ($node) {
-                                       my $management = $node->get_management();
-                                       if (!$node->is_running()) {
-                                               $status .= "Node " . $node->get_name() . " already stopped.";
-                                       }
-                                       elsif ($management->stop()) {
+                                       if ($node->stop()) {
                                                $status .= "Node " . $node->get_name() . " stopped successfully.";
+                                               log_info("[" . $node->get_name() . "] [Stopped node]");
                                        }
                                        else {
                                                $error .= "Could not stop " . $node->get_name() 
-                                                               . ": " . $management->get_error() . "\n"; 
+                                                               . ": " . get_error() . "\n"; 
                                        }
                                }
-                               $tmpl_var{'group'} = $node->get_group();
+                               $tmpl_var{'group_id'} = $node->get_group_id();
                        }
                        else {
                                $error .= "Could not stop node: Missing node ID\n";
@@ -762,24 +927,39 @@ use Socket;
                }
 
                # Populate the node table
-               my @groups = Varnish::NodeManager->get_groups();
-               if (@groups) {
-                       if (!$tmpl_var{'group'} && !$tmpl_var{'add_group'}) {
-                               $tmpl_var{'group'} = $groups[0];
-                       }
+               my $groups_ref = Varnish::NodeManager->get_groups();
+               if ($groups_ref) {
                        my @group_infos = map {
                                {
-                                       name            => $_,
-                                       selected        => $_ eq $tmpl_var{'group'},
+                                       name            => $_->get_name(),
+                                       id                      => $_->get_id(),
+                                       is_real         => $_->get_id() >= 0,
+                                       selected        => $_->get_id() eq $tmpl_var{'group_id'},
                                }
-                       } @groups;
+                       } @$groups_ref;
+                       unshift @group_infos, {
+                                       name            => "All nodes",
+                                       id                      => -1,
+                                       selected        => -1 == $tmpl_var{'group_id'},
+                       };
                        $tmpl_var{'group_infos'} = \@group_infos;
-                       
-                       my @nodes = Varnish::NodeManager->get_nodes();
-                       for my $node (@nodes) {
-                               next if ($node->get_group() ne $tmpl_var{'group'});
-
-                               push @{$tmpl_var{'node_infos'}}, {
+               
+                       my $group;
+                       my $nodes_ref;
+                       if ($tmpl_var{'group_id'} != -1) {
+                               $group = Varnish::NodeManager->get_group($tmpl_var{'group_id'});
+                               $nodes_ref = Varnish::NodeManager->get_nodes($group);
+                               if ($tmpl_var{'group_id'} == 0) {
+                                       $tmpl_var{'show_inherit_settings'} = 0;
+                               }
+                       }
+                       else {
+                               $nodes_ref = Varnish::NodeManager->get_nodes();
+                       }
+                       for my $node (@$nodes_ref) {
+                               my $group_name = ($group ? $group->get_name() 
+                                                                                : Varnish::NodeManager->get_group_name($node->get_group_id));
+                               my $node_info_ref = {
                                        id                                              => $node->get_id(),     
                                        is_running_ok                   => $node->is_running_ok(),      
                                        is_running                              => $node->is_running(), 
@@ -788,87 +968,125 @@ use Socket;
                                        address                                 => $node->get_address(),        
                                        port                                    => $node->get_port(),   
                                        management_port                 => $node->get_management_port(),
-                                       group                                   => $node->get_group(),  
+                                       group                                   => $group_name,
+                                       edit                                    => $node->get_id() == $param{'edit_node'},
                                };
-
-                               if (@{$tmpl_var{'backend_health_infos'}} == 0) {
-                                       my $backend_health = $node->get_management()->get_backend_health();
-                                       if ($backend_health) {
-                                               while (my ($backend, $health) = each %{$backend_health}) {
-                                                       push @{$tmpl_var{'backend_health_infos'}}, {
-                                                               name    => $backend,
-                                                               health  => $health,
-                                                       };
-                                               }
+                               my $backend_health = $node->get_backend_health();
+                               if ($backend_health) {
+                                       while (my ($backend, $health) = each %{$backend_health}) {
+                                               push @{$tmpl_var{'backend_health_infos'}}, {
+                                                       name    => $backend,
+                                                       health  => $health,
+                                                       node    => $node_info_ref->{'name'},
+                                               };
                                        }
                                }
+                               push @{$tmpl_var{'node_infos'}}, $node_info_ref;
+                       }
+                       if (@$nodes_ref == 0) {
+                               $tmpl_var{'inherit_settings'} = 1;
                        }
                }
                else {
                        $tmpl_var{'add_group'} = 1;
                }
 
+               my $selected_group = Varnish::NodeManager->get_group($tmpl_var{'group_id'});
+               if ($selected_group) {
+                       $tmpl_var{'group_name'} = $selected_group->get_name();
+               }
+               $tmpl_var{'show_group_controls'} = $tmpl_var{'group_id'} > 0;
+               $tmpl_var{'show_group'} = $tmpl_var{'group_id'} == -1 || $param{'edit_node'} > -1;
+               $tmpl_var{'show_add_node'} = $tmpl_var{'group_id'} >= 0;
                $tmpl_var{'error'} = $error;
                $tmpl_var{'status'} = $status;
                
                return ($template, \%tmpl_var);
        }
 
-sub generate_graph {
-       my ($parameter_ref) = @_;
-
-       my %param = %{$parameter_ref};
-       $param{'width'} ||= 250;
-       $param{'height'} ||= 150;
-       $param{'time_span'} ||= "minute";
-       $param{'type'} ||= "";
-       $param{'node_id'} ||= 0;
-
-       my $interval = get_config_value('poll_interval');
-
-       # this hash holds available graphs which can be added to the summary stats in the view_stats
-       # function.
-       my %graph_info = (
-               # the name of the graph
-               cache_hit_ratio => {
-                       # the parameters to GD::Graph. y_number_format should be noted, as it let you format
-                       # the presentation, like multiplying with 100 to get the percentage as shown here
-                       graph_parameter => {
-                               y_label                 => '%',
-                               title                   => "Cache hit ratio last " . $param{'time_span'},
-                               y_max_value             => 1,
-                               y_min_value             => 0,
-                               y_number_format => sub { return $_[0] * 100 }
+       sub generate_graph {
+               my ($parameter_ref) = @_;
+
+               my %param = %{$parameter_ref};
+               $param{'width'} ||= get_config_value('graph_width');
+               $param{'height'} ||= get_config_value('graph_height');
+               $param{'time_span'} ||= "minute";
+               $param{'unit_id'} ||= -1;
+               $param{'custom_name'} ||= "";
+               $param{'custom_divisors'} ||= "";
+               $param{'custom_dividends'} ||= "";
+               $param{'custom_delta'} ||= "";
+
+
+               my $interval = get_config_value('poll_interval');
+
+               # this hash holds available graphs which can be added to the summary stats in the view_stats
+               # function.
+               my %graph_info = (
+                       # the name of the graph
+                       cache_hit_ratio_since_start     => {
+                               # the parameters to GD::Graph. y_number_format should be noted, as it let you format
+                               # the presentation, like multiplying with 100 to get the percentage as shown here
+                               graph_parameter => {
+                                       y_label                 => '%',
+                                       title                   => 'Cache hit ratio since start',
+                                       y_max_value             => 1,
+                                       #y_min_value            => 0,
+                                       y_number_format => sub { return sprintf("%.2f", $_[0] * 100) }
+                               },
+                               # the divisors and dividends are lists of names of the statistics to
+                               # use when calculating the values in the graph. The names can be obtained
+                               # by turning 'Raw statistics' on in the GUI. The value in the graph is calculated
+                               # by taking the sum of divisors and divide witht the sum of the dividends, i.e.
+                               # value = (divisor1 + divisor2 + divisor3 ...) / (dividend1 + dividend 2 +..)
+                               # if divisor or dividend is emitted, the value of 1 is used instead
+                               divisors                        => [ 'Cache hits' ],
+                               dividends                       => [ 'Cache hits', 'Cache misses' ],
+                       },
+                       connect_rate    => {
+                               graph_parameter => {
+                                       y_label                 => 'Reqs',
+                                       title                   => "Reqs / s last " . $param{'time_span'},
+                                       y_min_value             => 0,
+                               },
+                               # here we have no dividends as we only want to plot 'Client requests received'
+                               divisors                        => [ 'Client requests received' ],
+                               # if use_delta is set to 1, the derived value is used, i.e. the difference
+                               # in value between two measurements. This is usefull for graphs showing rates
+                               # like this connect rate
+                               use_delta                       => 1,
                        },
-                       # the divisors and dividends are lists of names of the statistics to
-                       # use when calculating the values in the graph. The names can be obtained
-                       # by turning 'Raw statistics' on in the GUI. The value in the graph is calculated
-                       # by taking the sum of divisors and divide witht the sum of the dividends, i.e.
-                       # value = (divisor1 + divisor2 + divisor3 ...) / (dividend1 + dividend 2 +..)
-                       # if divisor or dividend is emitted, the value of 1 is used instead
-                       divisors                        => [ 'Cache hits' ],
-                       dividends                       => [ 'Cache hits', 'Cache misses' ],
-               },
-               connect_rate    => {
-                       graph_parameter => {
-                               y_label                 => 'Reqs',
-                               title                   => "Reqs / $interval s  last " . $param{'time_span'},
-                               y_min_value             => 0,
+                       cache_hit_ratio         => {
+                               graph_parameter => {
+                                       y_label                 => '%',
+                                       title                   => "Cache hit last " . $param{'time_span'},
+                                       y_number_format => sub { return sprintf("%.2f", $_[0] * 100) }
+                               },
+                               divisors                        => [ 'Cache hits' ],
+                               dividends                       => [ 'Cache hits', 'Cache misses' ],
+                               # with use_delta set to 2, the delta is calculated by doing
+                               # (divsor(n) - divisor(n-1))/(dividend(n) - dividend(n-1))
+                               # instead of
+                               # ((divisor(n)/dividend(n-1) - (divisor(n-1)/dividend(n-1)
+                               # in the case
+                               # of use_delta = 1
+                               use_delta                       => 2,
                        },
-                       # here we have no dividends as we only want to plot 'Client requests received'
-                       divisors                        => [ 'Client requests received' ],
-                       # if use_delta is set to 1, the derived value is used, i.e. the difference
-                       # in value between two measurements. This is usefull for graphs showing rates
-                       # like this connect rate
-                       use_delta                       => 1,
-               },
-       );
-       my %time_span_graph_parameters  = (
+                       custom                          => {
+                               graph_parameter => {
+                                       y_label                 => 'Value',
+                                       title                   => $param{'custom_name'} .
+                                                                       ($param{'custom_delta'} ? " / s " : "") 
+                                                                               .  " last " . $param{'time_span'},
+                               },
+                               use_delta               => $param{'custom_delta'},
+                       },
+               );
+               my %time_span_graph_parameters  = (
                        minute  => {
                                x_label         => 'Time',
-                               x_tick_number   => 6, # need to be set to make x_number_format work
-                               x_number_format => sub { return strftime(":%S", localtime($_[0])); },
-                               x_max_value             => time
+                               x_tick_number   => 4, # need to be set to make x_number_format work
+                               x_number_format => sub { return strftime("%H:%M:%S", localtime($_[0])); },
                        },
                        hour    => {
                                x_label                 => 'Time',
@@ -888,37 +1106,49 @@ sub generate_graph {
                        month   => {
                                x_label                 => 'Time',
                                x_tick_number   => 4, # need to be set to make x_number_format work
-                               x_number_format => sub { return strftime("%d.%m", localtime($_[0])); },
+                       x_number_format => sub { return strftime("%d.%m", localtime($_[0])); },
                        },
-                       );
-
-
-       if ( !$graph_info{$param{'type'}} 
-                || !$time_span_graph_parameters{$param{'time_span'}}) {
-               #print "Error: Missing data";
-               return;
-       }
-       my $data_ref = Varnish::Statistics->generate_graph_data(
-                       $param{'node_id'}, 
+               );
+       
+               if ( !$graph_info{$param{'type'}} 
+                        || !$time_span_graph_parameters{$param{'time_span'}}) {
+                       return;
+               }
+       
+               if ($param{'type'} eq 'custom') {
+                       if ($param{'custom_divisors'}) {
+                               my @divisors = split(/,\s*/, $param{'custom_divisors'});
+                               $graph_info{'custom'}->{'divisors'} = \@divisors;
+                       }
+                       if ($param{'custom_dividends'}) {
+                               my @dividends = split(/,\s*/, $param{'custom_dividends'});
+                               $graph_info{'custom'}->{'dividends'} = \@dividends;
+                       }
+               }
+               my ($data_ref, $x_min_value, $x_max_value) = Varnish::Statistics->generate_graph_data(
+                       $param{'unit_id'}, 
+                       $param{'is_node'},
                        $param{'time_span'}, 
                        $graph_info{$param{'type'}}->{'divisors'},
                        $graph_info{$param{'type'}}->{'dividends'},
-                       $graph_info{$param{'type'}}->{'use_delta'}
-                       );
-       if (!$data_ref) {
-               #print "Error generating graph data\n";
-               return;
-       }
-       my $graph = GD::Graph::lines->new($param{'width'}, $param{'height'});
-       $graph->set((%{$graph_info{$param{'type'}}->{'graph_parameter'}}, 
+                       $graph_info{$param{'type'}}->{'use_delta'}, 
+                       $param{'width'}
+               );
+               return if (!$data_ref);
+       
+               my $graph = GD::Graph::lines->new($param{'width'}, $param{'height'});
+               if ($param{'width'} < 300) {
+                               $graph->set_title_font(gdTinyFont);
+                       $graph->set_legend_font(gdTinyFont);
+               }
+               $graph->set((%{$graph_info{$param{'type'}}->{'graph_parameter'}}, 
                                %{$time_span_graph_parameters{$param{'time_span'}}}),
-                               dclrs => ["#990200"]);
+                               dclrs => ["#990200"],
+                               x_min_value => $x_min_value, x_max_value => $x_max_value,
+                               skip_undef => 1);
 
                my $graph_image = $graph->plot($data_ref);
-
-               if (!$graph_image) {
-                       return;
-               }
+               return if (!$graph_image);
 
                return $graph_image->png;
        }
@@ -938,10 +1168,10 @@ sub generate_graph {
                $tmpl_var{'default_console_cols'} = 80,
                $tmpl_var{'default_console_rows'} = 30,
 
-               my @nodes = Varnish::NodeManager->get_nodes();
-               if (@nodes) {
-                       my $node_id = $param{'node_id'} ? $param{'node_id'} : $nodes[0]->get_id();
-                       for my $node (@nodes) {
+               my $nodes_ref = Varnish::NodeManager->get_nodes();
+               if ($nodes_ref && @$nodes_ref > 0) {
+                       my $node_id = $param{'node_id'} ? $param{'node_id'} : $nodes_ref->[0]->get_id();
+                       for my $node (@$nodes_ref) {
                                my $selected = $node->get_id() == $node_id;
                                push @{$tmpl_var{'node_infos'}}, {
                                        id                      => $node->get_id(),
@@ -968,7 +1198,7 @@ sub generate_graph {
                        },
                        {
                                name            => 'Retro',
-                               foreground      => 'green',
+                               foreground      => '#00ff00',
                                background      => 'black',
                        }
                ];
index 2552e7300ce62a3482a5f7f90d0d11430f1749a3..328af350bf90b21c34825f8bb2af8fcfd8a63593 100644 (file)
@@ -6,58 +6,59 @@ use List::Util qw(first);
 
 use Varnish::Util;
 use Varnish::NodeManager;
+use Varnish::DB;
 
 {
-       my %data;
-       my $last_measure_ref;
        my $last_measure_time;
+       my $clean_up_time;
+
+       sub BEGIN {
+               my $now = time();
+               my ($sec, $min, $hour) = localtime($now);
+               $clean_up_time = $now 
+                                               + (23 - $hour) *  3600
+                                               + (59 - $min) * 60
+                                               + (60 - $sec);
+       }
 
        sub collect_data {
                my $time_stamp = time();
-               my %measure;
-               my $good_stat_ref;
-               my @nodes = Varnish::NodeManager->get_nodes();
+               my $nodes_ref = Varnish::NodeManager->get_nodes();
+
+               if ($time_stamp > $clean_up_time) {
+                       Varnish::DB->clean_up();
+                       $clean_up_time += 86400;
+               }
 
-               my @bad_nodes;
-               for my $node (@nodes) {
+               for my $node (@$nodes_ref) {
                        my $management = $node->get_management();
-                       my $stat_ref;
+                       my $stat_ref = {};
                        if ($management) {
                                $stat_ref = $management->get_stats();
                        }
-                       if ($stat_ref) {
-                               $measure{$node} = $stat_ref;
-                               if (!$good_stat_ref) {
-                                       $good_stat_ref = $stat_ref;
-                               }
-                       }
-                       else {
-                               push @bad_nodes, $node;
-                       }
-               }
-
-               if (@bad_nodes && $good_stat_ref) {
-                       for my $bad_node (@bad_nodes) {
-                               $measure{$bad_node}->{'missing data'} = 1;
-                               for my $key (keys %$good_stat_ref) {
-                                       $measure{$bad_node}->{$key} = -1;
-                               }
-                       }
+                       Varnish::DB->add_stat($node, $stat_ref, $time_stamp);
                }
-
-               $data{$time_stamp} = \%measure;
-               $last_measure_ref = \%measure;
                $last_measure_time = $time_stamp;
        }
 
 
        sub get_last_measure {
-       
-               return ($last_measure_time, $last_measure_ref);
+               my ($self, $unit) = @_;
+
+               my $stat_data_ref = Varnish::DB->get_stat_data($unit, $last_measure_time - 1);
+               if ($stat_data_ref) {
+                       delete $stat_data_ref->[0]->{'has_data'};
+
+                       return ($last_measure_time, $stat_data_ref->[0]);
+               }
+               else {
+                       return (undef, undef);
+               }
        }
        
        sub generate_graph_data {
-               my ($self, $node_id, $time_span, $divisors_ref, $dividends_ref, $use_delta) = @_;
+               my ($self, $unit_id, $is_node, $time_span, $divisors_ref, $dividends_ref, $use_delta, $desired_number_of_values) = @_;
+               $desired_number_of_values ||= 0;
                
                my %seconds_for = (
                        minute  => 60,
@@ -66,37 +67,59 @@ use Varnish::NodeManager;
                        week    => 604800,      
                        month   => 18144000, # 30 days
                );
-               my $start_time = time() - $seconds_for{$time_span};
+               my $current_time = time();
+               my $start_time = $current_time - $seconds_for{$time_span};
+               my $poll_interval = get_config_value('poll_interval');
                if ($use_delta) {
-                       $start_time -= get_config_value('poll_interval');
+                       $start_time -= $poll_interval;
+               }
+       
+               my $measures_ref;
+               if ($is_node) {
+                       my $node = Varnish::NodeManager->get_node($unit_id);
+                       return ([],[], -1, -1) if (!$node);
+                       $measures_ref = Varnish::DB->get_stat_data($node, $start_time);
+               }
+               else {
+                       my $group = Varnish::NodeManager->get_group($unit_id);
+                       return ([],[], -1, -1) if (!$group);
+                       $measures_ref = Varnish::DB->get_stat_data($group, $start_time);
                }
-               my $node = first { 
-                                               $_->get_id() == $node_id
-                                       } Varnish::NodeManager->get_nodes();
 
-               my @measures = grep { 
-                                                       $_ > $start_time 
-                                               } (sort keys %data);
+               my @divisors = ($divisors_ref ? 
+                                                       map {  get_db_friendly_name($_); } @$divisors_ref : ());
+               my @dividends = ($dividends_ref ? 
+                                                       map {  get_db_friendly_name($_); } @$dividends_ref : ());
                my @values;
+               my @times;
+               my $value2;
                my $last_value;
+               my $last_divisor;
+               my $last_dividend;
+               my $last_total_requests;
+               my $last_time;
+               my $x_min;
+               my $x_max;
                GENERATE_DATA:
-               for my $measure (@measures) {
+               for my $measure_ref (@$measures_ref) {
                        my $value;
-                       if (!$data{$measure}->{$node}->{'missing data'}) {
+                       my $time = $measure_ref->{'time'};
+
+                       if ($measure_ref->{'has_data'}) {
                                my $divisor_value = 0;
                                my $dividend_value = 0;
 
-                               if ($divisors_ref && @$divisors_ref) {
-                                       for my $divisor (@$divisors_ref) {
-                                               $divisor_value += $data{$measure}->{$node}->{$divisor};
+                               if (@divisors > 0) {
+                                       for my $divisor (@divisors) {
+                                               $divisor_value += $measure_ref->{$divisor};
                                        }
                                }
                                else {
                                        $divisor_value = 1;
                                }
-                               if ($dividends_ref && @$dividends_ref) {
-                                       for my $dividend (@$dividends_ref) {
-                                               $dividend_value += $data{$measure}->{$node}->{$dividend};
+                               if (@dividends) {
+                                       for my $dividend (@dividends) {
+                                               $dividend_value += $measure_ref->{$dividend};
                                        }
                                }
                                else {
@@ -109,23 +132,102 @@ use Varnish::NodeManager;
                                if ($use_delta) {
                                        if (!$last_value) {
                                                $last_value = $value;
+                                               $last_dividend = $dividend_value;
+                                               $last_divisor = $divisor_value;
+                                               $last_time = $time;
+                                               $last_total_requests = $measure_ref->{'total_requests'};
                                                next GENERATE_DATA;
                                        }
-                                       my $delta_value = $value - $last_value;
+                                       my $delta_time = $time - $last_time;
+                                       my $delta_value;
+                                       if ($use_delta == 2) {
+                                               if ($dividend_value != $last_dividend) {
+                                                       $delta_value = 
+                                                               ($divisor_value - $last_divisor) / ($dividend_value - $last_dividend);
+                                               }
+                                               else {
+                                                       $delta_value = undef;
+                                               }
+                                       }
+                                       else {
+                                               $delta_value = ($value - $last_value) / $delta_time;
+                                       }
+
                                        $last_value = $value;
-                                       # if the value is negative, then we have had restart and don't plot it.
-                                       if ($delta_value < 0) {
+                                       # check if node has been restarted, as the delta would be huge
+                                       # and negative if it has
+                                       my $total_requests = $measure_ref->{'total_requests'};
+                                       if ($total_requests < $last_total_requests) {
                                                $value = undef;
                                        }
                                        else {
                                                $value = $delta_value;
                                        }
+
+                                       $last_dividend = $dividend_value;
+                                       $last_divisor = $divisor_value;
+                                       $last_total_requests = $total_requests;
+                                       $last_time = $time;
                                }
                        }
+                       
+                       $x_min ||= $time;
+                       $x_max = $time;
+
+                       push @times, $time;
                        push @values, $value;
                }
+               
+               my $possible_number_of_values = $seconds_for{$time_span} / $poll_interval;
+               if ($desired_number_of_values && 
+                               $possible_number_of_values > $desired_number_of_values) {
+                       my $partition_size = $seconds_for{$time_span} / $desired_number_of_values;
+                       my $start_time = shift @times;
+                       my $aggregated_value = shift @values;
+                       my $aggregated_width = (defined($aggregated_value) ? 1 : 0);
+                       my $end_time = $start_time + $partition_size;
+                       my @new_times;
+                       my @new_values;
+                       
+                       while (my $time = shift(@times)) {
+                               my $value = shift @values;
+                               if ($time < $end_time) {
+                                       if (defined($value)) {
+                                               $aggregated_value += $value;
+                                               $aggregated_width++;
+                                       }
+                               }
+                               else {
+                                       push @new_times, $start_time;
+                                       if ($aggregated_width > 0) {
+                                               push @new_values, $aggregated_value / $aggregated_width;
+                                       }
+                                       else {
+                                               push @new_values, undef;
+                                       }
+                                       $start_time = $time;
+                                       $end_time = $start_time + $partition_size;
+                                       $aggregated_value = $value;
+                                       $aggregated_width = (defined($value) ? 1 : 0);
+                               }
+                       }
+                       
+                       push @new_times, $start_time;
+                       if ($aggregated_width > 0) {
+                               push @new_values, $aggregated_value / $aggregated_width;
+                       }
+                       else {
+                               push @new_values, undef;
+                       }
+
+                       @times = @new_times;
+                       @values = @new_values;
+               }
+
+               unshift @times, $start_time;
+               unshift @values, undef;
 
-               return [ \@measures, \@values ];
+               return ([\@times, \@values], $x_min, $x_max);
        }
 }
 
index d3be98815d8dce6a51c26c1d5842b6c51238357d..198abec59afe875e3e73182da6ac287dd1f474ff 100644 (file)
@@ -3,6 +3,9 @@ package Varnish::Util;
 use strict;
 use Exporter;
 use base qw(Exporter);
+use POSIX qw(strftime);
+use URI::Escape;
+use Algorithm::Diff;
 
 our @EXPORT = qw(
                                set_config
@@ -10,15 +13,35 @@ our @EXPORT = qw(
                                read_file
                                get_formatted_percentage
                                get_formatted_bytes
+                               get_db_friendly_name 
+                               get_error
+                               set_error
+                               no_error
+                               log_info
+                               log_error
+                               url_encode
+                               url_decode
+                               diff
                                );
 
 {
        my %config;
+       my $error;
+       my $log_handle;
 
        sub set_config {
                my ($config_ref) = @_;
 
                %config = %{$config_ref};
+
+               if ($config{'log_filename'}) {
+                       if (!open($log_handle, ">>" . $config{'log_filename'})) {
+                               die "Could not open log file " . $config{'log_filename'} . " for writing";
+                       }
+                       $log_handle->autoflush(1); # FIXME: Remove it, or is it usefull?
+               }
+
+               Varnish::DB->init($config{'db_filename'});
        }
 
        sub get_config_value {
@@ -63,6 +86,107 @@ our @EXPORT = qw(
                        return $bytes . " B";
         }
        }
+
+       sub get_db_friendly_name {
+               my ($name) = @_;
+
+               $name =~ s/ /_/g;
+               $name =~ s/\(/_/g;
+               $name =~ s/\)/_/g;
+
+               return lc($name);
+       }
+
+
+       sub set_error {
+               my ($new_error) = @_;
+
+               $error = $new_error;
+
+               return;
+       }
+
+       sub get_error {
+               
+               return $error;
+       }
+
+       sub no_error {
+               my ($return_value) = @_;
+
+               $error = "";
+
+               return defined($return_value) ? $return_value : 1;
+       }
+
+       sub _log {
+               my ($severity, $string) = @_;
+
+               return if (!$log_handle);
+
+               my $time_stamp = strftime("%Y-%m-%d %H:%M:%S", localtime);
+               print $log_handle "[$time_stamp] [$severity] $string\n";
+       }
+
+       sub log_error {
+               my ($string) = @_;
+
+               _log("ERROR", $string);
+       }
+
+       sub log_info {
+               my ($string) = @_;
+
+               _log("INFO", $string);
+       }
+
+       sub url_decode {
+               my ($value) = @_;
+
+               $value = uri_unescape($value);
+               $value =~ s/\+/ /g;
+
+               return $value;
+       }
+
+       sub url_encode {
+               my ($value) = @_;
+
+               $value = uri_escape($value);
+               $value =~ s/ /\+/g;
+
+               return $value;
+       }
+
+       sub diff {
+               my ($old_text, $new_text) = @_;
+               
+               my @old_text_lines = split /\n/, $old_text;
+               my @new_text_lines = split /\n/, $new_text;
+               my $diff_text = "";
+               my $diff = Algorithm::Diff->new( \@old_text_lines, \@new_text_lines );
+               $diff->Base( 1 );   # Return line numbers, not indices
+               while ($diff->Next()) {
+                       next if  $diff->Same();
+                       my $sep = '';
+                       if (!$diff->Items(2)) {
+                               $diff_text .= sprintf("%d,%dd%d\n",
+                                        $diff->Get(qw( Min1 Max1 Max2 )));
+                       } elsif (!$diff->Items(1)) {
+                               $diff_text .= sprintf("%da%d,%d\n",
+                                       $diff->Get(qw( Max1 Min2 Max2 )));
+                       } else {
+                               $sep = "---\n";
+                               $diff_text .= sprintf("%d,%dc%d,%d\n", 
+                                       $diff->Get(qw( Min1 Max1 Min2 Max2 )));
+                       }
+                       $diff_text .= "< $_" for $diff->Items(1);
+                       $diff_text .= $sep;
+                       $diff_text .= "> $_" for $diff->Items(2);
+               }
+
+               return $diff_text;
+       }
 }
 
 1;
diff --git a/varnish-tools/webgui/create_db_data.pl b/varnish-tools/webgui/create_db_data.pl
new file mode 100755 (executable)
index 0000000..acec4a4
--- /dev/null
@@ -0,0 +1,137 @@
+#!/usr/bin/perl
+#
+# This script generates the database schema SQL and Varnish::DB_Data module needed
+# by the web GUI. It connects to the management port of a running Varnish and extracts
+# the paramter and stat values.
+
+use strict;
+
+use Varnish::Node;
+use Varnish::Util;
+
+# The hostname of the varnish to extract the parameter and stat values from
+my $hostname = "localhost";
+my $management_port = 9001;
+
+
+my $node_info_ref = {
+       name                    => 'dummy',
+       address                 => $hostname,
+       group_id                => 0,
+       management_port => $management_port,
+};
+my $node = Varnish::Node->new($node_info_ref);
+if (!$node->get_management()->ping()) {
+       print STDERR "Could not contact " . $node_info_ref->{'address'}
+                       . ":" . $node_info_ref->{'management_port'} . ": " . get_error() . "\n"; 
+       exit(-1);
+}
+
+my $stat_ref = $node->get_management()->get_stats();
+my $stat_fields_exists_string = "my %stat_field_exist = (";
+my $stat_fields_sql;
+for my $stat (keys(%$stat_ref)) {
+       my $name = get_db_friendly_name($stat);
+       $stat_fields_sql .= $name . " INTEGER,\n";
+       $stat_fields_exists_string .= "'$name' => 1,\n";
+}
+$stat_fields_exists_string .= ");\n";
+
+my $parameter_ref = $node->get_parameters();
+my $parameter_fields_sql;
+my $parameter_info_sql;
+my $parameters_field_string = "my %parameter_field = (\n";
+for my $parameter (sort(keys(%$parameter_ref))) {
+       my $name = get_db_friendly_name($parameter);
+       if ($name eq "user" || $name eq "group") {
+               $name = "child_$name";
+       }
+       $parameter_fields_sql .= $name . " TEXT,\n";
+       my $unit = $parameter_ref->{$parameter}->{'unit'};
+       $unit =~ s/'/''/g;
+       my $description = $parameter_ref->{$parameter}->{'description'};
+       $description =~ s/'/''/g;
+       $parameter_info_sql .= sprintf("INSERT INTO parameter_info VALUES('%s', '%s', '%s');\n",
+               $name, $unit, $description);
+
+       my $value = $parameter_ref->{$parameter}->{'value'};
+       $value =~ s/'/\\'/g;
+       $name = get_db_friendly_name($parameter);
+       $parameters_field_string .= "'$name' => {value => '$value'},\n";
+}
+$parameters_field_string .= ");\n";
+
+my $sql = <<"END_SQL";
+DROP TABLE node_group;
+DROP TABLE node;
+DROP TABLE stat;
+DROP TABLE parameters;
+DROP TABLE parameter_info;
+DROP TABLE vcl;
+
+CREATE TABLE node_group (
+       id INTEGER PRIMARY KEY,
+       active_vcl TEXT,
+       name text
+);
+
+CREATE TABLE node (
+       id INTEGER PRIMARY KEY,
+       name TEXT,
+       address TEXT,
+       port TEXT,
+       group_id INTEGER,
+       management_port TEXT,
+       is_master BOOLEAN
+);
+
+CREATE TABLE stat (
+       id INTEGER PRIMARY KEY,
+       time TIMESTAMP,
+       node_id INTEGER,
+$stat_fields_sql
+       has_data INTEGER
+);
+
+CREATE TABLE parameters (
+       id INTEGER PRIMARY KEY,
+$parameter_fields_sql
+       group_id INTEGER
+);
+
+CREATE TABLE vcl(
+       group_id INTEGER,
+       name TEXT,
+       vcl TEXT
+);
+
+CREATE TABLE parameter_info(
+       name TEXT PRIMARY KEY,
+       unit TEXT,
+       description TEXT
+);
+
+INSERT INTO node_group VALUES(0, 0, 'Standalone');
+
+$parameter_info_sql
+END_SQL
+
+my $sql_file = "varnish_webgui.sql";
+open(my $SQL, ">$sql_file") || die "Could not open SQL output file";
+print $SQL "-- This file was auto generated " . localtime() . " by create_db_files.pl\n";
+print $SQL $sql;
+close($SQL);
+print "Wrote SQL to $sql_file successfully\n";
+
+my $db_data_file = "Varnish/DB_Data.pm";
+open(my $DB_DATA, ">$db_data_file") || die "Could not open DB fields";
+print $DB_DATA "# This file was auto generated " . localtime() . " by create_db_files.pl\n";
+print $DB_DATA "# DO NOT EDIT BUT RERUN THE SCRIPT!\n"; 
+print $DB_DATA "package Varnish::DB_Data;\n\n";
+print $DB_DATA $parameters_field_string;
+print $DB_DATA $stat_fields_exists_string;
+print $DB_DATA "sub get_parameter_field() { return \\%parameter_field; }";
+print $DB_DATA "sub get_stat_field_exist() { return \\%stat_field_exist; }";
+print $DB_DATA "\n1;\n";
+close $DB_DATA;
+print "Wrote SQL to $db_data_file successfully\n";
index 7f7cb2a3bb25caaf147352d581fadde892569cbf..1fa1bcc23554bb48cbd988a0ba41e73368319ddc 100644 (file)
@@ -24,7 +24,7 @@ img#headerLogo {
 }
 
 #menu {
-       padding: 5px 3px 5px 3px;
+       padding: 5px 3px 5px 15px;
        text-align: center;
 }
 
@@ -49,6 +49,7 @@ a.menu {
 }
 
 td.header {
+       vertical-align: top;
        font-weight: bold;
        border-style: solid;
        border-width: 0px 0px 1px 0px;
@@ -187,3 +188,16 @@ input.removeNode {
        background-color: red;
        padding: 5px;
 }
+
+td.addNodeBorder {
+       margin: 15px;
+}
+
+img.goToNodeManagement {
+       border-width: 0 0 1px 0;
+}
+
+a.showNodeStats {
+       font-size: 0.7em;
+       margin-left: 30px;
+}
index 30af292a16e9fa73c9515f477a3bfab81b6db0e3..7a23be15501383c1c7ee75f33376d697c8d110e9 100755 (executable)
@@ -11,6 +11,7 @@ use Varnish::RequestHandler;
 use Varnish::NodeManager;
 use Varnish::Node;
 use Varnish::Statistics;
+use Varnish::DB;
 
 
 # Configuration starts here
@@ -23,58 +24,29 @@ my %config = (
 
 # 'poll_intervall' is the polling interval for the statistics
        poll_interval           => 5,
-);
 
-# create some default groups 
-my @groups = qw(default images);
+# 'restricted' gives a restricted version of the web GUI, disabling the user
+# from changing any values
+       restricted                      => 0,
 
-# create some default nodes 
-my @node_params = (
-       {
-               name                    => 'varnish-1',
-               address                 => 'localhost',
-               port                    => '80',
-               group                   => 'default',
-               management_port => 9001,
-       },
-       {
-               name                    => 'varnish-2',
-               address                 => 'localhost',
-               port                    => '8181',
-               group                   => 'default',
-               management_port => 9002,
-       },
-       {
-               name                    => 'varnish-1',
-               address                 => 'localhost',
-               port                    => '8888',
-               group                   => 'images',
-               management_port => 9003,
-       },
-);
+# 'graph_width' and 'graph_height' are width and height for the graphs in 'View stats'
+       graph_width                     => 250,
+       graph_height            => 125,
+# 'large_graph_width' and 'large_graph_height' are width and height for the full size graph
+# when clicking a stat graph in 'View stats'
+       large_graph_width       => 1000,
+       large_graph_height      => 500,
 
+# 'log_filename' is the filename to log errors and information about actions done in the GUI
+       log_filename            => "varnish.log",
+
+# 'db_filename' is the sqlite3 database created with the SQL outputed from create_db_data.pl
+       db_filename                     => 'varnish.db',
+);
 # End of configuration
 
 set_config(\%config);
 
-for my $group (@groups) {
-       Varnish::NodeManager->add_group($group);
-}
-
-for my $node_param_ref (@node_params) {
-       my $group_exists =      grep {
-                                                       $_ eq $node_param_ref->{'group'}
-                                               } @groups;
-       if ($group_exists) {
-               my $node = Varnish::Node->new($node_param_ref);
-               Varnish::NodeManager->add_node($node);
-       }
-       else {
-               print "Node " . $node_param_ref->{'name'} . " has an invalid group "
-                               . $node_param_ref->{'group'} . ". Skipping.";
-       }
-}
-
 # catch interupt to stop the daemon
 $SIG{'INT'} = sub {
        print "Interrupt detected.\n";
@@ -85,15 +57,23 @@ $SIG{'PIPE'} = sub {
 #      print "Pipe ignored\n";
 };
 
+log_info("Starting HTTP daemon");
 my $daemon = HTTP::Daemon->new(        LocalPort => $config{'port'}, 
                                                                LocalAddr => $config{'address'},
-                                                               ReuseAddr => 1 ) || die "Could not start web server";
+                                                               ReuseAddr => 1 );
+
+if (!$daemon) {
+       log_error("Could not start HTTP daemon");
+       die "Could not start web server";
+}
+log_info("HTTP daemon started with URL " . $daemon->url);
 print "Web server started with URL: " . $daemon->url, "\n";
 my $data_collector_handle = threads->create('data_collector_thread');
 while (my $connection = $daemon->accept) {
        REQUEST:
        while (my $request = $connection->get_request) {
                $connection->force_last_request;
+#              print "Request for: " . $request->uri . "\n";
                if ($request->uri =~ m{/(.*?\.png)} ||
                        $request->uri =~ m{/(.*?\.css)} ||
                        $request->uri =~ m{/(.*?\.ico)}) {
@@ -114,25 +94,25 @@ while (my $connection = $daemon->accept) {
        $connection->close();
        undef($connection);
 }
-print "Shutting down!\n";
+log_info("Shutting down web server");
 $daemon->close();
-Varnish::NodeManager->quit();
-print "Stopping data collector thread\n";
+Varnish::DB->finish();
+log_info("Stopping data collector thread");
 $data_collector_handle->join();
 
 sub data_collector_thread {
        my $url = $daemon->url . "collect_data";
        my $interval = $config{'poll_interval'};
-       print "Data collector thread started. Polling URL $url at $interval seconds interval\n";
-
+       
+       log_info("Data collector thread started. Polling URL $url at $interval seconds interval");
        sleep 1; # wait for the server to come up
        while (1) {
                my $user_agent = LWP::UserAgent->new;
-               $user_agent->timeout(6);
+               $user_agent->timeout(10);
                my $response = $user_agent->get($url);
                        
                last if ($response->code eq "500");
-               sleep $interval;
+               sleep($interval);
        }
        print "Data collector thread stopped.\n";
 }
index 5b7244fdac8afbb95591a26780ddefcf1bd56992..c722903c610700fea018f0476c8eedc3697aba30 100644 (file)
@@ -20,15 +20,15 @@ function toggleHelp(sectionId) {
 <TMPL_IF NAME=IS_NODE>
 <input type="hidden" name="node_id" value="<TMPL_VAR NAME=ID>"/>
 <TMPL_ELSE>
-<input type="hidden" name="group" value="<TMPL_VAR NAME=ID>"/>
+<input type="hidden" name="group_id" value="<TMPL_VAR NAME=ID>"/>
 </TMPL_IF>
 <TMPL_ELSE>
 <span class="tab">
 </TMPL_IF>
 <TMPL_IF NAME=IS_NODE>
-<a href="configure_parameters?node_id=<TMPL_VAR NAME=ID>"><TMPL_VAR NAME=NAME> (node)</a>
+<a href="configure_parameters?node_id=<TMPL_VAR NAME=ID>"><TMPL_VAR NAME=NAME> (N)</a>
 <TMPL_ELSE>
-<a href="configure_parameters?group=<TMPL_VAR NAME=ID>"><TMPL_VAR NAME=NAME> (group)</a>
+<a href="configure_parameters?group_id=<TMPL_VAR NAME=ID>"><TMPL_VAR NAME=NAME> (G)</a>
 </TMPL_IF>
 </span>
 </TMPL_LOOP>
@@ -37,13 +37,24 @@ function toggleHelp(sectionId) {
 <table id="parameters">
 <tr><td class="header">Name</td><td class="header">Value</td><td class="header">Unit</td><td class="header"></td></tr>
 <TMPL_LOOP NAME=PARAMETER_INFOS>
-<TMPL_IF NAME=ODD_ROW>
+<TMPL_IF NAME=__ODD__>
 <tr class="oddRow">
 <TMPL_ELSE>
 <tr class="evenRow">
 </TMPL_IF>
 <td class="parameterLabel"><TMPL_VAR NAME=NAME></td>
 <td class="parameterValue">
+<TMPL_IF NAME=RESTRICTED>
+<TMPL_IF NAME=IS_BOOLEAN>
+<TMPL_IF NAME=VALUE>
+on
+<TMPL_ELSE>
+off
+</TMPL_IF>
+<TMPL_ELSE>
+<TMPL_VAR NAME=VALUE>
+</TMPL_IF>
+<TMPL_ELSE>
 <TMPL_IF NAME=IS_BOOLEAN>
 <select name="new_<TMPL_VAR NAME=NAME>">
 <TMPL_IF NAME=VALUE>
@@ -57,7 +68,6 @@ function toggleHelp(sectionId) {
 <TMPL_ELSE>
 <input type="text" name="new_<TMPL_VAR NAME=NAME>" value="<TMPL_VAR NAME=VALUE>"/>
 </TMPL_IF>
-
 <TMPL_IF NAME=IS_BOOLEAN>
 <TMPL_IF NAME=VALUE>
 <input type="hidden" name="old_<TMPL_VAR NAME=NAME>" value="on"/>
@@ -67,7 +77,7 @@ function toggleHelp(sectionId) {
 <TMPL_ELSE>
 <input type="hidden" name="old_<TMPL_VAR NAME=NAME>" value="<TMPL_VAR NAME=VALUE>"/>
 </TMPL_IF>
-
+</TMPL_IF>
 </td>
 <td class="parameterUnit"><TMPL_VAR NAME=UNIT></td>
 <td class="parameterDescription">
@@ -78,9 +88,11 @@ function toggleHelp(sectionId) {
 </td>
 </tr>
 </TMPL_LOOP>
+<TMPL_UNLESS NAME=RESTRICTED>
 <tr><td class="footer" colspan="4">
 <input type="submit" value="Update"/>
 </td></tr>
+</TMPL_UNLESS>
 </form>
 </table>
 </div>
index 28ced305c9b05e54fbb555b182821329d2acc0de..60a7fdf2f1d172bb5e43512462a46079448e829a 100644 (file)
@@ -105,16 +105,18 @@ function goToPosition(row, column) {
 }
 
 </script>
-<TMPL_IF NAME=GROUP_INFOS>
+<TMPL_IF NAME=UNIT_INFOS>
 <div class="tabArea">
 <div class="tabHeader">
-<TMPL_LOOP NAME=GROUP_INFOS>
+<TMPL_LOOP NAME=UNIT_INFOS>
 <TMPL_IF NAME=SELECTED>
 <span class="selectedTab">
 <TMPL_ELSE>
 <span class="tab">
 </TMPL_IF>
-<a href="edit_vcl?group_name=<TMPL_VAR NAME=NAME>"><TMPL_VAR NAME=NAME></a>
+<a href="edit_vcl?unit_id=<TMPL_VAR NAME=ID>&is_node=<TMPL_VAR NAME=IS_NODE>">
+<TMPL_VAR NAME=NAME><TMPL_IF NAME=IS_NODE> (N)<TMPL_ELSE> (G)</TMPL_IF>
+</a>
 </span>
 </TMPL_LOOP>
 </div>
@@ -124,6 +126,7 @@ function goToPosition(row, column) {
 <table>
 <tr>
 <td>
+<TMPL_UNLESS NAME=RESTRICTED>
 <input type="button" onclick="showNewEntry();" value="New"/>
 </td>
 <td id="newVclCell" style="display: none;">
@@ -132,6 +135,7 @@ function goToPosition(row, column) {
 </td>
 <td>
 |
+</TMPL_UNLESS>
 <select name="vcl_name">
 <TMPL_LOOP NAME=VCL_INFOS>
 <option 
@@ -149,18 +153,21 @@ value="<TMPL_VAR NAME=NAME>"><TMPL_VAR NAME=NAME>
 <td>
 <input type="hidden" value="load" name="operation"/>
 <input type="submit" value="Load"/>
+<TMPL_UNLESS NAME=RESTRICTED>
 <TMPL_IF NAME=EDITING_NEW_VCL>
 <input type="button" disabled value="Make active"/>
 <TMPL_ELSE>
 <input type="button" onclick="this.form.operation.value='make_active'; this.form.submit();" value="Make active"/>
 </TMPL_IF>
-<TMPL_LOOP NAME=GROUP_INFOS>
+<TMPL_LOOP NAME=UNIT_INFOS>
 <TMPL_IF NAME=SELECTED>
-<input type="hidden" name="group_name" value="<TMPL_VAR NAME=NAME>"/>
+<input type="hidden" name="unit_id" value="<TMPL_VAR NAME=ID>"/>
+<input type="hidden" name="is_node" value="<TMPL_VAR NAME=IS_NODE>"/>
 </TMPL_IF>
 </TMPL_LOOP>
 <input type="button" onclick="this.form.operation.value='save'; this.form.submit();" value="Save"/>
-| <input type="button" onclick="this.form.operation.value='discard'; this.form.submit();" value="Discard"/>
+| <input type="button" onclick="if (confirm('Are you sure you want to discard the VCL?')){ this.form.operation.value='discard'; this.form.submit();}" value="Discard"/>
+</TMPL_UNLESS>
 </td>
 </tr>
 </table>
index 95e9cfc8ac9f6f9c24d70e67994bcfe837bef0c6..73d0b2ff9c8d4ab7195dc4d40abf46aebb2aaa1b 100644 (file)
@@ -1,3 +1,6 @@
+<TMPL_IF NAME=RESTRICTED>
+Management console disabled in restricted mode.
+<TMPL_ELSE>
 <script type="text/javascript">
 <TMPL_LOOP NAME=NODE_INFOS>
 <TMPL_IF NAME=SELECTED>
@@ -14,9 +17,11 @@ var lastMatchIndex = -1;
 var lastPartialCommand;
 var managementCommands = [
        "help",
+       "banner",
        "param.set",
        "param.show", 
        "ping",
+       "purge",
        "purge.hash",
        "purge.list",
        "purge.url",
@@ -246,3 +251,4 @@ setConsoleColors('<TMPL_VAR NAME=DEFAULT_CONSOLE_FOREGROUND>', '<TMPL_VAR NAME=D
 <TMPL_ELSE>
 No nodes to manage.
 </TMPL_IF>
+</TMPL_IF>
index 403a1cc9d067ae720a1d3a77f89b60707918767c..ff9a5feff2cf29658f9a05f21ed8b57dc82f897f 100644 (file)
@@ -8,12 +8,12 @@
 <TMPL_IF NAME=AUTO_REFRESH_INTERVAL>
 <meta http-equiv="refresh" content="<TMPL_VAR NAME=AUTO_REFRESH_INTERVAL>">
 </TMPL_IF>
-<title>Varnish - Lust controller christmas edition</title>
+<title>Varnish - Lust controller</title>
 </head>
 <body>
 <div id="canvas">
 <div id="header">
-<img id="headerLogo" src="images/varnish-logo-christmas.png" id="logo"/>
+<img id="headerLogo" src="images/varnish-logo.png" id="logo"/><br/>
 <span id="menu">
 <a href="/view_stats" class="menu">View stats</a>
 <a href="/configure_parameters" class="menu">Configure parameters</a>
index 21448a7831608ada6c5f9fb10f493a5131fc4fb0..ba78c545e067b106c5e684339004655220957430 100644 (file)
@@ -5,9 +5,10 @@
 <TMPL_ELSE>
 <span class="tab">
 </TMPL_IF>
-<a href="node_management?group=<TMPL_VAR NAME=NAME>"><TMPL_VAR NAME=NAME></a>
+<a href="node_management?group_id=<TMPL_VAR NAME=ID>"><TMPL_VAR NAME=NAME></a>
 </span>
 </TMPL_LOOP>
+<TMPL_UNLESS NAME=RESTRICTED>
 <TMPL_IF NAME=ADD_GROUP>
 <span class="selectedTab">
 <TMPL_ELSE>
 <a href="node_management?operation=add_group">Add..</a>
 </span>
 </div>
+</TMPL_UNLESS>
 <div class="tabArea">
 <TMPL_IF NAME=ADD_GROUP>
+<TMPL_UNLESS NAME=RESTRICTED>
 <form action="node_management" method="post">
 <input type="hidden" name="operation" value="add_group"/>
 <table>
-<tr><td>Name:</td><td><input name="group"/></td></tr>
+<tr><td>Name:</td><td><input name="group_name" id="group_name"/></td></tr>
 <tr><td><input type="submit" value="Add"/></td></tr>
 </table>
+<script type="text/javascript">
+document.getElementById('group_name').focus();
+</script>
+</TMPL_UNLESS>
 <TMPL_ELSE>
 <table>
 <tr>
 <td class="header">V</td>
 <td class="header">M</td>
 <td class="header">Name</td>
+<TMPL_IF NAME=SHOW_GROUP>
+<td class="header">Group</td>
+</TMPL_IF>
 <td class="header">Address</td>
 <td class="header">Port</td>
 <td class="header">Management port</td>
 <td></td></tr>
 <TMPL_LOOP NAME=NODE_INFOS>
-<tr>
+<TMPL_IF NAME=__ODD__>
+<tr class="oddRow">
+<TMPL_ELSE>
+<tr class="evenRow">
+</TMPL_IF>
 <td>
 <TMPL_IF NAME=IS_RUNNING_OK>
 <img src="images/running.png"/>
 <img src="images/stopped.png"/>
 </TMPL_IF>
 </td>
-<td><TMPL_VAR NAME=NAME></td>
+<TMPL_IF NAME=EDIT>
+<form action="node_management" method="POST">
+<td><input type="text" name="name" id="edit_node_name" value="<TMPL_VAR NAME=NAME>"/></td>
+<td>
+<select name="node_group_id">
+<TMPL_LOOP NAME=GROUP_INFOS>
+<TMPL_IF NAME=IS_REAL>
+<option 
+<TMPL_IF NAME=SELECTED>
+selected
+</TMPL_IF>
+value="<TMPL_VAR NAME=ID>">
+<TMPL_VAR NAME=NAME>
+</OPTION>
+</TMPL_IF>
+</TMPL_LOOP>
+</td>
+<td><input type="text" name="address" value="<TMPL_VAR NAME=ADDRESS>"/></td>
+<td><input type="text" name="port" value="<TMPL_VAR NAME=PORT>" size=5/></td>
+<td><input type="text" name="management_port" value="<TMPL_VAR NAME=MANAGEMENT_PORT>"/></td>
+<td>
+<input type="hidden" name="node_id" value="<TMPL_VAR NAME=ID>">
+<input type="hidden" name="group_id" value="<TMPL_VAR NAME=GROUP_ID>">
+<input type="hidden" name="operation" value="update_node">
+<input type="submit" value="Update">
+</td>
+</form>
+<TMPL_ELSE>
+
+<td>
+<a href="http://<TMPL_VAR NAME=ADDRESS>:<TMPL_VAR NAME=PORT>" target="_blank"><TMPL_VAR NAME=NAME></a></td>
+<TMPL_IF NAME=SHOW_GROUP>
+<td><TMPL_VAR NAME=GROUP></td>
+</TMPL_IF>
 <td><TMPL_VAR NAME=ADDRESS></td>
 <td><TMPL_VAR NAME=PORT></td>
-<td><TMPL_VAR NAME=MANAGEMENT_PORT></td>
+<td><a href="/management_console?node_id=<TMPL_VAR NAME=ID>"><TMPL_VAR NAME=MANAGEMENT_PORT></a></td>
+<TMPL_UNLESS NAME=RESTRICTED>
 <td>
 <form action="node_management" method="POST">
 <input type="hidden" name="node_id" value="<TMPL_VAR NAME=ID>">
 </td>
 <td>
 <form action="node_management" method="POST">
+<input type="hidden" name="group_id" value="<TMPL_VAR NAME=GROUP_ID>">
+<input type="hidden" name="edit_node" value="<TMPL_VAR NAME=ID>">
+<input type="submit" value="Edit">
+</form>
+</td>
+<td>
+<form action="node_management" method="POST">
 <input type="hidden" name="node_id" value="<TMPL_VAR NAME=ID>">
 <input type="hidden" name="operation" value="remove_node">
-<input type="submit" value="Remove" class="removeNode">
+<input type="submit" onclick="return confirm('Removing the node can not be un-done. Remove node?');"value="Remove" class="removeNode">
 </form>
 </td>
+</TMPL_UNLESS>
+
+</TMPL_IF>
 </tr>
 </TMPL_LOOP>
-</td>
+<TMPL_UNLESS NAME=RESTRICTED>
+<TMPL_IF NAME=SHOW_ADD_NODE>
+<tr><td class="addNodeBorder" colspan=20>&nbsp;</td></tr>
 <tr>
 <form action="node_management" method="post">
 <input type="hidden" name="operation" value="add_node"/>
 <td></td>
 <td></td>
-<td><input type="text" name="name"/></td>
+<td><input type="text" name="name" id="new_node_name"/></td>
+<TMPL_IF NAME=SHOW_GROUP>
+<td><TMPL_VAR NAME=GROUP_NAME></td>
+</TMPL_IF>
 <td><input type="text" name="address"/></td>
-<td><input type="text" name="port"/></td>
+<td><input type="text" name="port" size=5/></td>
 <td><input type="text" name="management_port" value="<TMPL_VAR NAME=DEFAULT_MANAGEMENT_PORT>"/></td>
+<TMPL_IF NAME=SHOW_INHERIT_SETTINGS>
+<td><input type="checkbox" name="inherit_settings" value="true" <TMPL_IF NAME=INHERIT_SETTINGS>checked</TMPL_IF>></td><td>Group inherit settings</td>
+</TMPL_IF>
 <td>
-<input type="hidden" name="group" value="<TMPL_VAR NAME=GROUP>"/>
+<input type="hidden" name="group_id" value="<TMPL_VAR NAME=GROUP_ID>"/>
 <input type="submit" value="Add"/></td>
 </tr>
+</TMPL_IF>
+</TMPL_UNLESS>
 </form>
 </table>
 <TMPL_IF NAME=BACKEND_HEALTH_INFOS>
 <table>
-<tr><td class="header">Backend</td><td class="header">Health</td></tr>
+<tr>
+<TMPL_IF NAME=SHOW_NODE_IN_BACKEND_HEALTH>
+<td class="header">Node</td>
+</TMPL_IF>
+<td class="header">Backend</td><td class="header">Health</td></tr>
 <TMPL_LOOP NAME=BACKEND_HEALTH_INFOS>
-<tr><td><TMPL_VAR NAME=NAME></td><td><TMPL_VAR NAME=HEALTH></td></tr>
+<tr>
+<TMPL_IF NAME=SHOW_NODE_IN_BACKEND_HEALTH>
+<td><TMPL_VAR NAME=NODE></td>
+</TMPL_IF>
+<td><TMPL_VAR NAME=NAME></td><td><TMPL_VAR NAME=HEALTH></td></tr>
 </TMPL_LOOP>
 </table>
 <TMPL_ELSE>
 <i>No backend health information available</i>
 </TMPL_IF>
+<TMPL_UNLESS NAME=RESTRICTED>
+<TMPL_IF NAME=SHOW_GROUP_CONTROLS>
 <div id="groupControls">
 <table>
 <tr>
 <td>
 <form action="node_management" method="POST">
-<input type="hidden" name="group" value="<TMPL_VAR NAME=GROUP>">
+<input type="hidden" name="group_id" value="<TMPL_VAR NAME=GROUP_ID>">
 <input type="hidden" name="operation" value="start_group">
 <input type="submit" value="Start group">
 </form>
 </td>
 <td>
 <form action="node_management" method="POST">
-<input type="hidden" name="group" value="<TMPL_VAR NAME=GROUP>">
+<input type="hidden" name="group_id" value="<TMPL_VAR NAME=GROUP_ID>">
 <input type="hidden" name="operation" value="stop_group">
 <input type="submit" value="Stop group">
 </form>
 </td>
 <td>
 <form action="node_management" method="POST">
-<input type="hidden" name="group" value="<TMPL_VAR NAME=GROUP>">
+<input type="text" name="group_name" value="<TMPL_VAR NAME=GROUP_NAME>">
+<input type="hidden" name="group_id" value="<TMPL_VAR NAME=GROUP_ID>">
+<input type="hidden" name="operation" value="rename_group">
+<input type="submit" value="Rename group">
+</form>
+</td>
+
+<td>
+<form action="node_management" method="POST">
+<input type="hidden" name="group_id" value="<TMPL_VAR NAME=GROUP_ID>">
 <input type="hidden" name="operation" value="remove_group">
-<input type="submit" value="Remove group" class="removeNode">
+<input type="submit" onclick="return confirm('Removing group will also remove all nodes. Remove group?');" value="Remove group" class="removeNode">
 </form>
 </td>
 </tr>
 </table>
 </div>
 </TMPL_IF>
+</TMPL_UNLESS>
+</TMPL_IF>
 </div>
+<script type="text/javascript">
+var edit_node_name = document.getElementById('edit_node_name');
+var new_node_name = document.getElementById('new_node_name');
+if (edit_node_name)
+       edit_node_name.focus();
+else if(new_node_name)
+       new_node_name.focus();
+</script>
+
index 0cb0118211695a500d58d9b1943e5e37ee6456ce..eaa0d6de6a7292971ffcafe8428240dde082caf9 100644 (file)
@@ -1,17 +1,43 @@
 <script type="text/javascript">
 
-function loadGraph(nodeId, graphId, timeSpan) {
-       var id= "img_" + nodeId + "_" + graphId;
-       var graphUrl = "/generate_graph?time_span=" + timeSpan + "&node_id=" + nodeId + "&type=" + graphId;
+function loadRawGraph(unitId, isNode, name, timeSpan, delta) {
+       var id= "graph_" + unitId + "_" + isNode + "_" + name + "_raw";
+       var imgId = "div_img_" + unitId + "_" + isNode + "_" + name + "_raw";
+       var divImgId= "div_img_" + unitId + "_" + isNode + "_" + name + "_raw";
+       var largeLinkId= "large_link_" + unitId + "_" + isNode + "_" + name + "_raw";
+       var graphUrl = 
+               "/generate_graph?time_span=" + timeSpan + "&unit_id=" + unitId + "&is_node=" + isNode +"&type=custom" + "&custom_name=" + name + "&custom_divisors=" + name + "&custom_delta=" + delta;
+       
+       var graphDiv = document.getElementById(id);
+       var divImgDiv = document.getElementById(divImgId);
+       var largeLink = document.getElementById(largeLinkId);
+
+       largeLink.href = graphUrl + "&width=<TMPL_VAR NAME=LARGE_GRAPH_WIDTH>"
+                                                       + "&height=<TMPL_VAR NAME=LARGE_GRAPH_HEIGHT>";
+       
+       graphDiv.style['display'] = 'block';
+       divImgDiv.innerHTML = 
+               "<img width=<TMPL_VAR NAME=GRAPH_WIDTH> height=<TMPL_VAR NAME=GRAPH_HEIGHT> id='" +
+               imgId + "' src='" + graphUrl + "'/>";
+}
+
+function loadGraph(unitId, isNode, graphId, timeSpan) {
+       var id= "img_" + unitId + "_" + isNode + "_" + graphId;
+       var largeLinkId= "large_link_" + unitId + "_" + isNode + "_" + graphId;
+       var graphUrl = "/generate_graph?time_span=" + timeSpan + "&unit_id=" + unitId + "&is_node=" + isNode +"&type=" + graphId;
 
        var graphImage = document.getElementById(id);
        if (graphImage) 
                graphImage.src = graphUrl;
+       var largeLink = document.getElementById(largeLinkId);
+       if (largeLink)
+               largeLink.href = graphUrl + "&width=<TMPL_VAR NAME=LARGE_GRAPH_WIDTH>"
+                                                       + "&height=<TMPL_VAR NAME=LARGE_GRAPH_HEIGHT>";
 }
 
 </script>
 
-<TMPL_IF NAME=NODE_INFOS>
+<TMPL_IF NAME=UNIT_INFOS>
 <h2> 
 <TMPL_IF NAME=STAT_TIME>
 Statistics collected at <TMPL_VAR NAME=STAT_TIME>
@@ -24,20 +50,51 @@ No statistics yet collected
 </h2>
 <table id="statsTable">
 <tr>
-<td> 
-<h2>Summary</h2>
+<td colspan=2> 
+<h2>
+Summary
+<TMPL_IF NAME=GROUP_NAME>
+for <TMPL_VAR NAME=GROUP_NAME>
+</TMPL_IF>
+</h2>
+<TMPL_IF NAME=GROUP_NAME>
+<a href="/view_stats?view_raw_stats=<TMPL_VAR NAME=VIEW_RAW_STATS>&show_group=&auto_refresh=<TMPL_VAR NAME=AUTO_REFRESH>">Back to all groups and standalones</a>
+</TMPL_IF>
 </td>
 </tr>
 <tr class="header">
 <td></td>
-<TMPL_LOOP NAME=NODE_INFOS>
-<td><TMPL_VAR NAME=NAME></td>
+<TMPL_LOOP NAME=UNIT_INFOS>
+<td class="header">
+<a href="/node_management?group_id=<TMPL_VAR NAME=GROUP_ID>">
+<img class="goToNodeManagement"
+<TMPL_IF NAME=ALL_RUNNING>
+src="images/running.png"
+<TMPL_ELSE>
+<TMPL_IF NAME=RUNNING>
+src="images/running_nok.png"
+<TMPL_ELSE>
+src="images/stopped.png"
+/>
+</TMPL_IF>
+</TMPL_IF>
+</a>
+<TMPL_VAR NAME=NAME> 
+<TMPL_IF NAME=IS_NODE>
+(N)
+<TMPL_ELSE>
+(G)<br/>
+<TMPL_UNLESS NAME=SHOW_GROUP>
+<a class="showNodeStats" href="/view_stats?view_raw_stats=<TMPL_VAR NAME=VIEW_RAW_STATS>&show_group=<TMPL_VAR NAME=UNIT_ID>&auto_refresh=<TMPL_VAR NAME=AUTO_REFRESH>">(show group)</a>
+</TMPL_UNLESS>
+</TMPL_IF>
+</td>
 </TMPL_LOOP>
 </tr>
 <tr>
 <td>
 <TMPL_LOOP NAME=SUMMARY_STATS>
-<TMPL_IF NAME=ODD_ROW>
+<TMPL_IF NAME=__ODD__>
 <tr class="oddRow">
 <TMPL_ELSE>
 <tr class="evenRow">
@@ -47,16 +104,15 @@ No statistics yet collected
 <td>
 <TMPL_IF NAME=IS_GRAPH>
 <div class="graph">
-<img id="img_<TMPL_VAR NAME=NODE_ID>_<TMPL_VAR NAME=GRAPH_ID>" src=""/><br/>
+<a id="large_link_<TMPL_VAR NAME=UNIT_ID>_<TMPL_VAR NAME=IS_NODE>_<TMPL_VAR NAME=GRAPH_ID>" href=""><img width="<TMPL_VAR NAME=GRAPH_WIDTH>" height="<TMPL_VAR NAME=GRAPH_HEIGHT>" id="img_<TMPL_VAR NAME=UNIT_ID>_<TMPL_VAR NAME=IS_NODe>_<TMPL_VAR NAME=GRAPH_ID>" src=""/></a><br/>
 Last: 
-<a class="timeSpan" id="link_<TMPL_VAR NAME=NODE_ID>_<TMPL_VAR NAME=GRAPH_ID>" href="javascript:loadGraph('<TMPL_VAR NAME=NODE_ID>', '<TMPL_VAR NAME=GRAPH_ID>', 'minute')">Mi</a>
-<a class="timeSpan" id="link_<TMPL_VAR NAME=NODE_ID>_<TMPL_VAR NAME=GRAPH_ID>_hour" href="javascript:loadGraph('<TMPL_VAR NAME=NODE_ID>', '<TMPL_VAR NAME=GRAPH_ID>', 'hour')">H</a>
-<a class="timeSpan" id="link_<TMPL_VAR NAME=NODE_ID>_<TMPL_VAR NAME=GRAPH_ID>_hour" href="javascript:loadGraph('<TMPL_VAR NAME=NODE_ID>', '<TMPL_VAR NAME=GRAPH_ID>', 'day')">D</a>
-<a class="timeSpan" id="link_<TMPL_VAR NAME=NODE_ID>_<TMPL_VAR NAME=GRAPH_ID>_hour" href="javascript:loadGraph('<TMPL_VAR NAME=NODE_ID>', '<TMPL_VAR NAME=GRAPH_ID>', 'week')">W</a>
-<a class="timeSpan" id="link_<TMPL_VAR NAME=NODE_ID>_<TMPL_VAR NAME=GRAPH_ID>_hour" href="javascript:loadGraph('<TMPL_VAR NAME=NODE_ID>', '<TMPL_VAR NAME=GRAPH_ID>', 'month')">Mo</a>
+<a class="timeSpan" href="javascript:loadGraph('<TMPL_VAR NAME=UNIT_ID>', '<TMPL_VAR NAME=IS_NODE>', '<TMPL_VAR NAME=GRAPH_ID>', 'minute')">Mi</a>
+<a class="timeSpan" href="javascript:loadGraph('<TMPL_VAR NAME=UNIT_ID>', '<TMPL_VAR NAME=IS_NODE>', '<TMPL_VAR NAME=GRAPH_ID>', 'hour')">H</a>
+<a class="timeSpan" href="javascript:loadGraph('<TMPL_VAR NAME=UNIT_ID>', '<TMPL_VAR NAME=IS_NODE>', '<TMPL_VAR NAME=GRAPH_ID>', 'day')">D</a>
+<a class="timeSpan" href="javascript:loadGraph('<TMPL_VAR NAME=UNIT_ID>', '<TMPL_VAR NAME=IS_NODE>', '<TMPL_VAR NAME=GRAPH_ID>', 'week')">W</a>
 </div>
 <script type="text/javascript">
-loadGraph('<TMPL_VAR NAME=NODE_ID>', '<TMPL_VAR NAME=GRAPH_ID>', 'minute');
+loadGraph('<TMPL_VAR NAME=UNIT_ID>', '<TMPL_VAR NAME=IS_NODE>', '<TMPL_VAR NAME=GRAPH_ID>', 'minute');
 </script>
 <TMPL_ELSE>
 <TMPL_VAR NAME=VALUE>
@@ -71,29 +127,51 @@ loadGraph('<TMPL_VAR NAME=NODE_ID>', '<TMPL_VAR NAME=GRAPH_ID>', 'minute');
 <tr>
 <td>
 <TMPL_LOOP NAME=RAW_STATS>
-<TMPL_IF NAME=ODD_ROW>
+<TMPL_IF NAME=__ODD__>
 <tr class="oddRow">
 <TMPL_ELSE>
 <tr class="evenRow">
 </TMPL_IF>
 <td><TMPL_VAR NAME=NAME></td>
 <TMPL_LOOP NAME=VALUES>
-<td><TMPL_VAR NAME=VALUE></td>
+<td>
+<a href="javascript:loadRawGraph('<TMPL_VAR NAME=UNIT_ID>','<TMPL_VAR NAME=IS_NODE>','<TMPL_VAR NAME=NAME>', 'minute', 0)">
+<TMPL_VAR NAME=VALUE>
+</a>
+<div class="graph" id="graph_<TMPL_VAR NAME=UNIT_ID>_<TMPL_VAR NAME=IS_NODE>_<TMPL_VAR NAME=NAME>_raw" style="display: none">
+<a id="large_link_<TMPL_VAR NAME=UNIT_ID>_<TMPL_VAR NAME=IS_NODE>_<TMPL_VAR NAME=NAME>_raw" href="">
+<div id="div_img_<TMPL_VAR NAME=UNIT_ID>_<TMPL_VAR NAME=IS_NODE>_<TMPL_VAR NAME=NAME>_raw">
+</div>
+</a><br/>
+Last: 
+<a class="timeSpan" href="javascript:loadRawGraph('<TMPL_VAR NAME=UNIT_ID>', '<TMPL_VAR NAME=IS_NODE>', '<TMPL_VAR NAME=NAME>', 'minute', 0)">Mi</a>
+<a class="timeSpan" href="javascript:loadRawGraph('<TMPL_VAR NAME=UNIT_ID>', '<TMPL_VAR NAME=IS_NODE>', '<TMPL_VAR NAME=NAME>', 'hour', 0)">H</a>
+<a class="timeSpan" href="javascript:loadRawGraph('<TMPL_VAR NAME=UNIT_ID>', '<TMPL_VAR NAME=IS_NODE>', '<TMPL_VAR NAME=NAME>', 'day', 0)">D</a>
+<a class="timeSpan" href="javascript:loadRawGraph('<TMPL_VAR NAME=UNIT_ID>', '<TMPL_VAR NAME=IS_NODE>', '<TMPL_VAR NAME=NAME>', 'week', 0)">W</a><br/>
+Delta: 
+<a class="timeSpan" href="javascript:loadRawGraph('<TMPL_VAR NAME=UNIT_ID>', '<TMPL_VAR NAME=IS_NODE>', '<TMPL_VAR NAME=NAME>', 'minute', 1)">Mi</a>
+<a class="timeSpan" href="javascript:loadRawGraph('<TMPL_VAR NAME=UNIT_ID>', '<TMPL_VAR NAME=IS_NODE>', '<TMPL_VAR NAME=NAME>', 'hour', 1)">H</a>
+<a class="timeSpan" href="javascript:loadRawGraph('<TMPL_VAR NAME=UNIT_ID>', '<TMPL_VAR NAME=IS_NODE>', '<TMPL_VAR NAME=NAME>', 'day', 1)">D</a>
+<a class="timeSpan" href="javascript:loadRawGraph('<TMPL_VAR NAME=UNIT_ID>', '<TMPL_VAR NAME=IS_NODE>', '<TMPL_VAR NAME=NAME>', 'week', 1)">W</a>
+</div>
+
+</td>
 </TMPL_LOOP>
 </tr>
 </TMPL_LOOP>
 </table>
-Raw statistics: On <a href="/view_stats?view_raw_stats=0&auto_refresh=<TMPL_VAR NAME=AUTO_REFRESH>">Off</a>
+Raw statistics: On <a href="/view_stats?view_raw_stats=0&show_group=<TMPL_VAR NAME=SHOW_GROUP>&auto_refresh=<TMPL_VAR NAME=AUTO_REFRESH>">Off</a>
 <TMPL_ELSE>
 </table>
-Raw statistics: <a href="/view_stats?view_raw_stats=1&auto_refresh=<TMPL_VAR NAME=AUTO_REFRESH>">On</a> Off
+Raw statistics: <a href="/view_stats?view_raw_stats=1&show_group=<TMPL_VAR NAME=SHOW_GROUP>&auto_refresh=<TMPL_VAR NAME=AUTO_REFRESH>">On</a> Off
 </TMPL_IF>
 | Auto refresh: 
 <TMPL_IF NAME=AUTO_REFRESH>
-On <a href="/view_stats?view_raw_stats=<TMPL_VAR NAME=VIEW_RAW_STATS>&auto_refresh=0">Off</a>
+On <a href="/view_stats?view_raw_stats=<TMPL_VAR NAME=VIEW_RAW_STATS>&show_group=<TMPL_VAR NAME=SHOW_GROUP>&auto_refresh=0">Off</a>
 <TMPL_ELSE>
-<a href="/view_stats?view_raw_stats=<TMPL_VAR NAME=VIEW_RAW_STATS>&auto_refresh=1">On</a> Off
+<a href="/view_stats?view_raw_stats=<TMPL_VAR NAME=VIEW_RAW_STATS>&show_group=<TMPL_VAR NAME=SHOW_GROUP>&auto_refresh=1">On</a> Off
 </TMPL_IF>
+| <a href="/view_stats?csv=1&show_group=<TMPL_VAR NAME=SHOW_GROUP>">Raw data as CSV</a>
 <TMPL_ELSE>
 No nodes available
 </TMPL_IF>
diff --git a/varnish-tools/webgui/templates/view_stats_csv.tmpl b/varnish-tools/webgui/templates/view_stats_csv.tmpl
new file mode 100644 (file)
index 0000000..288d3d1
--- /dev/null
@@ -0,0 +1,2 @@
+<TMPL_LOOP NAME=ROWS><TMPL_VAR NAME=UNIT><TMPL_LOOP NAME=VALUES>;<TMPL_VAR NAME=VALUE></TMPL_LOOP>
+</TMPL_LOOP>
diff --git a/varnish-tools/webgui/varnish_webgui.sql b/varnish-tools/webgui/varnish_webgui.sql
new file mode 100644 (file)
index 0000000..b7b750f
--- /dev/null
@@ -0,0 +1,247 @@
+-- This file was auto generated Wed Feb 18 15:58:37 2009 by create_db_files.pl
+DROP TABLE node_group;
+DROP TABLE node;
+DROP TABLE stat;
+DROP TABLE parameters;
+DROP TABLE parameter_info;
+DROP TABLE vcl;
+
+CREATE TABLE node_group (
+       id INTEGER PRIMARY KEY,
+       active_vcl TEXT,
+       name text
+);
+
+CREATE TABLE node (
+       id INTEGER PRIMARY KEY,
+       name TEXT,
+       address TEXT,
+       port TEXT,
+       group_id INTEGER,
+       management_port TEXT,
+       is_master BOOLEAN
+);
+
+CREATE TABLE stat (
+       id INTEGER PRIMARY KEY,
+       time TIMESTAMP,
+       node_id INTEGER,
+session_pipeline INTEGER,
+shm_mtx_contention INTEGER,
+n_overflowed_work_requests INTEGER,
+backend_connections_failures INTEGER,
+n_worker_threads_limited INTEGER,
+sma_outstanding_bytes INTEGER,
+backend_connections_too_many INTEGER,
+shm_cycles_through_buffer INTEGER,
+esi_parse_errors__unlock_ INTEGER,
+total_pipe INTEGER,
+n_worker_threads_created INTEGER,
+objects_sent_with_write INTEGER,
+backend_connections_success INTEGER,
+n_dropped_work_requests INTEGER,
+objects_overflowing_workspace INTEGER,
+sms_outstanding_bytes INTEGER,
+client_requests_received INTEGER,
+n_objects_on_deathrow INTEGER,
+n_total_active_purges INTEGER,
+backend_requests_made INTEGER,
+bytes_allocated INTEGER,
+outstanding_allocations INTEGER,
+objects_esi_parsed__unlock_ INTEGER,
+n_struct_vbe_conn INTEGER,
+cache_hits_for_pass INTEGER,
+n_lru_saved_objects INTEGER,
+cache_hits INTEGER,
+sma_outstanding_allocations INTEGER,
+total_pass INTEGER,
+backend_connections_reuses INTEGER,
+backend_connections_not_attempted INTEGER,
+shm_flushes_due_to_overflow INTEGER,
+n_duplicate_purges_removed INTEGER,
+n_new_purges_added INTEGER,
+session_closed INTEGER,
+cache_misses INTEGER,
+n_struct_srcaddr INTEGER,
+sms_allocator_requests INTEGER,
+session_herd INTEGER,
+n_worker_threads_not_created INTEGER,
+n_vcl_discarded INTEGER,
+hcb_lookups_without_lock INTEGER,
+n_worker_threads INTEGER,
+n_lru_nuked_objects INTEGER,
+n_queued_work_requests INTEGER,
+total_sessions INTEGER,
+total_header_bytes INTEGER,
+n_objects_tested INTEGER,
+n_active_struct_srcaddr INTEGER,
+bytes_free INTEGER,
+n_vcl_total INTEGER,
+n_backends INTEGER,
+sma_bytes_free INTEGER,
+total_body_bytes INTEGER,
+shm_records INTEGER,
+n_vcl_available INTEGER,
+sma_bytes_allocated INTEGER,
+objects_sent_with_sendfile INTEGER,
+hcb_lookups_with_lock INTEGER,
+n_struct_sess_mem INTEGER,
+client_connections_accepted INTEGER,
+n_struct_bereq INTEGER,
+sms_bytes_freed INTEGER,
+sms_outstanding_allocations INTEGER,
+sms_bytes_allocated INTEGER,
+n_small_free_smf INTEGER,
+n_struct_objecthead INTEGER,
+total_fetch INTEGER,
+sma_allocator_requests INTEGER,
+backend_connections_recycles INTEGER,
+backend_connections_unused INTEGER,
+shm_writes INTEGER,
+n_struct_object INTEGER,
+total_requests INTEGER,
+hcb_inserts INTEGER,
+n_lru_moved_objects INTEGER,
+n_struct_sess INTEGER,
+allocator_requests INTEGER,
+n_regexps_tested_against INTEGER,
+n_expired_objects INTEGER,
+http_header_overflows INTEGER,
+n_struct_smf INTEGER,
+n_old_purges_deleted INTEGER,
+n_large_free_smf INTEGER,
+session_read_ahead INTEGER,
+session_linger INTEGER,
+
+       has_data INTEGER
+);
+
+CREATE TABLE parameters (
+       id INTEGER PRIMARY KEY,
+accept_fd_holdoff TEXT,
+auto_restart TEXT,
+backend_http11 TEXT,
+between_bytes_timeout TEXT,
+cache_vbe_conns TEXT,
+cc_command TEXT,
+cli_banner TEXT,
+cli_buffer TEXT,
+cli_timeout TEXT,
+client_http11 TEXT,
+clock_skew TEXT,
+connect_timeout TEXT,
+default_grace TEXT,
+default_ttl TEXT,
+diag_bitmap TEXT,
+err_ttl TEXT,
+esi_syntax TEXT,
+fetch_chunksize TEXT,
+first_byte_timeout TEXT,
+child_group TEXT,
+listen_address TEXT,
+listen_depth TEXT,
+log_hashstring TEXT,
+log_local_address TEXT,
+lru_interval TEXT,
+max_esi_includes TEXT,
+max_restarts TEXT,
+obj_workspace TEXT,
+overflow_max TEXT,
+ping_interval TEXT,
+pipe_timeout TEXT,
+prefer_ipv6 TEXT,
+purge_dups TEXT,
+purge_hash TEXT,
+rush_exponent TEXT,
+send_timeout TEXT,
+sess_timeout TEXT,
+sess_workspace TEXT,
+session_linger TEXT,
+shm_reclen TEXT,
+shm_workspace TEXT,
+srcaddr_hash TEXT,
+srcaddr_ttl TEXT,
+thread_pool_add_delay TEXT,
+thread_pool_add_threshold TEXT,
+thread_pool_fail_delay TEXT,
+thread_pool_max TEXT,
+thread_pool_min TEXT,
+thread_pool_purge_delay TEXT,
+thread_pool_timeout TEXT,
+thread_pools TEXT,
+child_user TEXT,
+vcl_trace TEXT,
+waiter TEXT,
+
+       group_id INTEGER
+);
+
+CREATE TABLE vcl(
+       group_id INTEGER,
+       name TEXT,
+       vcl TEXT
+);
+
+CREATE TABLE parameter_info(
+       name TEXT PRIMARY KEY,
+       unit TEXT,
+       description TEXT
+);
+
+INSERT INTO node_group VALUES(0, 0, 'Standalone');
+
+INSERT INTO parameter_info VALUES('accept_fd_holdoff', 'ms', 'Default is 50. If we run out of file descriptors, the accept thread will sleep.  This parameter control for how long it will sleep.   NB: We do not know yet if it is a good idea to change this parameter, or if the default value is even sensible.  Caution is advised, and feedback is most welcome. ');
+INSERT INTO parameter_info VALUES('auto_restart', 'bool', 'Default is on. Restart child process automatically if it dies. ');
+INSERT INTO parameter_info VALUES('backend_http11', 'bool', 'Default is on. Force all backend requests to be HTTP/1.1. By default we copy the protocol version from the incoming client request.   NB: We do not know yet if it is a good idea to change this parameter, or if the default value is even sensible.  Caution is advised, and feedback is most welcome. ');
+INSERT INTO parameter_info VALUES('between_bytes_timeout', 's', 'Default is 60. Default timeout between bytes when receiving data from backend. We only wait for this many seconds between bytes before giving up. A value of 0 means it will never time out. VCL can override this default value for each backend request and backend request. This parameter does not apply to pipe. ');
+INSERT INTO parameter_info VALUES('cache_vbe_conns', 'bool', 'Default is off. Cache vbe_conn''s or rely on malloc, that''s the question.   NB: We do not know yet if it is a good idea to change this parameter, or if the default value is even sensible.  Caution is advised, and feedback is most welcome. ');
+INSERT INTO parameter_info VALUES('cc_command', '', 'Default is exec cc -fpic -shared -Wl,-x -o %o %s. Command used for compiling the C source code to a dlopen(3) loadable object.  Any occurrence of %s in the string will be replaced with the source file name, and %o will be replaced with the output file name.   NB: This parameter will not take any effect until the VCL programs have been reloaded. ');
+INSERT INTO parameter_info VALUES('cli_banner', 'bool', 'Default is on. Emit CLI banner on connect. Set to off for compatibility with pre 2.1 versions. ');
+INSERT INTO parameter_info VALUES('cli_buffer', 'bytes', 'Default is 8192. Size of buffer for CLI input. You may need to increase this if you have big VCL files and use the vcl.inline CLI command. NB: Must be specified with -p to have effect. ');
+INSERT INTO parameter_info VALUES('cli_timeout', 'seconds', 'Default is 5. Timeout for the childs replies to CLI requests from the master. ');
+INSERT INTO parameter_info VALUES('client_http11', 'bool', 'Default is off. Force all client responses to be HTTP/1.1. By default we copy the protocol version from the backend response.   NB: We do not know yet if it is a good idea to change this parameter, or if the default value is even sensible.  Caution is advised, and feedback is most welcome. ');
+INSERT INTO parameter_info VALUES('clock_skew', 's', 'Default is 10. How much clockskew we are willing to accept between the backend and our own clock. ');
+INSERT INTO parameter_info VALUES('connect_timeout', 's', 'Default is 0.4. Default connection timeout for backend connections. We only try to connect to the backend for this many seconds before giving up. VCL can override this default value for each backend and backend request. ');
+INSERT INTO parameter_info VALUES('default_grace', '', 'Default is 10seconds. Default grace period.  We will deliver an object this long after it has expired, provided another thread is attempting to get a new copy.   NB: This parameter may take quite some time to take (full) effect. ');
+INSERT INTO parameter_info VALUES('default_ttl', 'seconds', 'Default is 120. The TTL assigned to objects if neither the backend nor the VCL code assigns one. Objects already cached will not be affected by changes made until they are fetched from the backend again. To force an immediate effect at the expense of a total flush of the cache use "url.purge ." ');
+INSERT INTO parameter_info VALUES('diag_bitmap', 'bitmap', 'Default is 0. Bitmap controlling diagnostics code: 0x00000001 - CNT_Session states. 0x00000002 - workspace debugging. 0x00000004 - kqueue debugging. 0x00000008 - mutex logging. 0x00000010 - mutex contests. 0x00000020 - waiting list. 0x00000040 - object workspace. 0x00001000 - do not core-dump child process. 0x00002000 - only short panic message. 0x00004000 - panic to stderr. 0x00010000 - synchronize shmlog. Use 0x notation and do the bitor in your head :-) ');
+INSERT INTO parameter_info VALUES('err_ttl', 'seconds', 'Default is 0. The TTL assigned to the synthesized error pages ');
+INSERT INTO parameter_info VALUES('esi_syntax', 'bitmap', 'Default is 0. Bitmap controlling ESI parsing code: 0x00000001 - Don''t check if it looks like XML 0x00000002 - Ignore non-esi elements 0x00000004 - Emit parsing debug records Use 0x notation and do the bitor in your head :-) ');
+INSERT INTO parameter_info VALUES('fetch_chunksize', 'kilobytes', 'Default is 128. The default chunksize used by fetcher. This should be bigger than the majority of objects with short TTLs. Internal limits in the storage_file module makes increases above 128kb a dubious idea.   NB: We do not know yet if it is a good idea to change this parameter, or if the default value is even sensible.  Caution is advised, and feedback is most welcome. ');
+INSERT INTO parameter_info VALUES('first_byte_timeout', 's', 'Default is 60. Default timeout for receiving first byte from backend. We only wait for this many seconds for the first byte before giving up. A value of 0 means it will never time out. VCL can override this default value for each backend and backend request. This parameter does not apply to pipe. ');
+INSERT INTO parameter_info VALUES('child_group', '', 'Default is \ 1. The unprivileged group to run as.   NB: This parameter will not take any effect until the child process has been restarted. ');
+INSERT INTO parameter_info VALUES('listen_address', '', 'Default is :80. Whitespace separated list of network endpoints where Varnish will accept requests. Possible formats: host, host:port, :port   NB: This parameter will not take any effect until the child process has been restarted. ');
+INSERT INTO parameter_info VALUES('listen_depth', 'connections', 'Default is 1024. Listen queue depth.   NB: This parameter will not take any effect until the child process has been restarted. ');
+INSERT INTO parameter_info VALUES('log_hashstring', 'bool', 'Default is off. Log the hash string to shared memory log. ');
+INSERT INTO parameter_info VALUES('log_local_address', 'bool', 'Default is off. Log the local address on the TCP connection in the SessionOpen shared memory record. ');
+INSERT INTO parameter_info VALUES('lru_interval', 'seconds', 'Default is 2. Grace period before object moves on LRU list. Objects are only moved to the front of the LRU list if they have not been moved there already inside this timeout period.  This reduces the amount of lock operations necessary for LRU list access.   NB: We do not know yet if it is a good idea to change this parameter, or if the default value is even sensible.  Caution is advised, and feedback is most welcome. ');
+INSERT INTO parameter_info VALUES('max_esi_includes', 'includes', 'Default is 5. Maximum depth of esi:include processing. ');
+INSERT INTO parameter_info VALUES('max_restarts', 'restarts', 'Default is 4. Upper limit on how many times a request can restart. Be aware that restarts are likely to cause a hit against the backend, so don''t increase thoughtlessly. ');
+INSERT INTO parameter_info VALUES('obj_workspace', 'bytes', 'Default is 8192. Bytes of HTTP protocol workspace allocated for objects. This space must be big enough for the entire HTTP protocol header and any edits done to it in the VCL code while it is cached. Minimum is 1024 bytes.   NB: This parameter may take quite some time to take (full) effect. ');
+INSERT INTO parameter_info VALUES('overflow_max', '%', 'Default is 100. Percentage permitted overflow queue length.   This sets the ratio of queued requests to worker threads, above which sessions will be dropped instead of queued.   NB: We do not know yet if it is a good idea to change this parameter, or if the default value is even sensible.  Caution is advised, and feedback is most welcome. ');
+INSERT INTO parameter_info VALUES('ping_interval', 'seconds', 'Default is 3. Interval between pings from parent to child. Zero will disable pinging entirely, which makes it possible to attach a debugger to the child.   NB: This parameter will not take any effect until the child process has been restarted. ');
+INSERT INTO parameter_info VALUES('pipe_timeout', 'seconds', 'Default is 60. Idle timeout for PIPE sessions. If nothing have been received in either direction for this many seconds, the session is closed. ');
+INSERT INTO parameter_info VALUES('prefer_ipv6', 'bool', 'Default is off. Prefer IPv6 address when connecting to backends which have both IPv4 and IPv6 addresses. ');
+INSERT INTO parameter_info VALUES('purge_dups', 'bool', 'Default is off. Detect and eliminate duplicate purges. ');
+INSERT INTO parameter_info VALUES('purge_hash', 'bool', 'Default is off. Enable purge.hash command. NB: this increases storage requirement per object by the length of the hash string.   NB: This parameter will not take any effect until the child process has been restarted. ');
+INSERT INTO parameter_info VALUES('rush_exponent', 'requests per request', 'Default is 3. How many parked request we start for each completed request on the object. NB: Even with the implict delay of delivery, this parameter controls an exponential increase in number of worker threads.     NB: We do not know yet if it is a good idea to change this parameter, or if the default value is even sensible.  Caution is advised, and feedback is most welcome. ');
+INSERT INTO parameter_info VALUES('send_timeout', 'seconds', 'Default is 600. Send timeout for client connections. If no data has been sent to the client in this many seconds, the session is closed. See setsockopt(2) under SO_SNDTIMEO for more information.   NB: This parameter may take quite some time to take (full) effect. ');
+INSERT INTO parameter_info VALUES('sess_timeout', 'seconds', 'Default is 5. Idle timeout for persistent sessions. If a HTTP request has not been received in this many seconds, the session is closed. ');
+INSERT INTO parameter_info VALUES('sess_workspace', 'bytes', 'Default is 16384. Bytes of HTTP protocol workspace allocated for sessions. This space must be big enough for the entire HTTP protocol header and any edits done to it in the VCL code. Minimum is 1024 bytes.   NB: This parameter may take quite some time to take (full) effect. ');
+INSERT INTO parameter_info VALUES('session_linger', 'ms', 'Default is 0. How long time the workerthread lingers on the session to see if a new request appears right away. If sessions are reused, as much as half of all reuses happen within the first 100 msec of the previous request completing. Setting this too high results in worker threads not doing anything for their keep, setting it too low just means that more sessions take a detour around the waiter.   NB: We do not know yet if it is a good idea to change this parameter, or if the default value is even sensible.  Caution is advised, and feedback is most welcome. ');
+INSERT INTO parameter_info VALUES('shm_reclen', 'bytes', 'Default is 255. Maximum number of bytes in SHM log record. Maximum is 65535 bytes. ');
+INSERT INTO parameter_info VALUES('shm_workspace', 'bytes', 'Default is 8192. Bytes of shmlog workspace allocated for worker threads. If too big, it wastes some ram, if too small it causes needless flushes of the SHM workspace. These flushes show up in stats as "SHM flushes due to overflow". Minimum is 4096 bytes.   NB: This parameter may take quite some time to take (full) effect. ');
+INSERT INTO parameter_info VALUES('srcaddr_hash', 'buckets', 'Default is 1049. Number of source address hash buckets. Powers of two are bad, prime numbers are good.   NB: We do not know yet if it is a good idea to change this parameter, or if the default value is even sensible.  Caution is advised, and feedback is most welcome.   NB: This parameter will not take any effect until the child process has been restarted. ');
+INSERT INTO parameter_info VALUES('srcaddr_ttl', 'seconds', 'Default is 30. Lifetime of srcaddr entries. Zero will disable srcaddr accounting entirely.   NB: We do not know yet if it is a good idea to change this parameter, or if the default value is even sensible.  Caution is advised, and feedback is most welcome. ');
+INSERT INTO parameter_info VALUES('thread_pool_add_delay', 'milliseconds', 'Default is 20. Wait at least this long between creating threads.   Setting this too long results in insuffient worker threads.   Setting this too short increases the risk of worker thread pile-up.   NB: We do not know yet if it is a good idea to change this parameter, or if the default value is even sensible.  Caution is advised, and feedback is most welcome. ');
+INSERT INTO parameter_info VALUES('thread_pool_add_threshold', 'requests', 'Default is 2. Overflow threshold for worker thread creation.   Setting this too low, will result in excess worker threads, which is generally a bad idea.   Setting it too high results in insuffient worker threads.   NB: We do not know yet if it is a good idea to change this parameter, or if the default value is even sensible.  Caution is advised, and feedback is most welcome. ');
+INSERT INTO parameter_info VALUES('thread_pool_fail_delay', 'milliseconds', 'Default is 200. Wait at least this long after a failed thread creation before trying to create another thread.   Failure to create a worker thread is often a sign that  the end is near, because the process is running out of RAM resources for thread stacks. This delay tries to not rush it on needlessly.   If thread creation failures are a problem, check that thread_pool_max is not too high.   It may also help to increase thread_pool_timeout and thread_pool_min, to reduce the rate at which treads are destroyed and later recreated.   NB: We do not know yet if it is a good idea to change this parameter, or if the default value is even sensible.  Caution is advised, and feedback is most welcome. ');
+INSERT INTO parameter_info VALUES('thread_pool_max', 'threads', 'Default is 500. The maximum number of worker threads in all pools combined.   Do not set this higher than you have to, since excess worker threads soak up RAM and CPU and generally just get in the way of getting work done.   NB: This parameter may take quite some time to take (full) effect.   NB: We do not know yet if it is a good idea to change this parameter, or if the default value is even sensible.  Caution is advised, and feedback is most welcome. ');
+INSERT INTO parameter_info VALUES('thread_pool_min', 'threads', 'Default is 5. The minimum number of threads in each worker pool.   Increasing this may help ramp up faster from low load situations where threads have expired.   Minimum is 2 threads.   NB: This parameter may take quite some time to take (full) effect.   NB: We do not know yet if it is a good idea to change this parameter, or if the default value is even sensible.  Caution is advised, and feedback is most welcome. ');
+INSERT INTO parameter_info VALUES('thread_pool_purge_delay', 'milliseconds', 'Default is 1000. Wait this long between purging threads.   This controls the decay of thread pools when idle(-ish).   Minimum is 100 milliseconds.   NB: This parameter may take quite some time to take (full) effect.   NB: We do not know yet if it is a good idea to change this parameter, or if the default value is even sensible.  Caution is advised, and feedback is most welcome. ');
+INSERT INTO parameter_info VALUES('thread_pool_timeout', 'seconds', 'Default is 300. Thread idle threshold.   Threads in excess of thread_pool_min, which have been idle for at least this long are candidates for purging.   Minimum is 1 second.   NB: This parameter may take quite some time to take (full) effect.   NB: We do not know yet if it is a good idea to change this parameter, or if the default value is even sensible.  Caution is advised, and feedback is most welcome. ');
+INSERT INTO parameter_info VALUES('thread_pools', 'pools', 'Default is 2. Number of worker thread pools.   Increasing number of worker pools decreases lock contention.   Too many pools waste CPU and RAM resources, and more than one pool for each CPU is probably detrimal to performance.   Can be increased on the fly, but decreases require a restart to take effect.   NB: This parameter may take quite some time to take (full) effect.   NB: We do not know yet if it is a good idea to change this parameter, or if the default value is even sensible.  Caution is advised, and feedback is most welcome. ');
+INSERT INTO parameter_info VALUES('child_user', '', 'Default is \ 1. The unprivileged user to run as.  Setting this will also set "group" to the specified user''s primary group.   NB: This parameter will not take any effect until the child process has been restarted. ');
+INSERT INTO parameter_info VALUES('vcl_trace', 'bool', 'Default is off. Trace VCL execution in the shmlog. Enabling this will allow you to see the path each request has taken through the VCL program. This generates a lot of logrecords so it is off by default. ');
+INSERT INTO parameter_info VALUES('waiter', '', 'Default is default. Select the waiter kernel interface.   NB: We do not know yet if it is a good idea to change this parameter, or if the default value is even sensible.  Caution is advised, and feedback is most welcome.   NB: This parameter will not take any effect until the child process has been restarted. ');
+