[Linux Utility]munin-node plugin configuration and plugin authoring

Source: Internet
Author: User

The 2 articles used in Munin are described in the previous article:

    • [Linux Utilities] Installation and configuration of Linux monitoring tools Munin
    • [Linux Utilities] Display of Linux monitoring Tools Munin (Nginx)

This time introduces the installation configuration of Munin-node plug-ins and the writing of plugins. plug-in configurationMunin-node itself integrates a lot of plug-ins, just need to directly build a soft chain on it. Like Nginx, Apach, MySQL are ready to use plug-ins can be used. Munin plugins are saved by default in/etc/munin/plugins. Go inside to see a lot of soft links, soft links to/usr/share/munin/plugins files in this directory. Yes, Munin's plugins are placed under/usr/share/munin/plugins. The use is quite simple, only need to refer to the original example, directly build a soft chain past can be. The following is an example of MySQL plugin:
Ln -s/usr/share/munin/plugins/mysql_threads/etc/munin/plugins/mysql_threadsLn -s/usr/ share/munin/plugins/mysql_queries/etc/munin/plugins/mysql_queriesLn -s/usr/share/munin/ plugins/mysql_bytes/etc/munin/plugins/mysql_bytesln -s/usr/share/munin/plugins/mysql_innodb/ Etc/munin/plugins/mysql_innodb
Then restart the Munin-node to take effect.
Service Munin-node Restart
Plugin AuthoringWhat if there is no plug-in support for apps that need to be monitored? Also very simple. Random open an existing plug-in, will find specific code content, observed that writing a plugin is not very difficult. and the Munin-node plugin supports shell, Python, and Perl. You can also write plugins based on the language you're familiar with. plug-in instances provided by Munin-nodeTake the Threads (/usr/share/munin/plugins/threads) plugin as an example, we can view the internal code:
#!/bin/SH# -*-SH-*-# vim:ft=SH if[" $"="autoconf"]; Then    grep-Q'^threads'/proc/$$/status &&Echo "Yes"||Echo "No"Exit0fi if[" $"="Config"]; Then    Echo 'graph_title Number of threads'    #Echo 'Graph_args--base 1000-l 0'    Echo 'Graph_vlabel Number of threads'    Echo 'Graph_category Processes'    Echo 'Graph_info This graph shows the number of threads.'    Echo 'Threads.label Threads'    Echo 'Threads.info the current number of threads.'Exit0fi grep-S'^threads'/proc/[0-9]*/status |awk '{sum + = $;} END {print "Threads.value", Sum;}'
You can directly execute plug-in files to view the structure of the output data. You can see that all the output formats are the same and have 1 parameters. Use parameters autoconf, config, and do not use parameters to view the output: #SH Threads autoconfYes #Sh threads configGraph_title number of Threadsgraph_vlabel number of threadsgraph_category Processesgraph_info This graph shows the number of Threads.threads.label Threadsthreads.info The current number of threads. #SH ThreadsThreads.value 174 parameter DescriptionautoconfUsed to detect whether a process exists. Not necessary.ConfigWhen using the config parameter, the content of the output is the configuration information of the drawing, and the meaning of the field can be known by viewing the field meaning.do not use parametersWhen parameters are not used, the output is the specific number of processes. This is related to the specific command output. Grep-s ' ^threads '/proc/[0-9]*/status | awk ' {sum + = $;} END {print "Threads.value", Sum;} ' Custom PluginsNow that we know what each parameter needs to be output, we can draw a gourd and we can write our own plugin. A specific example is given below to monitor the memory and CPU of a game server.
#!/bin/SHkeyword=munin-node Case$1 inch(config)Cat<<'EOM'graph_title My_titlegraph_vlabel (%) Graph_args--base +-L0Graph_scale nograph_category My_categoryeomPSAux |grep$keyword |grep-Vgrep|awk '{print $3,$4}'| whileRead CPU mem Do   Echo "Cpu.label%cpu"   Echo "cpu.warning"   Echo "cpu.critical"   Echo "Cpu.value $cpu"    Echo "Mem.label%MEM"   Echo "mem.warning"   Echo "mem.critical"   Echo "Mem.value $mem"  DoneExit0;;EsacPSAux |grep$keyword |grep-Vgrep|awk '{print $3,$4}'| whileRead CPU mem Do   Echo "Cpu.value $cpu"   Echo "Mem.value $mem" Done
There is no use of the autoconf parameter, in fact should be used, in case the process does not exist what to do, right. In fact, when there is no statistical value, the chart is empty, and all that is said autoconf parameter is not necessary. This example is different from threads, where multiple data is collected. After the plugin has been written, it needs to be configured in/etc/munin/plugin-conf. Add the above example to save the Munin-node_cpu file name. Add a file under/etc/munin/plugin-conf, name can be arbitrary, such as Munin_info:
Cat munin_info[munin-node_cpu]user root
Then restart the Munin-node to do it. Yes, the plugin is actually very simple to write. Just use Perl, python, or shell whenever the output format meets your requirements. Specific monitoring can be fully customizable. For example, I assume that I have access to the number of online games, I can also monitor, when the number of people in the online more than the time to give the relevant tips.

Start using the standalone blog, the original address is here:

    • Installation and configuration of the Munin
    • Munin Display (Nginx)
    • Munin plug-in configuration and plugin authoring
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.