Ganglia python扩展 - 配置文件说明

一、.pyconf配置说明
modules {
  module {
    name     = "example"     //指标名称,也是生成.rrd文件的文件名,此处跟.py文件名保持一致
    language = "python"
    enabled  = yes             //  取值yes或者no
 
    param RandomMax {
      value = 600
    }
    param ConstantValue {
      value = 112
    }
  }
}
 
collection_group {         //  只有配置collection_group,gmod才会去采集相关metric数据
  collect_every  = 10       //   采集间隔时间,单位:秒
  time_threshold = 50    //   发送全部collection_group数据的最长时间间隔,单位:秒
 
  metric {                                               //  定义采集哪些metric
    name = "PyRandom_Numbers"      //  与metric_init中定义的metric name保持一致
    title = "You metric name displayed on gweb"   // 定义在gweb界面上显示的名字,不填写时使用name定义
    value_threshold = 90         //  当超过此阀值时就会发送全部collection_group的数据,不管time_threshold时间是否到了
  }
}
 
man gmond.conf中有关于collection_group的更说细说明和用法:
 

collection_group
You can specify as many collection_group section as you like within the limitations of memory.  A collection_group has the following attributes: collect_once,
collect_every and time_threshold.  A collection_group must also contain one or more metric sections.
 
The metric section has the following attributes: (one of name or name_match; name_match is only permitted if pcre support is compiled in), value_threshold and title.
For a list of available metric names, run the following command:
 
% gmond -m
 
Here is an example of a collection group for a static metric...
 
collection_group {
collect_once   = yes
time_threshold = 1800
metric {
name = "cpu_num"
title = "Number of CPUs"
}
}
 
This collection_group entry would cause gmond to collect the cpu_num metric once at startup (since the number of CPUs will not change between reboots).  The metric
cpu_num would be send every 1/2 hour (1800 seconds).  The default value for the time_threshold is 3600 seconds if no time_threshold is specified.
 
The time_threshold is the maximum amount of time that can pass before gmond sends all metrics specified in the collection_group to all configured udp_send_channels.
A metric may be sent before this time_threshold is met if during collection the value surpasses the value_threshold (explained below).
 
Here is an example of a collection group for a volatile metric...
 
collection_group {
collect_every = 60
time_threshold = 300
metric {
name = "cpu_user"
value_threshold = 5.0
title = "CPU User"
}
metric {
name = "cpu_idle"
value_threshold = 10.0
title = "CPU Idle"
}
}
 
This collection group would collect the cpu_user and cpu_idle metrics every 60 seconds (specified in collect_every).  If cpu_user varies by 5.0% or cpu_idle varies
by 10.0%, then the entire collection_group is sent.  If no value_threshold is triggered within time_threshold seconds (in this case 300), the entire collection_group
is sent.
 
Each time the metric value is collected the new value is compared with the old value collected.  If the difference between the last value and the current value is
greater than the value_threshold, the entire collection group is send to the udp_send_channels defined.
 
It’s important to note that all metrics in a collection group are sent even when only a single value_threshold is surpassed.
 
In addition a user friendly title can be substituted for the metric name by including a title within the metric section.
 
By using the name_match parameter instead of name, it is possible to use a single definition to configure multiple metrics that match a regular expression.  The perl
compatible regular expression (pcre) syntax is used.  This approach is particularly useful for a series of metrics that may vary in number between reboots (e.g.
metric names that are generated for each individual NIC or CPU core).
 
Here is an example of using the name_match directive to enable the multicpu metrics:
 
metric {
name_match = "multicpu_([a-z]+)([0-9]+)"
value_threshold = 1.0
title = "CPU-\\2 \\1"
}
 
Note that in the example above, there are two matches: the alphabetical match matches the variations of the metric name (e.g. idle, system) while the numeric match
matches the CPU core number.  The second thing to note is the use of substitutions within the argument to title.
 
If both name and name_match are specified, then name is ignored.
 

二、metric_init中metric定义说明
metric_init函数中可以配置多个metric(每个metric都是一个字典),每个metric有十项配置,至少要配置前八项:
metric = {
'name': 'PyRandom_Numbers',
'call_back': Random_Numbers,
'time_max': 90,
'value_type': 'uint',
'units': 'N',
'slope': 'both',
'format': '%u',
'description': 'Example module metric (random numbers)',
'groups': 'example,random',
'extra_data':'extradata'
}
有两点需要说明:
1.   其中每一项的值都可以不配置,为空时fill_metric_info函数会赋给一个默认值。
2.   fill_metric_info函数不会判断extra data的key的全法性,因为key是自定义的,只会检查其 value 的合法性,不为string类型时打印错误。

猜你喜欢

转载自wks3000.iteye.com/blog/2237448