Projet

Général

Profil

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

root / plugins / other / nginx_status @ ba2f09ff

Historique | Voir | Annoter | Télécharger (1,83 ko)

1 dc892da5 unkown
#!/usr/bin/perl -w
2
#
3
# Magic markers:
4
#%# family=auto
5
#%# capabilities=autoconf
6
7
my $ret = undef;
8
9
if (! eval "require LWP::UserAgent;"){
10
	$ret = "LWP::UserAgent not found";
11
}
12
13
chomp(my $fqdn=`hostname -f`);
14
15
my $URL = exists $ENV{'url'} ? $ENV{'url'} : "http://$fqdn/nginx_status";
16
17
if ( exists $ARGV[0] and $ARGV[0] eq "autoconf" )
18
{
19
	if ($ret){
20
		print "no ($ret)\n";
21
		exit 1;
22
	}
23
	
24
	my $ua = LWP::UserAgent->new(timeout => 30);
25
    my $response = $ua->request(HTTP::Request->new('GET',$URL));
26
27
	unless ($response->is_success and $response->content =~ /server/im)
28
	{
29
		print "no (no nginx status on $URL)\n";
30
		exit 1;
31
	}
32
	else
33
	{
34
		print "yes\n";
35
		exit 0;
36
	}
37
}
38
39
if ( exists $ARGV[0] and $ARGV[0] eq "config" )
40
{
41
	print "graph_title NGINX status\n";
42
    print "graph_args --base 1000\n";
43
	print "graph_category nginx\n";
44
    print "graph_vlabel Connections\n";
45
46
    print "total.label Active connections\n";
47
	print "total.info  Active connections\n";
48
	print "total.draw LINE2\n";
49
50
    print "reading.label Reading\n";
51
	print "reading.info  Reading\n";
52
	print "reading.draw LINE2\n";	
53
54
    print "writing.label Writing\n";
55
	print "writing.info  Writing\n";
56
	print "writing.draw LINE2\n";	
57
58
    print "waiting.label Waiting\n";
59
	print "waiting.info  Waiting\n";
60
	print "waiting.draw LINE2\n";	
61
	
62
	exit 0;
63
}
64
65
my $ua = LWP::UserAgent->new(timeout => 30);
66
67
my $response = $ua->request(HTTP::Request->new('GET',$URL));
68
69
#Active connections: 1845 
70
#server accepts handled requests
71
# 4566318 4566318 84218236 
72
# Reading: 2 Writing: 278 Waiting: 1565 
73
if ($response->content =~ /Active connections:\s+(\d+).*Reading:\s+(\d+).*Writing:\s+(\d+).*Waiting:\s+(\d+)/s) {
74
    print "total.value $1\n";
75
    print "reading.value $2\n";
76
    print "writing.value $3\n";
77
    print "waiting.value $4\n";
78
} else {
79
	foreach (qw(total reading writing waiting)){
80
	    print "$_.value U\n";
81
	}
82
}