Projet

Général

Profil

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

root / plugins / hhvm / hhvm_ @ c8d88c62

Historique | Voir | Annoter | Télécharger (4,48 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 NGINX FASTCGI CONFIG
29

    
30
server {
31
    listen              127.0.0.1:8081 default;
32
    location ~ {
33
        fastcgi_pass    127.0.0.1:8080;
34
        include         fastcgi_params;
35
    }
36
}
37

    
38
=head1 APACHE 2.2 FASTCGI CONFIG
39

    
40
FastCgiExternalServer /var/run/hhvm_admin.fcgi -host 127.0.0.1:8080
41
Listen 127.0.0.1:8081               
42
<VirtualHost 127.0.0.1:8081>
43
    Alias  /check-health  /var/run/hhvm_admin.fcgi
44
    Alias  /status.json   /var/run/hhvm_admin.fcgi
45
    Alias  /              /var/run/hhvm_admin.fcgi
46
</VirtualHost>
47

    
48
=cut
49

    
50
use warnings;
51
use strict;
52
# use lib $ENV{'MUNIN_LIBDIR'};
53
use Munin::Plugin;
54
use LWP::Simple;
55
use JSON::PP;
56

    
57
sub getJson( $ );
58

    
59
my $script = $0;
60
my $host = '127.0.0.1';
61
my $port = 8081;
62

    
63
if ( $script =~ /\bhhvm_([a-z0-9\-\.]+)(?:_(\d+))?$/ ) {
64
    $host = $1;
65
    if ( $2 ) {
66
        $port = int( $2 );
67
    }
68
}
69

    
70
$host = defined $ENV{'host'} ? $ENV{'host'} : $host;
71
$port = defined $ENV{'port'} ? $ENV{'port'} : $port;
72

    
73
if ( exists $ARGV[0] && 'config' eq $ARGV[0] ) {
74
    print <<EOF;
75
multigraph hhvm_threads
76
graph_title HHVM Threads ${host}:${port}
77
graph_args --base 1000
78
graph_category hhvm
79
threads.label Threads
80
load.warning 10
81
load.label Active Workers
82
queued.label Queued Jobs
83

    
84
multigraph hhvm_sizes
85
graph_title HHVM Sizes ${host}:${port}
86
graph_args --base 1024
87
graph_category hhvm
88
hhbc-roarena-capac.label HHBC Arena Capacity
89
tc-hotsize.label TC Hot Size
90
tc-hotsize.info Translation Cache Hot Size
91
tc-size.label TC Size
92
tc-size.info Translation Cache Main Size
93
tc-profsize.label TC Profiling Size
94
tc-profsize.info Translation Cache Profiling Size
95
tc-coldsize.label TC Cold Size
96
tc-coldsize.info Translation Cache Cold Size
97
tc-trampolinessize.label TC Trampoline Size
98
tc-trampolinessize.info Translation Cache Trampoline Size
99
tc-frozensize.label TC Frozen Size
100
tc-frozensize.info Translation Cache Frozen Size
101
rds.label RDS Used Bytes
102
units.label Loaded Units
103
funcs.label Functions
104
EOF
105
} else {
106
    my $url = sprintf( 'http://%s:%d', $host, $port );
107
    my $health = getJson( sprintf( '%s/check-health', $url ) );
108
    my $status = getJson( sprintf( '%s/status.json', $url ) );
109

    
110
    print "multigraph hhvm_threads\n";
111
    printf( "threads.value %d\n", int( @{ $status->{'status'}->{'threads'} } ) ); 
112
    printf( "load.value %d\n", $health->{'load'} );
113
    printf( "queued.value %d\n", $health->{'queued'} );
114
    print "\n";
115

    
116
    print "multigraph hhvm_sizes\n";
117
    printf( "hhbc-roarena-capac.value %d\n", $health->{'hhbc-roarena-capac'} );
118
    printf( "tc-hotsize.value %d\n", $health->{'tc-hotsize'} );
119
    printf( "tc-size.value %d\n", $health->{'tc-size'} );
120
    printf( "tc-profsize.value %d\n", $health->{'tc-profsize'} );
121
    printf( "tc-coldsize.value %d\n", $health->{'tc-coldsize'} );
122
    printf( "tc-trampolinessize.value %d\n", $health->{'tc-trampolinessize'} );
123
    printf( "tc-frozensize.value %d\n", $health->{'tc-frozensize'} );
124
    printf( "rds.value %d\n", $health->{'rds'} );
125
    printf( "units.value %d\n", $health->{'units'} );
126
    printf( "funcs.value %d\n", $health->{'funcs'} );
127
}
128

    
129
exit 0;
130

    
131
sub getJson( $ ) {
132
    my ( $url ) = @_;
133
    my $json = get( $url );
134
    if ( ! $json ) {
135
        die( sprintf( "Could not get json from '%s'.", $url ) );
136
    }
137
    my $data = decode_json( $json );
138
    if ( ! $data || 'HASH' ne ref($data) ) {
139
        die( sprintf( "Could not decode json from '%s'.", $url ) );
140
    }
141
    return $data;
142
}