From c8d88c62dd2f6c651d7933e8186dbf575d04c136 Mon Sep 17 00:00:00 2001 From: Jeroen Vermeulen Date: Sat, 2 Aug 2014 17:39:43 +0200 Subject: [PATCH 1/4] First version of the Munin plugin to monitor HHVM --- plugins/hhvm/hhvm_ | 142 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100755 plugins/hhvm/hhvm_ diff --git a/plugins/hhvm/hhvm_ b/plugins/hhvm/hhvm_ new file mode 100755 index 00000000..d50a0f55 --- /dev/null +++ b/plugins/hhvm/hhvm_ @@ -0,0 +1,142 @@ +#!/usr/bin/env perl + +=head1 NAME + +hhvm_ - Munin plugin to monitor HHVM. + +=head1 LICENCE + +This source file is subject to the Open Software License (OSL 3.0) +Which is available through the world-wide-web at this URL: +http://opensource.org/licenses/osl-3.0.php + +Copyright (c) 2014 Jeroen Vermeulen - http://www.jeroenvermeulen.eu + +=head1 USAGE + +- You need HHVM 3.0 or greater. +- The HHVM AdminServer needs to be locally accessible via HTTP. +- Since version 3.0 HHVM has no longer a built-in webserver. Not even for the AdminServer. +- You will need to configure a special HHVM Admin webserver like Apache or Nginx, and connect it via FastCGI to the HHVM AdminServer Port. More info below. +- You can use the HHVM Config setting "AdminServer.Port" or ini variable "hhvm.admin_server.port" to choose that port. For example 8080. +- Copy this file to "/usr/share/munin/plugins/hhvm_". +- Create a symlink in "/etc/munin/plugins" +- By default this script will try to connect to a webserver on 127.0.0.1 port 8081. +- You can make it connect to another IP and port by naming the symlink "hhvm_[IP]_[PORT]", for example hhvm_11.22.33.44_8081 +- You can also use the plugin config to set "env.host" and "env.port" + +=head1 NGINX FASTCGI CONFIG + +server { + listen 127.0.0.1:8081 default; + location ~ { + fastcgi_pass 127.0.0.1:8080; + include fastcgi_params; + } +} + +=head1 APACHE 2.2 FASTCGI CONFIG + +FastCgiExternalServer /var/run/hhvm_admin.fcgi -host 127.0.0.1:8080 +Listen 127.0.0.1:8081 + + Alias /check-health /var/run/hhvm_admin.fcgi + Alias /status.json /var/run/hhvm_admin.fcgi + Alias / /var/run/hhvm_admin.fcgi + + +=cut + +use warnings; +use strict; +# use lib $ENV{'MUNIN_LIBDIR'}; +use Munin::Plugin; +use LWP::Simple; +use JSON::PP; + +sub getJson( $ ); + +my $script = $0; +my $host = '127.0.0.1'; +my $port = 8081; + +if ( $script =~ /\bhhvm_([a-z0-9\-\.]+)(?:_(\d+))?$/ ) { + $host = $1; + if ( $2 ) { + $port = int( $2 ); + } +} + +$host = defined $ENV{'host'} ? $ENV{'host'} : $host; +$port = defined $ENV{'port'} ? $ENV{'port'} : $port; + +if ( exists $ARGV[0] && 'config' eq $ARGV[0] ) { + print <{'status'}->{'threads'} } ) ); + printf( "load.value %d\n", $health->{'load'} ); + printf( "queued.value %d\n", $health->{'queued'} ); + print "\n"; + + print "multigraph hhvm_sizes\n"; + printf( "hhbc-roarena-capac.value %d\n", $health->{'hhbc-roarena-capac'} ); + printf( "tc-hotsize.value %d\n", $health->{'tc-hotsize'} ); + printf( "tc-size.value %d\n", $health->{'tc-size'} ); + printf( "tc-profsize.value %d\n", $health->{'tc-profsize'} ); + printf( "tc-coldsize.value %d\n", $health->{'tc-coldsize'} ); + printf( "tc-trampolinessize.value %d\n", $health->{'tc-trampolinessize'} ); + printf( "tc-frozensize.value %d\n", $health->{'tc-frozensize'} ); + printf( "rds.value %d\n", $health->{'rds'} ); + printf( "units.value %d\n", $health->{'units'} ); + printf( "funcs.value %d\n", $health->{'funcs'} ); +} + +exit 0; + +sub getJson( $ ) { + my ( $url ) = @_; + my $json = get( $url ); + if ( ! $json ) { + die( sprintf( "Could not get json from '%s'.", $url ) ); + } + my $data = decode_json( $json ); + if ( ! $data || 'HASH' ne ref($data) ) { + die( sprintf( "Could not decode json from '%s'.", $url ) ); + } + return $data; +} \ No newline at end of file From 4a214b006b988efd854c105f435e95e8df0d3c98 Mon Sep 17 00:00:00 2001 From: Jeroen Vermeulen Date: Sun, 3 Aug 2014 22:27:04 +0200 Subject: [PATCH 2/4] Removed load warning level --- plugins/hhvm/hhvm_ | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/hhvm/hhvm_ b/plugins/hhvm/hhvm_ index d50a0f55..a38e755a 100755 --- a/plugins/hhvm/hhvm_ +++ b/plugins/hhvm/hhvm_ @@ -77,7 +77,6 @@ graph_title HHVM Threads ${host}:${port} graph_args --base 1000 graph_category hhvm threads.label Threads -load.warning 10 load.label Active Workers queued.label Queued Jobs From 2fe6d91bbe22d700ea8afd4742096daa4399e2d3 Mon Sep 17 00:00:00 2001 From: Jeroen Vermeulen Date: Sun, 3 Aug 2014 23:10:40 +0200 Subject: [PATCH 3/4] Added Apache 2.4 config example --- plugins/hhvm/hhvm_ | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/plugins/hhvm/hhvm_ b/plugins/hhvm/hhvm_ index a38e755a..a27975d0 100755 --- a/plugins/hhvm/hhvm_ +++ b/plugins/hhvm/hhvm_ @@ -25,7 +25,9 @@ Copyright (c) 2014 Jeroen Vermeulen - http://www.jeroenvermeulen.eu - You can make it connect to another IP and port by naming the symlink "hhvm_[IP]_[PORT]", for example hhvm_11.22.33.44_8081 - You can also use the plugin config to set "env.host" and "env.port" -=head1 NGINX FASTCGI CONFIG +=head1 ADMIN WEBSERVER CONFIG + +=head2 NGINX CONFIG server { listen 127.0.0.1:8081 default; @@ -35,7 +37,7 @@ server { } } -=head1 APACHE 2.2 FASTCGI CONFIG +=head2 APACHE 2.2 CONFIG FastCgiExternalServer /var/run/hhvm_admin.fcgi -host 127.0.0.1:8080 Listen 127.0.0.1:8081 @@ -45,6 +47,13 @@ Listen 127.0.0.1:8081 Alias / /var/run/hhvm_admin.fcgi +=head2 APACHE 2.4 CONFIG + +Listen 127.0.0.1:8081 + + ProxyPass / fcgi://127.0.0.1:8080/ + + =cut use warnings; From 5f05c8c73353fa1f9dcc4abce1233273c33a9090 Mon Sep 17 00:00:00 2001 From: Root on server Star Date: Mon, 4 Aug 2014 01:09:54 +0200 Subject: [PATCH 4/4] Fixed multigraph for monitoring multple HHVM instances --- plugins/hhvm/hhvm_ | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/plugins/hhvm/hhvm_ b/plugins/hhvm/hhvm_ index a27975d0..42419999 100755 --- a/plugins/hhvm/hhvm_ +++ b/plugins/hhvm/hhvm_ @@ -68,9 +68,11 @@ sub getJson( $ ); my $script = $0; my $host = '127.0.0.1'; my $port = 8081; +my $name = undef; if ( $script =~ /\bhhvm_([a-z0-9\-\.]+)(?:_(\d+))?$/ ) { $host = $1; + $name = $host; if ( $2 ) { $port = int( $2 ); } @@ -78,19 +80,22 @@ if ( $script =~ /\bhhvm_([a-z0-9\-\.]+)(?:_(\d+))?$/ ) { $host = defined $ENV{'host'} ? $ENV{'host'} : $host; $port = defined $ENV{'port'} ? $ENV{'port'} : $port; +$name = defined $name ? $name : $host.':'.$port; +my $graphName = $name; +$graphName =~ s/[^\w]+/_/g; if ( exists $ARGV[0] && 'config' eq $ARGV[0] ) { print <{'status'}->{'threads'} } ) ); printf( "load.value %d\n", $health->{'load'} ); printf( "queued.value %d\n", $health->{'queued'} ); print "\n"; - - print "multigraph hhvm_sizes\n"; + printf( "multigraph hhvm_%s_sizes\n", $graphName ); printf( "hhbc-roarena-capac.value %d\n", $health->{'hhbc-roarena-capac'} ); printf( "tc-hotsize.value %d\n", $health->{'tc-hotsize'} ); printf( "tc-size.value %d\n", $health->{'tc-size'} );