Expand the Python module under Ganglia 3.1.x (translated from the official wiki)

Source: Internet
Author: User

For reference only, not responsible

Gmond extended Python measurement module

In the latest Ganglia3.1.x version, we can create measurement collection modules for C/Python that can be directly inserted into gmond to monitor user-defined measurements.
In earlier versions (2.5.x, 3.0.x), to add custom metrics, you can only call gmetric through the command line, it can insert a measurement to gmond through a cronjob or another process. Although this method is feasible for most people, it makes it difficult to manage user-defined measurements.
This article describes how to compile a python metric monitoring module.

The following components are required to establish/use Python support

  • Ganglia 3.1.x
  • Python 2.3.4 + (this is the oldest supported version tested on RHEL4. Versions later than 2.3 should work normally)
  • Python development header file (usually in the python-devel package)
Install RPM

If you install the Python measurement module on the RPM-based software package management system, install the "ganglia-gmond-modules-python" software package. This includes everything developed by the Python module.

APT Installation

Run apt-get install ganglia-monitor
Next, let's take a look at the following precautions:

Source code Installation

If you compile from the source code, make sure the-with-python option is added. This option is automatically added if the Python interpreter is detected.

Check

To ensure that Python-supported settings are available for Ganglia installation, check the following settings:

  • Gmond. conf has a line of include ("/etc/ganglia/conf. d/*. conf"). This is the directory where you should place the python module configuration file in. pyconf format.
  • The modpython. conf file should exist in/etc/ganglia/conf. d. It contains the location of the pyconf file.
  • Modpython. so should be in/usr/lib {64}/ganglia
  • The/usr/lib {64}/ganglia/python_modules Directory should exist. This is the directory where you put the python module File ending with. py.

If you install python module support through a binary file, the above information should be automatically generated. If some files are missing, submit the bug to us.

Precautions for Ubuntu 10.10

Ubuntu 10.10 does not support Python. You need:

  • Create/etc/ganglia/conf. d/modpython. conf to make it look like this, https://sourceforge.net/apps/trac/ganglia/browser/trunk/monitor-core/gmond/modules/conf.d/modpython.conf.in
Modules {
Module {
Name = "python_module"
Path = "/usr/lib (64)/ganglia/modpython. so"
Params = "/usr/lib (64)/ganglia/python_modules"
}
}
Include ('/etc/ganglia/conf. d/*. pyconf ')
  • Create directory/usr/lib (64)/ganglia/python_modules
  • Make sure that/usr/lib (64)/ganglia/modpython. so already exists (Ubuntu 10.10 will have this file by default if you install apt)
Compile a custom Python Module

Writing a Python module is very simple. You only need to compile the template, and then put the modules ending with. py under/usr/lib (64)/ganglia/python_modules. At the same time, place the corresponding configuration file in. pyconf format under/etc/ganglia/conf. d.
If your Python module needs to access some files on the server, remember that it is executed by the user running the gmond process. In other words, if gmond runs with nobody, your module is running with nobody. Therefore, make sure that the user running gmond has the permission to access these files. Ganglia has sample modules in/usr/lib (64)/ganglia/python_modules/example. py.

Sample Module

Let's look at a real Python module instance that monitors the host temperature. It reads the/proc file system and calls it temp. py.

Acpi_file = "/proc/acpi/thermal_zone/THRM/temperature"

Def temp_handler (name ):
Try:
F = open (acpi_file, 'R ')

Handle t IOError:
Return 0

For l in f:
Line = l. split ()

Return int (line [1])

Def metric_init (params ):
Global descriptors, acpi_file

If 'acpi _ file' in params:
Acpi_file = params ['acpi _ file']

D1 = {'name': 'temp ',
'Call _ back': temp_handler,
'Time _ max ': 90,
'Value _ type': 'uint ',
'Units ': 'C ',
'Slope': 'both ',
'Format': '% U ',
'Description': 'temperature of host ',
'Groupup': 'health '}

Descriptors = [d1]

Return descriptors

Def metric_cleanup ():
'''Clean up the metric module .'''
Pass

# This code is for debugging and unit testing
If _ name _ = '_ main __':
Metric_init ({})
For d in descriptors:
V = d ['call _ back'] (d ['name'])
Print 'value for % s is % U' % (d ['name'], v) Details of Python: click here
Python: click here

Recommended reading:

Python development technology details. (Zhou Wei, Zong Jie). [hd PDF scan version + book guide video + code]

Obtain Linux information using a Python script

  • 1
  • 2
  • Next Page

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.