root / plugins / hhvm / hhvm_ @ 2fe6d91b
Historique | Voir | Annoter | Télécharger (4,61 ko)
| 1 |
#!/usr/bin/env perl |
|---|---|
| 2 |
|
| 3 |
=head1 NAME |
| 4 |
|
| 5 |
hhvm_ - Munin plugin to monitor HHVM. |
| 6 |
|
| 7 |
=head1 LICENCE |
| 8 |
|
| 9 |
This source file is subject to the Open Software License (OSL 3.0) |
| 10 |
Which is available through the world-wide-web at this URL: |
| 11 |
http://opensource.org/licenses/osl-3.0.php |
| 12 |
|
| 13 |
Copyright (c) 2014 Jeroen Vermeulen - http://www.jeroenvermeulen.eu |
| 14 |
|
| 15 |
=head1 USAGE |
| 16 |
|
| 17 |
- You need HHVM 3.0 or greater. |
| 18 |
- The HHVM AdminServer needs to be locally accessible via HTTP. |
| 19 |
- Since version 3.0 HHVM has no longer a built-in webserver. Not even for the AdminServer. |
| 20 |
- 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. |
| 21 |
- You can use the HHVM Config setting "AdminServer.Port" or ini variable "hhvm.admin_server.port" to choose that port. For example 8080. |
| 22 |
- Copy this file to "/usr/share/munin/plugins/hhvm_". |
| 23 |
- Create a symlink in "/etc/munin/plugins" |
| 24 |
- By default this script will try to connect to a webserver on 127.0.0.1 port 8081. |
| 25 |
- 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 |
| 26 |
- You can also use the plugin config to set "env.host" and "env.port" |
| 27 |
|
| 28 |
=head1 ADMIN WEBSERVER CONFIG |
| 29 |
|
| 30 |
=head2 NGINX CONFIG |
| 31 |
|
| 32 |
server {
|
| 33 |
listen 127.0.0.1:8081 default; |
| 34 |
location ~ {
|
| 35 |
fastcgi_pass 127.0.0.1:8080; |
| 36 |
include fastcgi_params; |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
=head2 APACHE 2.2 CONFIG |
| 41 |
|
| 42 |
FastCgiExternalServer /var/run/hhvm_admin.fcgi -host 127.0.0.1:8080 |
| 43 |
Listen 127.0.0.1:8081 |
| 44 |
<VirtualHost 127.0.0.1:8081> |
| 45 |
Alias /check-health /var/run/hhvm_admin.fcgi |
| 46 |
Alias /status.json /var/run/hhvm_admin.fcgi |
| 47 |
Alias / /var/run/hhvm_admin.fcgi |
| 48 |
</VirtualHost> |
| 49 |
|
| 50 |
=head2 APACHE 2.4 CONFIG |
| 51 |
|
| 52 |
Listen 127.0.0.1:8081 |
| 53 |
<VirtualHost 127.0.0.1:8081> |
| 54 |
ProxyPass / fcgi://127.0.0.1:8080/ |
| 55 |
</VirtualHost> |
| 56 |
|
| 57 |
=cut |
| 58 |
|
| 59 |
use warnings; |
| 60 |
use strict; |
| 61 |
# use lib $ENV{'MUNIN_LIBDIR'};
|
| 62 |
use Munin::Plugin; |
| 63 |
use LWP::Simple; |
| 64 |
use JSON::PP; |
| 65 |
|
| 66 |
sub getJson( $ ); |
| 67 |
|
| 68 |
my $script = $0; |
| 69 |
my $host = '127.0.0.1'; |
| 70 |
my $port = 8081; |
| 71 |
|
| 72 |
if ( $script =~ /\bhhvm_([a-z0-9\-\.]+)(?:_(\d+))?$/ ) {
|
| 73 |
$host = $1; |
| 74 |
if ( $2 ) {
|
| 75 |
$port = int( $2 ); |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
$host = defined $ENV{'host'} ? $ENV{'host'} : $host;
|
| 80 |
$port = defined $ENV{'port'} ? $ENV{'port'} : $port;
|
| 81 |
|
| 82 |
if ( exists $ARGV[0] && 'config' eq $ARGV[0] ) {
|
| 83 |
print <<EOF; |
| 84 |
multigraph hhvm_threads |
| 85 |
graph_title HHVM Threads ${host}:${port}
|
| 86 |
graph_args --base 1000 |
| 87 |
graph_category hhvm |
| 88 |
threads.label Threads |
| 89 |
load.label Active Workers |
| 90 |
queued.label Queued Jobs |
| 91 |
|
| 92 |
multigraph hhvm_sizes |
| 93 |
graph_title HHVM Sizes ${host}:${port}
|
| 94 |
graph_args --base 1024 |
| 95 |
graph_category hhvm |
| 96 |
hhbc-roarena-capac.label HHBC Arena Capacity |
| 97 |
tc-hotsize.label TC Hot Size |
| 98 |
tc-hotsize.info Translation Cache Hot Size |
| 99 |
tc-size.label TC Size |
| 100 |
tc-size.info Translation Cache Main Size |
| 101 |
tc-profsize.label TC Profiling Size |
| 102 |
tc-profsize.info Translation Cache Profiling Size |
| 103 |
tc-coldsize.label TC Cold Size |
| 104 |
tc-coldsize.info Translation Cache Cold Size |
| 105 |
tc-trampolinessize.label TC Trampoline Size |
| 106 |
tc-trampolinessize.info Translation Cache Trampoline Size |
| 107 |
tc-frozensize.label TC Frozen Size |
| 108 |
tc-frozensize.info Translation Cache Frozen Size |
| 109 |
rds.label RDS Used Bytes |
| 110 |
units.label Loaded Units |
| 111 |
funcs.label Functions |
| 112 |
EOF |
| 113 |
} else {
|
| 114 |
my $url = sprintf( 'http://%s:%d', $host, $port ); |
| 115 |
my $health = getJson( sprintf( '%s/check-health', $url ) ); |
| 116 |
my $status = getJson( sprintf( '%s/status.json', $url ) ); |
| 117 |
|
| 118 |
print "multigraph hhvm_threads\n"; |
| 119 |
printf( "threads.value %d\n", int( @{ $status->{'status'}->{'threads'} } ) );
|
| 120 |
printf( "load.value %d\n", $health->{'load'} );
|
| 121 |
printf( "queued.value %d\n", $health->{'queued'} );
|
| 122 |
print "\n"; |
| 123 |
|
| 124 |
print "multigraph hhvm_sizes\n"; |
| 125 |
printf( "hhbc-roarena-capac.value %d\n", $health->{'hhbc-roarena-capac'} );
|
| 126 |
printf( "tc-hotsize.value %d\n", $health->{'tc-hotsize'} );
|
| 127 |
printf( "tc-size.value %d\n", $health->{'tc-size'} );
|
| 128 |
printf( "tc-profsize.value %d\n", $health->{'tc-profsize'} );
|
| 129 |
printf( "tc-coldsize.value %d\n", $health->{'tc-coldsize'} );
|
| 130 |
printf( "tc-trampolinessize.value %d\n", $health->{'tc-trampolinessize'} );
|
| 131 |
printf( "tc-frozensize.value %d\n", $health->{'tc-frozensize'} );
|
| 132 |
printf( "rds.value %d\n", $health->{'rds'} );
|
| 133 |
printf( "units.value %d\n", $health->{'units'} );
|
| 134 |
printf( "funcs.value %d\n", $health->{'funcs'} );
|
| 135 |
} |
| 136 |
|
| 137 |
exit 0; |
| 138 |
|
| 139 |
sub getJson( $ ) {
|
| 140 |
my ( $url ) = @_; |
| 141 |
my $json = get( $url ); |
| 142 |
if ( ! $json ) {
|
| 143 |
die( sprintf( "Could not get json from '%s'.", $url ) ); |
| 144 |
} |
| 145 |
my $data = decode_json( $json ); |
| 146 |
if ( ! $data || 'HASH' ne ref($data) ) {
|
| 147 |
die( sprintf( "Could not decode json from '%s'.", $url ) ); |
| 148 |
} |
| 149 |
return $data; |
| 150 |
} |
