ganglia Spoof with Modules or gmetric

简介:
spoof的作用是篡改metric包里主机IP, 主机名, metric名的信息.
例如我们要在A主机监控其他主机或应用, 同时通过A主机发送到网络上的metric接收者, 正常情况下, metric发出去会携带A主机的IP, 主机名. 那么就导致接收方会按照IP将信息写入A主机对应的RRD文件, 在gweb上显示时, 也会显示在A主机的监控项里面.
但实际上我们希望它写入其他主机对应的rrd文件.
如图1, 在不使用spoof时, 如果从a主机将b,c,d的监控数据发出去, 会写入a主机IP对应的rrd file.
ganglia Spoof with Modules or gmetric - 德哥@Digoal - PostgreSQL research
当使用spoof后, 我们可以纂改metric携带的IP, hostname, metric name.
因此可以从a主机发出, 并写入对应的rrd file. 如下图 :   
ganglia Spoof with Modules or gmetric - 德哥@Digoal - PostgreSQL research
在模块中使用变量 SPOOF_HOST and  SPOOF_NAME后, gmond会将这个数据包按照spoof来处理.
Spoofing with Modules
Spoofing is a concept that allows an instance of gmond running on one host to report
the metrics that it gathers as if they were coming from an instance of gmond running
on another host. In other words, gmond can fool the rest of Ganglia into thinking that
the metrics that it is gathering are really coming from somewhere else. Spoofing was a
concept originally designed and implemented as part of the gmetric utility. The idea of
being able to report metrics as if they originated somewhere else was so popular in
gmetric, that it only seemed natural to extend that idea into gmond modules as well.
Spoofing a metric within a gmond Python module is a matter of adding extra metadata
elements to the metric description. Each metric definition, as previously described, may
contain extra elements, which indicate to gmond that special handling of the metric is
required.  These  extra  elements  include  SPOOF_HOST and  SPOOF_NAME.  By  adding
SPOOF_HOST and  SPOOF_NAME to  a  metric  definition,  gmond  will  treat  the  metric  as  a
spoofed metric rather than an actual metric.
Because the concept of spoofing original came from the gmetric utility, the format of
the  SPOOF_HOSTand  SPOOF_NAMEvalues also follow the same format as defined by gmetric.
The SPOOF_HOSTextra element specifies the IP address and the hostname of the host for
which the metric should be reported. The format of the SPOOF_HOSTvalue must be the
IP address followed by the hostname separated by a colon (ip_address:host_name).
When gmond sees this extra element, it will automatically replace the originating IP
address  and  hostname  with  the  values  that  are  specified  by  this  element.  The
SPOOF_NAMEextra element is used to indicate to gmond that the metric definition should
assume the name of a different metric. In other words, if spoofing is being used to gather
the boot time of a remote host, the SPOOF_NAMEcan be set to boot_timeto indicate that
this metric is actually an alias of the standard boot_timemetric. This concept makes a
little more sense when you consider that each spoofed metric must also have a unique
name.
Let’s take the example of the  boot_time  metric. If you have a metric module that gathers
the boot time of not only the host on which it is currently running but also several other
remote hosts, the dictionary of metric definitions that is returned by this module must
include a metric definition for the local  boot_timemetric as well as each remote host
boot_time. Because gmond requires that every metric defined by a module have a unique
metric name, there would be no way to define three different metrics all with the same
boot_timemetric name. Therefore, in order to uniquely identify each metric by its name,
a common practice when defining a spoofed metric is to include the hostname as part
of the metric name (boot_time:my_host). But naming a metric in this way would cause
each of the remote host boot time metrics to show up in the web frontend as separate
metrics that don’t actually correspond to the boot time of the host. In order to fix this
problem, use the SPOOF_NAMEextra element to tell gmond that the metric definition is
actually an alias for the standard boot_timemetric.
Just to make sure that you got all of that, let’s summarize. Specifying  SPOOF_HOSTas part
of the metric definition tells gmond that this metric is a spoofed metric. The format of
its value should be the remote host IP address followed by the hostname separated by
a colon. Specifying  SPOOF_NAMEas part of the metric definition tells gmond that the spoof
name is really an alias for another metric. Finally, the name of each spoofed metric must
be unique. In addition to that, you will need to remember that when your metric callback function is called, the name parameter that is passed in will be the unique name
of the metric and not the SPOOF_NAME. By passing in the unique name, this helps your
callback function determine not only the metric it needs to gather but also the remote
host that it should gather the metric from.


使用gmetric来填写spoof信息 : 
  -S, --spoof=STRING    IP address and name of host/device (colon separated) we 
                          are spoofing  (default=`')
  -n, --name=STRING     Name of the metric

[root@150 data03]# gmetric -h
gmetric 3.6.0

The Ganglia Metric Client (gmetric) announces a metric
on the list of defined send channels defined in a configuration file

Usage: gmetric [OPTIONS]...

  -h, --help            Print help and exit
  -V, --version         Print version and exit
  -c, --conf=STRING     The configuration file to use for finding send channels 
                           (default=`/opt/ganglia-core-3.6.0/etc/gmond.conf')
  -n, --name=STRING     Name of the metric
  -v, --value=STRING    Value of the metric
  -t, --type=STRING     Either 
                          string|int8|uint8|int16|uint16|int32|uint32|float|double
  -u, --units=STRING    Unit of measure for the value e.g. Kilobytes, Celcius  
                          (default=`')
  -s, --slope=STRING    Either zero|positive|negative|both  (default=`both')
  -x, --tmax=INT        The maximum time in seconds between gmetric calls  
                          (default=`60')
  -d, --dmax=INT        The lifetime in seconds of this metric  (default=`0')
  -g, --group=STRING    Group(s) of the metric (comma-separated)
  -C, --cluster=STRING  Cluster of the metric
  -D, --desc=STRING     Description of the metric
  -T, --title=STRING    Title of the metric
  -S, --spoof=STRING    IP address and name of host/device (colon separated) we 
                          are spoofing  (default=`')
  -H, --heartbeat       spoof a heartbeat message (use with spoof option)


[参考]
相关文章
|
7月前
|
前端开发 JavaScript
ES6(三)
es6补充知识
46 1
|
3月前
ES6常用知识小结
ES6常用知识小结
13 0
|
7月前
ES6(二)
es6相关知识
33 0
|
8月前
|
前端开发 容器
ES6 Day04
ES6 Day04
56 0
|
9月前
初学es6
初学es6
53 0
|
JavaScript 前端开发 API
【ES6】Module模块详解
【ES6】Module模块详解
170 0
|
JavaScript 前端开发 Java
浅析-ES6
后端项目搭建完毕,接下来就是前端页面了。不过在这之前需要一些准备工作。我们需要学习ES6的语法标准。
浅析-ES6
|
JavaScript 前端开发
Day19 ES6
ECMAScript 6.0
79 0
|
网络架构
Day20 ES6
ECMAScript 6.0
53 0
|
网络架构
那些必会用到的 ES6 精粹(中)
那些必会用到的 ES6 精粹(中)
95 0