Skip to content
This repository
Browse code

Added memory additional memory stats and entropy available

  • Loading branch information...
commit 42b0c90a5604e01dca84dd6b487238bdd1e8578c 1 parent 72ef01b
vuksan authored
34 mem_stats/README.mkdn
Source Rendered
... ... @@ -0,0 +1,34 @@
  1 +mem_stats
  2 +===============
  3 +
  4 +Python module for ganglia 3.1.
  5 +
  6 +This module allows you to collect memory metrics that have been left out of stock
  7 +Ganglia gmond. For example I have it
  8 +
  9 +Install
  10 +===============
  11 +
  12 +Copy mem_stats.py from python_modules to your python modules directory e.g.
  13 +
  14 +/usr/lib64/ganglia/python_modules
  15 +
  16 +and mem_stats.pyconf to
  17 +
  18 +/etc/ganglia/conf.d/
  19 +
  20 +Restart Gmond and you should be set. If you would like additional memory stats collected
  21 +look through mem_stats.py for the metric you want then add it to mem_stats.pyconf e.g.
  22 +if you wanted to keep track of unevictable memory you would add
  23 +
  24 + metric {
  25 + name = "mem_unevictable"
  26 + title = "Unevictable memory"
  27 + value_threshold = 1.0
  28 + }
  29 +
  30 +Restart Gmond and you are done.
  31 +
  32 +## AUTHOR
  33 +
  34 +Author: Vladimir Vuksan https://github.com/vvuksan
22 mem_stats/conf.d/mem_stats.pyconf
... ... @@ -0,0 +1,22 @@
  1 +modules {
  2 + module {
  3 + name = "mem_stats"
  4 + language = "python"
  5 + }
  6 +}
  7 +
  8 +collection_group {
  9 + collect_every = 30
  10 + time_threshold = 45
  11 + metric {
  12 + name = "mem_writeback"
  13 + title = "Mem actively being written to disk"
  14 + value_threshold = 1.0
  15 + }
  16 + metric {
  17 + name = "mem_dirty"
  18 + title = "Mem waiting to be written to disk"
  19 + value_threshold = 1.0
  20 + }
  21 +
  22 +}
