-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphp_opcache_
executable file
·129 lines (108 loc) · 2.66 KB
/
php_opcache_
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/perl
#
# Magic markers:
#%# family=auto
#%# capabilities=autoconf
use strict;
use Munin::Plugin;
need_multigraph();
my $ret = undef;
if (! eval "require LWP::UserAgent;")
{
$ret = "LWP::UserAgent not found";
}
my $URL = exists $ENV{'url'} ? $ENV{'url'} : "http://127.0.0.1:%d/opcache_info.php?auto";
my @PORTS = exists $ENV{'ports'} ? split(' ', $ENV{'ports'}) : (80);
if ( defined $ARGV[0] and $ARGV[0] eq "autoconf" )
{
if ($ret)
{
print "no ($ret)\n";
exit 1;
}
my $ua = LWP::UserAgent->new(timeout => 30);
my @badports;
foreach my $port (@PORTS) {
my $url = sprintf $URL, $port;
my $response = $ua->request(HTTP::Request->new('GET',$url));
push @badports, $port unless $response->is_success and $response->content =~ /^size: /im;
}
if (@badports) {
print "no (opcache-status)\n";
exit 1;
} else {
print "yes\n";
exit 0;
}
}
if ( defined $ARGV[0] and $ARGV[0] eq "config" )
{
$0 =~ /php_opcache([^_]+)?_(.+)*/;
my $custom_name = $1;
my $plugin = $2;
## PHP Opcache Cache Usage
if($plugin eq 'usage') {
print("multigraph php_opcache$custom_name\_usage
graph_title Cache Usage $custom_name
graph_args --base 1024 -l 0
graph_vlabel Bytes
graph_category php-opcache
graph_order used free
graph_total Total
used.label Used Memory
used.draw AREASTACK
free.label Available Memory
free.draw AREASTACK
");
}
## PHP Opcache Hit / Miss by percentage
elsif($plugin eq 'hit_miss') {
print("multigraph php_opcache$custom_name\_hit_miss
graph_title Opcode Cache Hits / Misses $custom_name
graph_args --base 1000 --lower-limit 0 --upper-limit 100 --rigid
graph_vlabel Percent
graph_category php-opcache
graph_total Total
hits.label Hits
hits.draw AREA
hits.min 0
misses.label Misses
misses.draw STACK
misses.min 0
misses.warning 50
");
}
exit 0;
}
foreach my $port (@PORTS)
{
my $ua = LWP::UserAgent->new(timeout => 30);
my $url = sprintf $URL, $port;
my $response = $ua->request(HTTP::Request->new('GET',$url));
if ($response->content =~ /size:\s+([0-9\.]+)/im) {
print "size.value $1\n";
} else {
print "size.value U\n";
}
if ($response->content =~ /used:\s+([0-9\.]+)/im) {
print "used.value $1\n";
} else {
print "used.value U\n";
}
if ($response->content =~ /free:\s+([0-9\.]+)/im) {
print "free.value $1\n";
} else {
print "free.value U\n";
}
if ($response->content =~ /hits:\s+([0-9\.]+)/im) {
print "hits.value $1\n";
} else {
print "hits.value U\n";
}
if ($response->content =~ /free:\s+([0-9\.]+)/im) {
print "misses.value $1\n";
} else {
print "misses.value U\n";
}
}
# vim:syntax=perl