Projet

Général

Profil

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

root / plugins / php / php_eaccelerator @ b0b39b01

Historique | Voir | Annoter | Télécharger (2,77 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 b0b39b01 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
key = ""
53 e94cf4d4 Dirk Gomez
54 b0b39b01 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
      three_liners = three_liners + 1
58 e94cf4d4 Dirk Gomez
59 b0b39b01 Lars Kruse
      if three_liners == 2
60 e94cf4d4 Dirk Gomez
        print "Memoryusagepercentage.value "
61
      end
62
63 b0b39b01 Lars Kruse
      if three_liners == 3
64 e94cf4d4 Dirk Gomez
        print "Memoryusage.value "
65
      end
66
67 b0b39b01 Lars Kruse
      if three_liners == 4
68 e94cf4d4 Dirk Gomez
        print "Memorymax.value "
69
      end
70
71 b0b39b01 Lars Kruse
      print line.gsub!(/[^0-9.]/s, "")
72 e94cf4d4 Dirk Gomez
      print "\n"
73
    end
74
75 b0b39b01 Lars Kruse
    if one_liners > 0
76
      one_liners = one_liners + 1
77 e94cf4d4 Dirk Gomez
      print "#{key}.value "
78 b0b39b01 Lars Kruse
      print line.gsub!(/[^0-9.]/s, "")
79 e94cf4d4 Dirk Gomez
      print "\n"
80
    end
81
82 b0b39b01 Lars Kruse
    if one_liners > 1
83
      line = ""
84
      one_liners = 0
85 e94cf4d4 Dirk Gomez
    end
86
87 b0b39b01 Lars Kruse
    if three_liners > 3
88
      line = ""
89
      three_liners = 0
90 e94cf4d4 Dirk Gomez
    end
91
92
    if line =~ /Memory usage/
93 b0b39b01 Lars Kruse
      key = line.gsub!(/(<[^>]*>)|\n|\t| /s, "")
94
      three_liners = three_liners + 1
95 e94cf4d4 Dirk Gomez
    end
96
97 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/
98
      key = line.gsub!(/(<[^>]*>)|\n|\t| /s, "")
99
      one_liners = one_liners + 1
100 e94cf4d4 Dirk Gomez
    end
101
  end
102
end