Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / php / hhvm_ @ 09b88141

Historique | Voir | Annoter | Télécharger (4,61 ko)

1 c8d88c62 Jeroen Vermeulen
#!/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 2fe6d91b Jeroen Vermeulen
=head1 ADMIN WEBSERVER CONFIG
29
30
=head2 NGINX CONFIG
31 c8d88c62 Jeroen Vermeulen
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 2fe6d91b Jeroen Vermeulen
=head2 APACHE 2.2 CONFIG
41 c8d88c62 Jeroen Vermeulen
42
FastCgiExternalServer /var/run/hhvm_admin.fcgi -host 127.0.0.1:8080
43 b1f8b9f0 Fran Rodriguez
Listen 127.0.0.1:8081
44 c8d88c62 Jeroen Vermeulen
<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 2fe6d91b Jeroen Vermeulen
=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 c8d88c62 Jeroen Vermeulen
=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 5f05c8c7 Root on server Star
my $name = undef;
72 c8d88c62 Jeroen Vermeulen
73
if ( $script =~ /\bhhvm_([a-z0-9\-\.]+)(?:_(\d+))?$/ ) {
74
    $host = $1;
75 5f05c8c7 Root on server Star
    $name = $host;
76 c8d88c62 Jeroen Vermeulen
    if ( $2 ) {
77
        $port = int( $2 );
78
    }
79
}
80
81
$host = defined $ENV{'host'} ? $ENV{'host'} : $host;
82
$port = defined $ENV{'port'} ? $ENV{'port'} : $port;
83 5f05c8c7 Root on server Star
$name = defined $name ? $name : $host.':'.$port;
84
my $graphName = $name;
85
$graphName =~ s/[^\w]+/_/g;
86 c8d88c62 Jeroen Vermeulen
87
if ( exists $ARGV[0] && 'config' eq $ARGV[0] ) {
88
    print <<EOF;
89 5f05c8c7 Root on server Star
multigraph hhvm_${graphName}_threads
90
graph_title HHVM Threads ${name}
91 c8d88c62 Jeroen Vermeulen
graph_args --base 1000
92 ed77c82d dipohl
graph_category webserver
93 c8d88c62 Jeroen Vermeulen
threads.label Threads
94
load.label Active Workers
95
queued.label Queued Jobs
96
97 5f05c8c7 Root on server Star
multigraph hhvm_${graphName}_sizes
98
graph_title HHVM Sizes ${name}
99 c8d88c62 Jeroen Vermeulen
graph_args --base 1024
100 ed77c82d dipohl
graph_category webserver
101 c8d88c62 Jeroen Vermeulen
hhbc-roarena-capac.label HHBC Arena Capacity
102
tc-hotsize.label TC Hot Size
103
tc-hotsize.info Translation Cache Hot Size
104
tc-size.label TC Size
105
tc-size.info Translation Cache Main Size
106
tc-profsize.label TC Profiling Size
107
tc-profsize.info Translation Cache Profiling Size
108
tc-coldsize.label TC Cold Size
109
tc-coldsize.info Translation Cache Cold Size
110
tc-frozensize.label TC Frozen Size
111
tc-frozensize.info Translation Cache Frozen Size
112
rds.label RDS Used Bytes
113
units.label Loaded Units
114
funcs.label Functions
115
EOF
116
} else {
117
    my $url = sprintf( 'http://%s:%d', $host, $port );
118
    my $health = getJson( sprintf( '%s/check-health', $url ) );
119
    my $status = getJson( sprintf( '%s/status.json', $url ) );
120
121 5f05c8c7 Root on server Star
    printf( "multigraph hhvm_%s_threads\n", $graphName );
122 b1f8b9f0 Fran Rodriguez
    printf( "threads.value %d\n", int( @{ $status->{'status'}->{'threads'} } ) );
123 c8d88c62 Jeroen Vermeulen
    printf( "load.value %d\n", $health->{'load'} );
124
    printf( "queued.value %d\n", $health->{'queued'} );
125
    print "\n";
126 5f05c8c7 Root on server Star
    printf( "multigraph hhvm_%s_sizes\n", $graphName );
127 c8d88c62 Jeroen Vermeulen
    printf( "hhbc-roarena-capac.value %d\n", $health->{'hhbc-roarena-capac'} );
128
    printf( "tc-hotsize.value %d\n", $health->{'tc-hotsize'} );
129
    printf( "tc-size.value %d\n", $health->{'tc-size'} );
130
    printf( "tc-profsize.value %d\n", $health->{'tc-profsize'} );
131
    printf( "tc-coldsize.value %d\n", $health->{'tc-coldsize'} );
132
    printf( "tc-frozensize.value %d\n", $health->{'tc-frozensize'} );
133
    printf( "rds.value %d\n", $health->{'rds'} );
134
    printf( "units.value %d\n", $health->{'units'} );
135
    printf( "funcs.value %d\n", $health->{'funcs'} );
136
}
137
138
exit 0;
139
140
sub getJson( $ ) {
141
    my ( $url ) = @_;
142
    my $json = get( $url );
143
    if ( ! $json ) {
144
        die( sprintf( "Could not get json from '%s'.", $url ) );
145
    }
146
    my $data = decode_json( $json );
147
    if ( ! $data || 'HASH' ne ref($data) ) {
148
        die( sprintf( "Could not decode json from '%s'.", $url ) );
149
    }
150
    return $data;
151 b1f8b9f0 Fran Rodriguez
}