368 mem_stats/python_modules/mem_stats.py
... ... @@ -0,0 +1,368 @@
  1 +import sys
  2 +import traceback
  3 +import os
  4 +import re
  5 +
  6 +
  7 +###############################################################################
  8 +# Explanation of metrics in /proc/meminfo can be found here
  9 +#
  10 +# http://www.redhat.com/advice/tips/meminfo.html
  11 +# and
  12 +# http://unixfoo.blogspot.com/2008/02/know-about-procmeminfo.html
  13 +# and
  14 +# http://www.centos.org/docs/5/html/5.2/Deployment_Guide/s2-proc-meminfo.html
  15 +###############################################################################
  16 +
  17 +meminfo_file = "/proc/meminfo"
  18 +
  19 +def metrics_handler(name):
  20 + try:
  21 + file = open(meminfo_file, 'r')
  22 +
  23 + except IOError:
  24 + return 0
  25 +
  26 + value = 0
  27 + for line in file:
  28 + parts = re.split("\s+", line)
  29 + if parts[0] == metric_map[name]['name'] + ":" :
  30 + # All of the measurements are in kBytes. We want to change them over
  31 + # to Bytes
  32 + if metric_map[name]['units'] == "Bytes":
  33 + value = float(parts[1]) * 1024
  34 + else:
  35 + value = parts[1]
  36 +
  37 + return float(value)
  38 +
  39 +def create_desc(skel, prop):
  40 + d = skel.copy()
  41 + for k,v in prop.iteritems():
  42 + d[k] = v
  43 + return d
  44 +
  45 +def metric_init(params):
  46 + global descriptors, metric_map, Desc_Skel
  47 +
  48 + descriptors = []
  49 +
  50 + Desc_Skel = {
  51 + 'name' : 'XXX',
  52 + 'orig_name' : 'XXX',
  53 + 'call_back' : metrics_handler,
  54 + 'time_max' : 60,
  55 + 'value_type' : 'float',
  56 + 'format' : '%.0f',
  57 + 'units' : 'XXX',
  58 + 'slope' : 'both', # zero|positive|negative|both
  59 + 'description' : 'XXX',
  60 + 'groups' : 'memory',
  61 + }
  62 +
  63 + descriptors.append( create_desc(Desc_Skel, {
  64 + "name" : "mem_total",
  65 + "orig_name" : "MemTotal",
  66 + "units" : "Bytes",
  67 + "description": "Total usable ram",
  68 + }))
  69 +
  70 + descriptors.append(create_desc(Desc_Skel, {
  71 + "name" : "mem_free",
  72 + "orig_name" : "MemFree",
  73 + "units" : "Bytes",
  74 + "description": "The amount of physical RAM left unused by the system. ",
  75 + }))
  76 +
  77 + descriptors.append(create_desc(Desc_Skel, {
  78 + "name" : "mem_buffers",
  79 + "orig_name" : "Buffers",
  80 + "units" : "Bytes",
  81 + "description": "Buffers used",
  82 + }))
  83 +
  84 + descriptors.append(create_desc(Desc_Skel, {
  85 + "name" : "mem_cached",
  86 + "orig_name" : "Cached",
  87 + "units" : "Bytes",
  88 + "description": "Cached Memory",
  89 + }))
  90 +
  91 + descriptors.append(create_desc(Desc_Skel, {
  92 + "name" : "mem_swap_cached",
  93 + "orig_name" : "SwapCached",
  94 + "units" : "Bytes",
  95 + "description": "Amount of Swap used as cache memory. Memory that once was swapped out, is swapped back in, but is still in the swapfile",
  96 + }))
  97 +
  98 + descriptors.append(create_desc(Desc_Skel, {
  99 + "name" : "mem_active",
  100 + "orig_name" : "Active",
  101 + "units" : "Bytes",
  102 + "description": "Memory that has been used more recently and usually not reclaimed unless absolutely necessary.",
  103 + }))
  104 +
  105 + descriptors.append(create_desc(Desc_Skel, {
  106 + "name" : "mem_inactive",
  107 + "orig_name" : "Inactive",
  108 + "units" : "Bytes",
  109 + "description": "The total amount of buffer or page cache memory that are free and available",
  110 + }))
  111 +
  112 + descriptors.append(create_desc(Desc_Skel, {
  113 + "name" : "mem_total",
  114 + "orig_name" : "Active(anon)",
  115 + "units" : "Bytes",
  116 + "description": "Active(anon)",
  117 + }))
  118 +
  119 + descriptors.append(create_desc(Desc_Skel, {
  120 + "name" : "mem_inactive_anon",
  121 + "orig_name" : "Inactive(anon)",
  122 + "units" : "Bytes",
  123 + "description": "Inactive(anon)",
  124 + }))
  125 +
  126 + descriptors.append(create_desc(Desc_Skel, {
  127 + "name" : "mem_active_file",
  128 + "orig_name" : "Active(file)",
  129 + "units" : "Bytes",
  130 + "description": "Active(file)",
  131 + }))
  132 +
  133 + descriptors.append(create_desc(Desc_Skel, {
  134 + "name" : "mem_inactive_file",
  135 + "orig_name" : "Inactive(file)",
  136 + "units" : "Bytes",
  137 + "description": "Inactive(file)",
  138 + }))
  139 +
  140 + descriptors.append(create_desc(Desc_Skel, {
  141 + "name" : "mem_unevictable",
  142 + "orig_name" : "Unevictable",
  143 + "units" : "Bytes",
  144 + "description": "Unevictable",
  145 + }))
  146 +
  147 + descriptors.append(create_desc(Desc_Skel, {
  148 + "name" : "mem_mlocked",
  149 + "orig_name" : "Mlocked",
  150 + "units" : "Bytes",
  151 + "description": "Mlocked",
  152 + }))
  153 +
  154 + descriptors.append(create_desc(Desc_Skel, {
  155 + "name" : "mem_swap_total",
  156 + "orig_name" : "SwapTotal",
  157 + "units" : "Bytes",
  158 + "description": "Total amount of physical swap memory",
  159 + }))
  160 +
  161 + descriptors.append(create_desc(Desc_Skel, {
  162 + "name" : "mem_swap_free",
  163 + "orig_name" : "SwapFree",
  164 + "units" : "Bytes",
  165 + "description": "Total amount of swap memory free",
  166 + }))
  167 +
  168 + descriptors.append(create_desc(Desc_Skel, {
  169 + "name" : "mem_dirty",
  170 + "orig_name" : "Dirty",
  171 + "units" : "Bytes",
  172 + "description": "The total amount of memory waiting to be written back to the disk. ",
  173 + }))
  174 +
  175 + descriptors.append(create_desc(Desc_Skel, {
  176 + "name" : "mem_writeback",
  177 + "orig_name" : "Writeback",
  178 + "units" : "Bytes",
  179 + "description": "The total amount of memory actively being written back to the disk.",
  180 + }))
  181 +
  182 + descriptors.append(create_desc(Desc_Skel, {
  183 + "name" : "mem_anonpages",
  184 + "orig_name" : "AnonPages",
  185 + "units" : "Bytes",
  186 + "description": "AnonPages",
  187 + }))
  188 +
  189 + descriptors.append(create_desc(Desc_Skel, {
  190 + "name" : "mem_mapped",
  191 + "orig_name" : "Mapped",
  192 + "units" : "Bytes",
  193 + "description": "Mapped",
  194 + }))
  195 +
  196 + descriptors.append(create_desc(Desc_Skel, {
  197 + "name" : "mem_shmem",
  198 + "orig_name" : "Shmem",
  199 + "units" : "Bytes",
  200 + "description": "Shmem",
  201 + }))
  202 +
  203 + descriptors.append(create_desc(Desc_Skel, {
  204 + "name" : "mem_slab",
  205 + "orig_name" : "Slab",
  206 + "units" : "Bytes",
  207 + "description": "Slab",
  208 + }))
  209 +
  210 + descriptors.append(create_desc(Desc_Skel, {
  211 + "name" : "mem_s_reclaimable",
  212 + "orig_name" : "SReclaimable",
  213 + "units" : "Bytes",
  214 + "description": "SReclaimable",
  215 + }))
  216 +
  217 + descriptors.append(create_desc(Desc_Skel, {
  218 + "name" : "mem_s_unreclaimable",
  219 + "orig_name" : "SUnreclaim",
  220 + "units" : "Bytes",
  221 + "description": "SUnreclaim",
  222 + }))
  223 +
  224 + descriptors.append(create_desc(Desc_Skel, {
  225 + "name" : "mem_kernel_stack",
  226 + "orig_name" : "KernelStack",
  227 + "units" : "Bytes",
  228 + "description": "KernelStack",
  229 + }))
  230 +
  231 + descriptors.append(create_desc(Desc_Skel, {
  232 + "name" : "mem_page_tables",
  233 + "orig_name" : "PageTables",
  234 + "units" : "Bytes",
  235 + "description": "PageTables",
  236 + }))
  237 +
  238 + descriptors.append(create_desc(Desc_Skel, {
  239 + "name" : "mem_nfs_unstable",
  240 + "orig_name" : "NFS_Unstable",
  241 + "units" : "Bytes",
  242 + "description": "NFS_Unstable",
  243 + }))
  244 +
  245 + descriptors.append(create_desc(Desc_Skel, {
  246 + "name" : "mem_bounce",
  247 + "orig_name" : "Bounce",
  248 + "units" : "Bytes",
  249 + "description": "Bounce",
  250 + }))
  251 +
  252 + descriptors.append(create_desc(Desc_Skel, {
  253 + "name" : "mem_writeback_tmp",
  254 + "orig_name" : "WritebackTmp",
  255 + "units" : "Bytes",
  256 + "description": "WritebackTmp",
  257 + }))
  258 +
  259 + descriptors.append(create_desc(Desc_Skel, {
  260 + "name" : "mem_commit_limit",
  261 + "orig_name" : "CommitLimit",
  262 + "units" : "Bytes",
  263 + "description": "CommitLimit",
  264 + }))
  265 +
  266 + descriptors.append(create_desc(Desc_Skel, {
  267 + "name" : "mem_committed_as",
  268 + "orig_name" : "Committed_AS",
  269 + "units" : "Bytes",
  270 + "description": "Committed_AS",
  271 + }))
  272 +
  273 + descriptors.append(create_desc(Desc_Skel, {
  274 + "name" : "mem_vmalloc_total",
  275 + "orig_name" : "VmallocTotal",
  276 + "units" : "Bytes",
  277 + "description": "VmallocTotal",
  278 + }))
  279 +
  280 + descriptors.append(create_desc(Desc_Skel, {
  281 + "name" : "mem_vmalloc_used",
  282 + "orig_name" : "VmallocUsed",
  283 + "units" : "Bytes",
  284 + "description": "VmallocUsed",
  285 + }))
  286 +
  287 + descriptors.append(create_desc(Desc_Skel, {
  288 + "name" : "mem_vmalloc_chunk",
  289 + "orig_name" : "VmallocChunk",
  290 + "units" : "Bytes",
  291 + "description": "VmallocChunk",
  292 + }))
  293 +
  294 + descriptors.append(create_desc(Desc_Skel, {
  295 + "name" : "mem_hardware_corrupted",
  296 + "orig_name" : "HardwareCorrupted",
  297 + "units" : "Bytes",
  298 + "description": "HardwareCorrupted",
  299 + }))
  300 +
  301 + descriptors.append(create_desc(Desc_Skel, {
  302 + "name" : "mem_hugepages_total",
  303 + "orig_name" : "HugePages_Total",
  304 + "units" : "pages",
  305 + "description": "HugePages_Total",
  306 + }))
  307 +
  308 + descriptors.append(create_desc(Desc_Skel, {
  309 + "name" : "mem_hugepages_free",
  310 + "orig_name" : "HugePages_Free",
  311 + "units" : "pages",
  312 + "description": "HugePages_Free",
  313 + }))
  314 +
  315 + descriptors.append(create_desc(Desc_Skel, {
  316 + "name" : "mem_hugepage_rsvd",
  317 + "orig_name" : "HugePages_Rsvd",
  318 + "units" : "pages",
  319 + "description": "HugePages_Rsvd",
  320 + }))
  321 +
  322 + descriptors.append(create_desc(Desc_Skel, {
  323 + "name" : "mem_hugepages_surp",
  324 + "orig_name" : "HugePages_Surp",
  325 + "units" : "pages",
  326 + "description": "HugePages_Surp",
  327 + }))
  328 +
  329 + descriptors.append(create_desc(Desc_Skel, {
  330 + "name" : "mem_hugepage_size",
  331 + "orig_name" : "Hugepagesize",
  332 + "units" : "Bytes",
  333 + "description": "Hugepagesize",
  334 + }))
  335 +
  336 + descriptors.append(create_desc(Desc_Skel, {
  337 + "name" : "mem_directmap_4k",
  338 + "orig_name" : "DirectMap4k",
  339 + "units" : "Bytes",
  340 + "description": "DirectMap4k",
  341 + }))
  342 +
  343 + descriptors.append(create_desc(Desc_Skel, {
  344 + "name" : "mem_directmap_2M",
  345 + "orig_name" : "DirectMap2M",
  346 + "units" : "Bytes",
  347 + "description": "DirectMap2M",
  348 + }))
  349 +
  350 + # We need a metric_map that maps metric_name to the index in /proc/meminfo
  351 + metric_map = {}
  352 +
  353 + for d in descriptors:
  354 + metric_name = d['name']
  355 + metric_map[metric_name] = { "name": d['orig_name'], "units": d['units'] }
  356 +
  357 + return descriptors
  358 +
  359 +def metric_cleanup():
  360 + '''Clean up the metric module.'''
  361 + pass
  362 +
  363 +#This code is for debugging and unit testing
  364 +if __name__ == '__main__':
  365 + metric_init({})
  366 + for d in descriptors:
  367 + v = d['call_back'](d['name'])
  368 + print 'value for %s is %f' % (d['name'], v)
