Projet

Général

Profil

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

root / plugins / php / php_eaccelerator @ 09b88141

Historique | Voir | Annoter | Télécharger (2,67 ko)

1 7a37bfb1 Lars Kruse
#!/usr/bin/env ruby
2 e94cf4d4 Dirk Gomez
3 17f78427 Lars Kruse
# Monitor your EAccelerator usage.
4 e94cf4d4 Dirk Gomez
# Requires: ruby
5
6
# Mandatory Parameters
7
8
# user / pwd - for basic authentication against control.php
9
# url - fullpath to control.php
10
11
# Author: Dirk Gomez <munin@dirkgomez.de>
12
# Copyright (C) 2007 Dirk Gomez
13
#
14
# This program is free software; you can redistribute it and/or
15
# modify it under the terms of the GNU General Public License
16
# as published by the Free Software Foundation; either version 2
17
# of the License, or (at your option) any later version.
18
#
19
# This program is distributed in the hope that it will be useful,
20
# but WITHOUT ANY WARRANTY; without even the implied warranty of
21
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
# GNU General Public License for more details.
23
#
24
# You should have received a copy of the GNU General Public License
25
# along with this program; if not, write to the Free Software
26
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
27
28
require 'open-uri'
29
30
user  = ENV['user'] || 'user'
31
pwd   = ENV['password'] || 'password'
32
url   = ENV['url'] || 'http://127.0.0.1/control.php'
33
34 809639ab Lars Kruse
if ARGV[0] == 'config'
35 e94cf4d4 Dirk Gomez
  print "EAccelerator Monitoring\n"
36
  print "graph_title PHP Eaccelerator\n"
37 b19b3a81 dipohl
  print "graph_category webserver\n"
38 17f78427 Lars Kruse
  print "Memoryusagepercentage.label Memory Usage %\n"
39
  print "Memoryusagepercentage.warning 95\n"
40
  print "Memoryusagepercentage.critical 95\n"
41
  print "Memoryusage.label Memory Usage MB\n"
42
  print "Memorymax.label Cache Size MB\n"
43 e94cf4d4 Dirk Gomez
  print "Freememory.label Free Memory MB\n"
44
  print "Cachedscripts.label Cached Scripts\n"
45
  print "Removedscripts.label Removed Scripts\n"
46
  print "Cachedkeys.label Cached Keys\n"
47
  exit
48
end
49
50 b0b39b01 Lars Kruse
one_liners = 0
51
three_liners = 0
52 809639ab Lars Kruse
key = ''
53 e94cf4d4 Dirk Gomez
54 809639ab Lars Kruse
open(url, http_basic_authentication: [user, pwd]) do |f|
55 e94cf4d4 Dirk Gomez
  f.each do |line|
56 b0b39b01 Lars Kruse
    if three_liners > 0
57 809639ab Lars Kruse
      three_liners += 1
58 e94cf4d4 Dirk Gomez
59 809639ab Lars Kruse
      print 'Memoryusagepercentage.value ' if three_liners == 2
60 e94cf4d4 Dirk Gomez
61 809639ab Lars Kruse
      print 'Memoryusage.value ' if three_liners == 3
62 e94cf4d4 Dirk Gomez
63 809639ab Lars Kruse
      print 'Memorymax.value ' if three_liners == 4
64 e94cf4d4 Dirk Gomez
65 809639ab Lars Kruse
      print line.gsub!(/[^0-9.]/s, '')
66 e94cf4d4 Dirk Gomez
      print "\n"
67
    end
68
69 b0b39b01 Lars Kruse
    if one_liners > 0
70 809639ab Lars Kruse
      one_liners += 1
71 e94cf4d4 Dirk Gomez
      print "#{key}.value "
72 809639ab Lars Kruse
      print line.gsub!(/[^0-9.]/s, '')
73 e94cf4d4 Dirk Gomez
      print "\n"
74
    end
75
76 b0b39b01 Lars Kruse
    if one_liners > 1
77 809639ab Lars Kruse
      line = ''
78 b0b39b01 Lars Kruse
      one_liners = 0
79 e94cf4d4 Dirk Gomez
    end
80
81 b0b39b01 Lars Kruse
    if three_liners > 3
82 809639ab Lars Kruse
      line = ''
83 b0b39b01 Lars Kruse
      three_liners = 0
84 e94cf4d4 Dirk Gomez
    end
85
86
    if line =~ /Memory usage/
87 809639ab Lars Kruse
      key = line.gsub!(/(<[^>]*>)|\n|\t| /s, '')
88
      three_liners += 1
89 e94cf4d4 Dirk Gomez
    end
90
91 b0b39b01 Lars Kruse
    if line =~ /<td class="e">Free memory/ || line =~ /<td class="e">Cached scripts/ || line =~ /<td class="e">Removed scripts/ || line =~ /<td class="e">Cached keys/
92 809639ab Lars Kruse
      key = line.gsub!(/(<[^>]*>)|\n|\t| /s, '')
93
      one_liners += 1
94 e94cf4d4 Dirk Gomez
    end
95
  end
96
end