Munin 结合了来自多个服务器的网络流量图

Munin 结合了来自多个服务器的网络流量图

我一直在搜索 munin wiki 和文档,尝试了各种组合来设置自定义图表,但都以失败告终。

问题是,我根本无法理解创建自定义图表背后的机制,我所做的只是反复试验,却不了解实际发生了什么。Munin 文档在这方面的说明很差。

我正在尝试简单地生成一个包含 5 台服务器的网络流量图表,以便可以快速比较每台服务器的流量。

我只监控 5 台服务器上的 if_eth0,并且想要生成一张同时显示所有 5 台服务器的图表。

答案1

在默认的 /etc/munin/munin.conf (稳定版 2.0) 中,您可以找到以下模板:

# A more complex example of a host tree
#
## First our "normal" host.
# [fii.foo.com]
#       address foo
#
## Then our other host...
# [fay.foo.com]
#       address fay
#
## IPv6 host. note that the ip adress has to be in brackets
# [ip6.foo.com]
#       address [2001::1234:1]
#
## Then we want totals...
# [foo.com;Totals] #Force it into the "foo.com"-domain...
#       update no   # Turn off data-fetching for this "host".
#
#   # The graph "load1". We want to see the loads of both machines...
#   # "fii=fii.foo.com:load.load" means "label=machine:graph.field"
#       load1.graph_title Loads side by side
#       load1.graph_order fii=fii.foo.com:load.load fay=fay.foo.com:load.load
#
#   # The graph "load2". Now we want them stacked on top of each other.
#       load2.graph_title Loads on top of each other
#       load2.dummy_field.stack fii=fii.foo.com:load.load fay=fay.foo.com:load.load
#       load2.dummy_field.draw AREA # We want area instead the default LINE2.
#       load2.dummy_field.label dummy # This is needed. Silly, really.
#
#   # The graph "load3". Now we want them summarised into one field
#       load3.graph_title Loads summarised
#       load3.combined_loads.sum fii.foo.com:load.load fay.foo.com:load.load
#       load3.combined_loads.label Combined loads # Must be set, as this is
#                                                 # not a dummy field!
#
## ...and on a side note, I want them listen in another order (default is
## alphabetically)
#
# # Since [foo.com] would be interpreted as a host in the domain "com", we
# # specify that this is a domain by adding a semicolon.
# [foo.com;]
#       node_order Totals fii.foo.com fay.foo.com

此示例创建了一张新图表,显示两台服务器的负载(取自http://munin-monitoring.org/wiki/LoaningData):

[example.org;Overview]
address 127.0.0.1 
use_node_name no
update no

loadall.update no
loadall.graph_title Load of all servers
loadall.graph_args --base 1000  
loadall.graph_vlabel Load
loadall.graph_scale no
loadall.graph_category system

loadall.graph_order \
    Server1=sv1.example.org:load.load \
    Server2=sv2.example.org:load.load

答案2

首先不太明显的是,每个主机都必须属于某个组。因此,句法无效的

[;myhost]
    address  ip.add.re.ss;

这样你就得到了一个没有主机的组:

[myhost;]
    ...

您可以通过在后面添加以下代码来检查下面这行

foreach my $k (keys %$gah) {
    DEBUG "-- $k";
    foreach my $h (keys %{$gah->{$k}{'hosts'}}) {
        DEBUG "   $h";
    }
}

然后运行(很多输出,您可能想要添加| tail -n 100或其他内容):

$ su - munin -s /bin/bash -c '/usr/share/munin/munin-update --debug'
...
2019/06/14 16:31:43 -- myhost1
2019/06/14 16:31:43 -- myhost2
2019/06/14 16:31:43    myhost2
2019/06/14 16:31:43 -- myhost3
2019/06/14 16:31:43    myhost3
...

所以,

[myhost]                 # group "myhost", conaining host "myhost"
[foo.com]                # group "com", containing host "foo.com"
[group;foo.com]          # group "group", containing host "foo.com"
[group1;group2;foo.com]  # group "group1", containing group "group2",
                         # which in its turn contains host "foo.com"

有了这些,语法基本如下:

[group1;host1]
    ...
[group1;host2]
    ...
[group1;virt_host1]
    virt_plugin1.graph_title Some title
    virt_plugin1.graph_order resulting_field_name1=host1:plugin1.field_name1 resulting_field_name2=host2:plugin2.field_name2

virt_plugin1resulting_field_name1resulting_field_name2都是任意名称。virt_plugin1出现在页面的面包屑中。resulting_field_name*成为图表的标签。除非您覆盖它:

[group1;virt_host1]
    ...
    virt_plugin1.resulting_field_name1.label = my_field_name

关于从哪里获取(如何确认)插件和字段名称(数据源):

$ nc host1 4949
# munin node at host1
fetch plugin1
field_name1.value 0.17
.

然后,如果您要从不同的组借用数据,则必须明确说明:

[group1;host1]
    ...
[group2;host2]
    ...
[group2;virt_host1]
    virt_plugin1.graph_title Some title
    virt_plugin1.graph_order resulting_field_name1=group1:host1.plugin1.field_name1 resulting_field_name2=host2:plugin2.field_name2

关于何时更改配置的说明生效。

什么html_strategy时候cgimunin-html(作为...的一部分munin-cron写道 状态/var/lib/munin/htmlconf.storable每一个5分钟. 状态包含每个主机的设置,并且用过的经过munin-cgi-html作为一个配置

因此,您要么等待下一次更新,要么自己触发更新:

$ su - munin -s /bin/bash -c /usr/share/munin/munin-html

或者:

$ su - munin -s /bin/bash -c munin-cron

在里面相同的 静脉munin-update 更新 /var/lib/munin/datafile.storable.但datafile部分标记为包括基础,而不是htmlconf一。这意味着的内容/etc/munin/munin.conf合并分成datafile部分。并munin-cgi-graph使用datafile部分作为配置

因此您只需重新启动munin-cgi-graph即可注意到变化。

还有最后的 事物munin-cgi-graph Expires标头。这意味着您必须以某种方式重置/禁用浏览器缓存,以便浏览器发出请求。

如果你通知其中一个,但没有通知另一个……我把它留给读者作为练习:)

相关内容