root / plugins / php / eaccelerator-python @ 17f78427
Historique | Voir | Annoter | Télécharger (3,56 ko)
| 1 |
#!/usr/bin/env python |
|---|---|
| 2 |
''' |
| 3 |
Plugin to monitor performance of eaccelerator module for PHP. |
| 4 |
|
| 5 |
To use: |
| 6 |
1. Copy script to munin plugins folder |
| 7 |
2. Symbolically link to eacc_memory and eacc_cached |
| 8 |
* eacc_memory shows memory usage |
| 9 |
* eacc_cached shows number of scripts cached and discarded |
| 10 |
3. Set configuration options in munin config file as follows |
| 11 |
[eacc_*] |
| 12 |
env.auth_user username |
| 13 |
env.auth_pwd password |
| 14 |
env_cpanel url_of_stats.php |
| 15 |
4. Copy stats.php into the eacc control panel folder and set $user/$pw to match auth_user/auth_pwd |
| 16 |
* Ideally, these should be the same values as set in control.php |
| 17 |
5. Run `munin-run eacc_memory` and `munin-run eacc_cached` to make sure scripts are running correctly, you should see non-zero values |
| 18 |
6. Restart munin-node |
| 19 |
|
| 20 |
This script's homepage: https://github.com/hermzz/munin-eaccelerator-plugin |
| 21 |
eAccelerator homepage: http://eaccelerator.net/ |
| 22 |
''' |
| 23 |
import sys, os |
| 24 |
|
| 25 |
command_vars = {
|
| 26 |
'memory': ['memorysize', 'memoryallocated'], |
| 27 |
'cached': ['cachedscripts', 'removedscripts'] |
| 28 |
} |
| 29 |
|
| 30 |
config = {
|
| 31 |
'memory': |
| 32 |
'graph_title eacceleratory memory usage\n' + |
| 33 |
'graph_info This graph shows memory performance of PHP eaccelerator module\n' + |
| 34 |
'graphs_args -1 0\n' + |
| 35 |
'graph_category webserver\n' + |
| 36 |
|
| 37 |
'memorysize.label total\n' + |
| 38 |
'memorysize.draw AREA\n' + |
| 39 |
'memorysize.min 0\n' + |
| 40 |
'memorysize.info Total memory\n' + |
| 41 |
|
| 42 |
'memoryallocated.label allocated\n' + |
| 43 |
'memoryallocated.draw LINE1\n' + |
| 44 |
'memoryallocated.min 0\n' + |
| 45 |
'memoryallocated.info Memory allocated', |
| 46 |
'cached': |
| 47 |
'graph_title eacceleratory cached scripts\n' + |
| 48 |
'graph_info This graph shows how many scripts are cached by PHP eaccelerator module\n' + |
| 49 |
'graphs_args -1 0\n' + |
| 50 |
'graph_category webserver\n' + |
| 51 |
|
| 52 |
'cachedscripts.label cached scripts\n' + |
| 53 |
'cachedscripts.draw LINE1\n' + |
| 54 |
'cachedscripts.min 0\n' + |
| 55 |
'cachedscripts.info Cached scripts\n' + |
| 56 |
|
| 57 |
'removedscripts.label removed scripts\n' + |
| 58 |
'removedscripts.draw LINE1\n' + |
| 59 |
'removedscripts.min 0\n' + |
| 60 |
'removedscripts.info Removed scripts' |
| 61 |
} |
| 62 |
|
| 63 |
def print_config(command): |
| 64 |
print config[command] |
| 65 |
|
| 66 |
def get_stats(): |
| 67 |
fetcher = httplib2.Http() |
| 68 |
if 'auth_user' in os.environ and 'auth_pwd' in os.environ: |
| 69 |
fetcher.add_credentials(os.environ['auth_user'], os.environ['auth_pwd']) |
| 70 |
resp, content = fetcher.request(os.environ["cpanel"]) |
| 71 |
|
| 72 |
if resp['status'] != '200': |
| 73 |
content = '0 0 0 0' |
| 74 |
|
| 75 |
bits = content.split(' ')
|
| 76 |
return {'memorysize': bits[0], 'memoryallocated': bits[1], 'cachedscripts': bits[2], 'removedscripts': bits[3]}
|
| 77 |
|
| 78 |
def print_stats(command): |
| 79 |
stats = get_stats() |
| 80 |
|
| 81 |
for var in command_vars[command]: |
| 82 |
print "%s.value %s" % (var, stats[var]) |
| 83 |
|
| 84 |
if __name__ == "__main__": |
| 85 |
try: |
| 86 |
import httplib2 |
| 87 |
except ImportError: |
| 88 |
print "httplib2 not found" |
| 89 |
sys.exit(1) |
| 90 |
|
| 91 |
if os.environ['cpanel'] == '': |
| 92 |
print "env.cpanel not defined in munin config" |
| 93 |
sys.exit() |
| 94 |
|
| 95 |
underscore = sys.argv[0].find('_')
|
| 96 |
|
| 97 |
if underscore == -1: |
| 98 |
print "Symbolically link this file to eacc_memory or eacc_cached" |
| 99 |
sys.exit(1) |
| 100 |
else: |
| 101 |
command = sys.argv[0][underscore+1:] |
| 102 |
|
| 103 |
if len(sys.argv) > 1 and sys.argv[1] != '': |
| 104 |
if sys.argv[1] == 'config': |
| 105 |
print_config(command) |
| 106 |
else: |
| 107 |
print "Command %s not recognized" % sys.argv[1] |
| 108 |
sys.exit(1) |
| 109 |
else: |
| 110 |
print_stats(command) |
