The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
# Memory checks
# ============================================

include common.cfg

# Base definition for memory relative checks
# (i.e. checks with a base value). Should 
# not be used directly
<Check memory_relative_base>
   Use = relative_base($0,$1)
   Unit = B
   BaseUnit = B
</Check>

# Relative Heap Memory used by the application. This
# is the ratio between used heap memory and the maximal
# available heap memory
# $0: Critical value (optional)
# $1: Warning value (optional)
<Check memory_heap>
   Use = memory_relative_base($0,$1)
   Value = java.lang:type=Memory/HeapMemoryUsage/used
   Base = java.lang:type=Memory/HeapMemoryUsage/max
   Label = Heap-Memory: $BASE
   Name = Heap
   MultiCheckPrefix
</Check>

# Relative non-heap memory.  The JVM has memory other than the heap,
# referred to as non-heap memory. It stores per-class structures such
# as runtime constant pool, field and method data, and the code for
# methods and constructors, as well as interned Strings. More detailed
# information can be obtained from the pool checks defined below
# $0: Critical value (optional)
# $1: Warning value (optional)
<Check memory_non_heap>
   Use = memory_relative_base
   Value = java.lang:type=Memory/NonHeapMemoryUsage/used
   Base = java.lang:type=Memory/NonHeapMemoryUsage/max
   Label = Non-Heap-Memory: $BASE
   Name = Non-Heap
   MultiCheckPrefix
</Check>

# =============================================================
# Memory pool checks. These are specific to a Sun/Oracle JVM.

# Base definition for pool based checks
# $0: Label prefix and name to used
# $1: Critical value (optional)
# $2: Warning value (optional)
<Check memory_pool_base>
   Use = memory_relative_base($1,$2)
   Value = java.lang:type=MemoryPool,name=$0/Usage/used   
   Base = java.lang:type=MemoryPool,name=$0/Usage/max
   Label = $0 : $BASE
   Name = $0
</Check>

# Base definition for garbage collection count
# This checks count the number of garbage collections per 
# minute
# $0: Name of garbage collector (used as Label as well)
# $1: Critical value (default: 30)
# $2: Warning value (default: 20)
<Check memory_gc_count_base>
   Use = count_per_minute("GC count")
   Value = java.lang:type=GarbageCollector,name=$0/CollectionCount

   Label = $0 : $BASE
   Name = $0 count

   Critical = 30
   Warning = 20
</Check>

# Base definition for garbage time measurements
# This checks measure the ratio the garbage collection takes from a minute
# (e.g. how many percent of a minute is used for garbage collecting)

# $0: Name of garbage collector (used as Label as well)
# $1: Critical value in percent (default: 20)
# $2: Warning value in percent (default: 10)

# WARNING: THIS CHECK HAS CHANGED IN 1.08. Remove the 'Base' and adapt the label 
# to obtain the old behaviour.
<Check memory_gc_time_base>
   Value = java.lang:type=GarbageCollector,name=$0/CollectionTime

   Label = %2.2r% GC Overhead
   Name = $0 time
   
   Delta 60

   # Next line switches on relative checking to get the percentual overhead   
   # for a garbage collection
   Base = 60000

   Critical = ${1:20}
   Warning = ${2:10}
</Check>

# The paralled garbage collectors and memory 
# pools switched on with -XX:+UseParallelGC.
# Used by 64bit server VMs by default.
<MultiCheck memory_pools_parallel>
  Check = memory_pool_base("PS Eden Space",100,100)
  Check = memory_pool_base("PS Survivor Space",100,100)
  Check = memory_pool_base("PS Old Gen")
  Check = memory_pool_base("PS Perm Gen")
</MultiCheck>

<MultiCheck memory_gc_count_parallel>
  Check = memory_gc_count_base("PS Scavenge")
  Check = memory_gc_count_base("PS MarkSweep")
</MultiCheck>

# Since 1.08: Relative time instead of absolute values. 
<MultiCheck memory_gc_time_parallel>
  Check = memory_gc_time_base("PS Scavenge")
  Check = memory_gc_time_base("PS MarkSweep")
</MultiCheck>

# Garbage collectors and memory pools used for 
# -XX:+UseConcMarkSweepGC and -XX:+UseParNewGC
# used by default by OS X, client vm.
<MultiCheck memory_pools_concurrent>
   Check = memory_pool_base("Par Eden Space")
   Check = memory_pool_base("Par Survivor Space")
   Check = memory_pool_base("CMS Old Gen")
   Check = memory_pool_base("CMS Perm Gen")
</MultiCheck>

<MultiCheck memory_gc_count_concurrent>
  Check = memory_gc_count_base("ParNew")
  Check = memory_gc_count_base("ConcurrentMarkSweep")
</MultiCheck>

# Since 1.08: Relative time instead of absolute values. 
<MultiCheck memory_gc_time_concurrent>
  Check = memory_gc_time_base("ParNew")
  Check = memory_gc_time_base("ConcurrentMarkSweep")
</MultiCheck>


# Garbage collector and memory pools used 
# when -XX:+UseSerialGC is used. Seems to be the default
# on linux for -client and -server VMs
<MultiCheck memory_pools_serial>
   Check = memory_pool_base("Eden Space")
   Check = memory_pool_base("Survivor Space")
   Check = memory_pool_base("Tenured Gen")
   Check = memory_pool_base("Perm Gen")
</MultiCheck>

<MultiCheck memory_gc_count_serial>
  Check = memory_gc_count_base("Copy")
  Check = memory_gc_count_base("MarkSweepCompact")
</MultiCheck>

# Since 1.08: Relative time instead of absolute values. 
<MultiCheck memory_gc_time_serial>
  Check = memory_gc_time_base("Copy")
  Check = memory_gc_time_base("MarkSweepCompact")
</MultiCheck>

<Check memory_code_cache>
   Use = memory_pool_base("Code Cache")
</Check>

# ================================================
# Collection of related checks.

# Overall view to the memory statistics
<MultiCheck memory>
   Check memory_heap
   Check memory_non_heap
</MultiCheck>