33 ssl/entropy/README.mkdn
Source Rendered
... ... @@ -0,0 +1,33 @@
  1 +entropy
  2 +===============
  3 +
  4 +Python module for ganglia 3.1.
  5 +
  6 +This module allows you to collect available entropy on your system. Why is
  7 +entropy important.
  8 +
  9 +[http://www.chrissearle.org/node/326]
  10 +
  11 + There are two random number sources on linux - /dev/random and /dev/urandom.
  12 + /dev/random will block if there is nothing left in the entropy bit bucket.
  13 + /dev/urandom uses the same bucket - but will not block
  14 + (it can reuse the pool of bits).
  15 +
  16 +Therefore if you are running SSL on the box you want to know this.
  17 +
  18 +Install
  19 +===============
  20 +
  21 +Copy entropy.py from python_modules to your python modules directory e.g.
  22 +
  23 +/usr/lib64/ganglia/python_modules
  24 +
  25 +and entropy.pyconf to
  26 +
  27 +/etc/ganglia/conf.d/
  28 +
  29 +Restart Gmond and you should be set.
  30 +
  31 +## AUTHOR
  32 +
  33 +Author: Vladimir Vuksan https://github.com/vvuksan
17 ssl/entropy/conf.d/entropy.pyconf
... ... @@ -0,0 +1,17 @@
  1 +modules {
  2 + module {
  3 + name = "entropy"
  4 + language = "python"
  5 + }
  6 +}
  7 +
  8 +collection_group {
  9 + collect_every = 15
  10 + time_threshold = 50
  11 +
  12 + metric {
  13 + name = "entropy_avail"
  14 + title = "Entropy Available"
  15 + }
  16 +
  17 +}
44 ssl/entropy/python_modules/entropy.py
... ... @@ -0,0 +1,44 @@
  1 +import sys
  2 +
  3 +
  4 +entropy_file = "/proc/sys/kernel/random/entropy_avail"
  5 +
  6 +def metrics_handler(name):
  7 + try:
  8 + f = open(entropy_file, 'r')
  9 +
  10 + except IOError:
  11 + return 0
  12 +
  13 + for l in f:
  14 + line = l
  15 +
  16 + return int(line)
  17 +
  18 +def metric_init(params):
  19 + global descriptors, node_id
  20 +
  21 + dict = {'name': 'entropy_avail',
  22 + 'call_back': metrics_handler,
  23 + 'time_max': 90,
  24 + 'value_type': 'uint',
  25 + 'units': 'bits',
  26 + 'slope': 'both',
  27 + 'format': '%u',
  28 + 'description': 'Entropy Available',
  29 + 'groups': 'ssl'}
  30 +
  31 + descriptors = [dict]
  32 +
  33 + return descriptors
  34 +
  35 +def metric_cleanup():
  36 + '''Clean up the metric module.'''
  37 + pass
  38 +
  39 +#This code is for debugging and unit testing
  40 +if __name__ == '__main__':
  41 + metric_init({})
  42 + for d in descriptors:
  43 + v = d['call_back'](d['name'])
  44 + print 'value for %s is %u' % (d['name'], v)

0 comments on commit 42b0c90

Please sign in to comment.
Something went wrong with that request. Please try again.