root / plugins / other / ksm_ @ e5ce7492
Historique | Voir | Annoter | Télécharger (4,13 ko)
| 1 |
#!/usr/bin/env python |
|---|---|
| 2 |
# -*- encoding: UTF-8 -*- |
| 3 |
# |
| 4 |
# ksm |
| 5 |
# |
| 6 |
# Plugin to monitor ksm - Kernel Samepage Merging. |
| 7 |
# |
| 8 |
# Author: Markus Heberling <markus@tisoft.de> |
| 9 |
# |
| 10 |
# v1.0 2011-04-05 - First version |
| 11 |
# |
| 12 |
# Usage: place in /etc/munin/plugins/ (or link it there using ln -s) |
| 13 |
# |
| 14 |
# Parameters understood: |
| 15 |
# |
| 16 |
# config (required) |
| 17 |
# autoconf (optional - used by munin-config) |
| 18 |
# |
| 19 |
# Magic markers - optional - used by installation scripts and |
| 20 |
# munin-config: |
| 21 |
# |
| 22 |
#%# capabilities=autoconf suggest |
| 23 |
#%# family=auto |
| 24 |
|
| 25 |
########################################################### |
| 26 |
category = 'system' # 'upgrades' |
| 27 |
title = 'Kernel Samepage Merging' # 'Upgradeable packages' |
| 28 |
########################################################### |
| 29 |
|
| 30 |
import os |
| 31 |
import sys |
| 32 |
import warnings |
| 33 |
|
| 34 |
def autoconf(): |
| 35 |
if os.path.exists('/sys/kernel/mm/ksm/run'):
|
| 36 |
for line in open('/sys/kernel/mm/ksm/run'):
|
| 37 |
if line.strip() == '1': |
| 38 |
print 'yes' |
| 39 |
sys.exit(0) |
| 40 |
print 'no (/sys/kernel/mm/ksm/run must be present and value must be 1)' |
| 41 |
sys.exit(0) |
| 42 |
|
| 43 |
def suggest(): |
| 44 |
print 'pages_absolute' |
| 45 |
print 'pages_relative' |
| 46 |
print 'full_scans' |
| 47 |
sys.exit(0) |
| 48 |
|
| 49 |
|
| 50 |
def config(): |
| 51 |
if('ksm_pages_absolute' in sys.argv[0]):
|
| 52 |
print 'graph_category %s' % (category) |
| 53 |
print 'graph_title %s Pages Absolute' % (title) |
| 54 |
print 'graph_order pages_unshared pages_volatile pages_shared pages_sharing' |
| 55 |
print 'pages_shared.info how many shared pages are being used' |
| 56 |
print 'pages_sharing.info how many more sites are sharing them i.e. how much saved' |
| 57 |
print 'pages_unshared.info how many pages unique but repeatedly checked for merging' |
| 58 |
print 'pages_volatile.info how many pages changing too fast to be placed in a tree' |
| 59 |
print 'pages_shared.label pages_shared' |
| 60 |
print 'pages_sharing.label pages_sharing' |
| 61 |
print 'pages_unshared.label pages_unshared' |
| 62 |
print 'pages_volatile.label pages_volatile' |
| 63 |
print 'pages_shared.draw AREASTACK' |
| 64 |
print 'pages_sharing.draw AREASTACK' |
| 65 |
print 'pages_unshared.draw AREASTACK' |
| 66 |
print 'pages_volatile.draw AREASTACK' |
| 67 |
elif('ksm_pages_relative' in sys.argv[0]):
|
| 68 |
print 'graph_category %s' % (category) |
| 69 |
print 'graph_title %s Pages Relative' % (title) |
| 70 |
print 'pages_sharing_shared.info ratio of sharing to shared pages' |
| 71 |
print 'pages_unshared_sharing.info ratio of unshared to sharing pages' |
| 72 |
print 'pages_sharing_shared.label pages_sharing_shared' |
| 73 |
print 'pages_unshared_sharing.label pages_unshared_sharing' |
| 74 |
print 'pages_sharing_shared.cdef pages_sharing_shared,100,*' |
| 75 |
print 'pages_unshared_sharing.cdef pages_unshared_sharing,100,*' |
| 76 |
elif('ksm_full_scans' in sys.argv[0]):
|
| 77 |
print 'graph_category %s' % (category) |
| 78 |
print 'graph_title %s Full Scans' % (title) |
| 79 |
print 'full_scans.info how many times all mergeable areas have been scanned' |
| 80 |
print 'full_scans.label full_scans' |
| 81 |
sys.exit(0) |
| 82 |
|
| 83 |
if len(sys.argv) > 1: |
| 84 |
if sys.argv[1] == 'autoconf': |
| 85 |
autoconf() |
| 86 |
elif sys.argv[1] == 'config': |
| 87 |
config() |
| 88 |
elif sys.argv[1] == 'suggest': |
| 89 |
suggest() |
| 90 |
elif sys.argv[1]: |
| 91 |
print('unknown argument "' + sys.argv[1] + '"')
|
| 92 |
sys.exit(1) |
| 93 |
|
| 94 |
pages_shared=int(open('/sys/kernel/mm/ksm/pages_shared').read())
|
| 95 |
pages_sharing=int(open('/sys/kernel/mm/ksm/pages_sharing').read())
|
| 96 |
pages_unshared=int(open('/sys/kernel/mm/ksm/pages_unshared').read())
|
| 97 |
pages_volatile=int(open('/sys/kernel/mm/ksm/pages_volatile').read())
|
| 98 |
full_scans=int(open('/sys/kernel/mm/ksm/full_scans').read())
|
| 99 |
|
| 100 |
if('ksm_pages_absolute' in sys.argv[0]):
|
| 101 |
print 'pages_shared.value %i' % pages_shared |
| 102 |
print 'pages_sharing.value %i' % pages_sharing |
| 103 |
print 'pages_unshared.value %i' % pages_unshared |
| 104 |
print 'pages_volatile.value %i' % pages_volatile |
| 105 |
elif('ksm_pages_relative' in sys.argv[0]):
|
| 106 |
print 'pages_sharing_shared.value %f' % (float(pages_sharing)/float(pages_shared) if pages_shared>0 else 0) |
| 107 |
print 'pages_unshared_sharing.value %f' % (float(pages_unshared)/float(pages_sharing) if pages_sharing>0 else 0) |
| 108 |
elif('ksm_full_scans' in sys.argv[0]):
|
| 109 |
print 'full_scans.value %i' % full_scans |
