root / plugins / other / ksm_ @ a975706f
Historique | Voir | Annoter | Télécharger (4,15 ko)
| 1 | 8308ba95 | Markus Heberling | #!/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 | 8e3f1d88 | Lars Kruse | # #%# capabilities=autoconf suggest |
| 23 | # #%# family=auto |
||
| 24 | 8308ba95 | Markus Heberling | |
| 25 | import os |
||
| 26 | import sys |
||
| 27 | 8e3f1d88 | Lars Kruse | import warnings # noqa |
| 28 | |||
| 29 | ################################# |
||
| 30 | title = 'Kernel Samepage Merging' |
||
| 31 | ################################# |
||
| 32 | |||
| 33 | 8308ba95 | Markus Heberling | |
| 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 | 8e3f1d88 | Lars Kruse | print('yes')
|
| 39 | break |
||
| 40 | else: |
||
| 41 | print('no (/sys/kernel/mm/ksm/run does not contain "1")')
|
||
| 42 | else: |
||
| 43 | print('no (/sys/kernel/mm/ksm/run not found)')
|
||
| 44 | 8308ba95 | Markus Heberling | sys.exit(0) |
| 45 | |||
| 46 | 8e3f1d88 | Lars Kruse | |
| 47 | 8308ba95 | Markus Heberling | def suggest(): |
| 48 | 8e3f1d88 | Lars Kruse | print('pages_absolute')
|
| 49 | print('pages_relative')
|
||
| 50 | print('full_scans')
|
||
| 51 | 8308ba95 | Markus Heberling | sys.exit(0) |
| 52 | |||
| 53 | |||
| 54 | def config(): |
||
| 55 | 8e3f1d88 | Lars Kruse | if('ksm_pages_absolute' in sys.argv[0]):
|
| 56 | print('graph_category system')
|
||
| 57 | print('graph_title %s Pages Absolute' % (title))
|
||
| 58 | print('graph_order pages_unshared pages_volatile pages_shared pages_sharing')
|
||
| 59 | print('pages_shared.info how many shared pages are being used')
|
||
| 60 | print('pages_sharing.info how many more sites are sharing them i.e. how much saved')
|
||
| 61 | print('pages_unshared.info how many pages unique but repeatedly checked for merging')
|
||
| 62 | print('pages_volatile.info how many pages changing too fast to be placed in a tree')
|
||
| 63 | print('pages_shared.label pages_shared')
|
||
| 64 | print('pages_sharing.label pages_sharing')
|
||
| 65 | print('pages_unshared.label pages_unshared')
|
||
| 66 | print('pages_volatile.label pages_volatile')
|
||
| 67 | print('pages_shared.draw AREASTACK')
|
||
| 68 | print('pages_sharing.draw AREASTACK')
|
||
| 69 | print('pages_unshared.draw AREASTACK')
|
||
| 70 | print('pages_volatile.draw AREASTACK')
|
||
| 71 | f6145f0b | Markus Heberling | elif('ksm_pages_relative' in sys.argv[0]):
|
| 72 | 8e3f1d88 | Lars Kruse | print('graph_category system')
|
| 73 | print('graph_title %s Pages Relative' % (title))
|
||
| 74 | print('pages_sharing_shared.info ratio of sharing to shared pages')
|
||
| 75 | print('pages_unshared_sharing.info ratio of unshared to sharing pages')
|
||
| 76 | print('pages_sharing_shared.label pages_sharing_shared')
|
||
| 77 | print('pages_unshared_sharing.label pages_unshared_sharing')
|
||
| 78 | print('pages_sharing_shared.cdef pages_sharing_shared,100,*')
|
||
| 79 | print('pages_unshared_sharing.cdef pages_unshared_sharing,100,*')
|
||
| 80 | 8308ba95 | Markus Heberling | elif('ksm_full_scans' in sys.argv[0]):
|
| 81 | 8e3f1d88 | Lars Kruse | print('graph_category system')
|
| 82 | print('graph_title %s Full Scans' % (title))
|
||
| 83 | print('full_scans.info how many times all mergeable areas have been scanned')
|
||
| 84 | print('full_scans.label full_scans')
|
||
| 85 | 8308ba95 | Markus Heberling | sys.exit(0) |
| 86 | |||
| 87 | 8e3f1d88 | Lars Kruse | |
| 88 | 8308ba95 | Markus Heberling | if len(sys.argv) > 1: |
| 89 | if sys.argv[1] == 'autoconf': |
||
| 90 | autoconf() |
||
| 91 | elif sys.argv[1] == 'config': |
||
| 92 | config() |
||
| 93 | elif sys.argv[1] == 'suggest': |
||
| 94 | suggest() |
||
| 95 | elif sys.argv[1]: |
||
| 96 | print('unknown argument "' + sys.argv[1] + '"')
|
||
| 97 | sys.exit(1) |
||
| 98 | |||
| 99 | 8e3f1d88 | Lars Kruse | pages_shared = int(open('/sys/kernel/mm/ksm/pages_shared').read())
|
| 100 | pages_sharing = int(open('/sys/kernel/mm/ksm/pages_sharing').read())
|
||
| 101 | pages_unshared = int(open('/sys/kernel/mm/ksm/pages_unshared').read())
|
||
| 102 | pages_volatile = int(open('/sys/kernel/mm/ksm/pages_volatile').read())
|
||
| 103 | full_scans = int(open('/sys/kernel/mm/ksm/full_scans').read())
|
||
| 104 | 8308ba95 | Markus Heberling | |
| 105 | 8e3f1d88 | Lars Kruse | if('ksm_pages_absolute' in sys.argv[0]):
|
| 106 | print('pages_shared.value %i' % pages_shared)
|
||
| 107 | print('pages_sharing.value %i' % pages_sharing)
|
||
| 108 | print('pages_unshared.value %i' % pages_unshared)
|
||
| 109 | print('pages_volatile.value %i' % pages_volatile)
|
||
| 110 | elif('ksm_pages_relative' in sys.argv[0]):
|
||
| 111 | print('pages_sharing_shared.value %f'
|
||
| 112 | % (float(pages_sharing) / float(pages_shared) if pages_shared > 0 else 0)) |
||
| 113 | print('pages_unshared_sharing.value %f'
|
||
| 114 | % (float(pages_unshared) / float(pages_sharing) if pages_sharing > 0 else 0)) |
||
| 115 | elif('ksm_full_scans' in sys.argv[0]):
|
||
| 116 | print('full_scans.value %i' % full_scans) |
