Install, configure, and extend the python module in ganglia under fedora

Source: Internet
Author: User
Tags rrdtool

1InstallGanglia

1.1Installation environment

CentOS, fedora

1.2Install the standalone version

Assume that the IP address of the machine is 192.168.1.253. First install the required software.

Copy to ClipboardReference: [www.bkjia.com] rpm-Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpmyum install rrdtool ganglia-gmetad ganglia-gmond ganglia-web httpd php apr-util 1.3 settings

1. Set the File Location of gmond to/etc/gmond. conf and open it for editing. You only need to modify the following content:

Cluster {

Name = "cluster1"

Owner = "owner1"

Latlong = "unspecified"

Url = "unspecified"

}

Udp_send_channel {

Host = 192.168.1.253

Port = 8649

Ttl = 1

}

Udp_recv_channel {

Port = 8649

}

2. Set the File Location of gmetad to/etc/gmetad. conf. Open it and edit it. You only need to modify the following content:

Copy to ClipboardReference: [www.bkjia.com] data_source "my cluster" 192.168.1.253: 8649

1.4 start the service

1. Start gmond

Chkconfig gmond on

Service gmond start

2. Start gmetad

Chkconfig gmetad on

Service gmetad start

3. Start httpd

Chkconfig httpd on

Service httpd start

1.5 observed results

Open localhost/ganglia and you will see the result.

2. python module Extension

2.1 install the python module for Function Extension

Yum install ganglia-gmond-python

2.2 check whether the installation is successful
  1. Gmond. conf has this line of code include ("/etc/ganglia/conf. d /*. conf "). this directory stores the module configuration file. The extension name of the python module configuration file should be. pyconf

  2. Modpython. conf is available under/etc/ganglia/conf. d. The content of this file is:

    /*

    params - path to the directory where mod_python

    should look for python metric modules



    the "pyconf" files in the include directory below

    will be scanned for configurations for those modules

    */

    modules {

    module {

    name = "python_module"

    path = "modpython.so"

    params = "/usr/lib/ganglia/python_modules"

    }

    }



    include ('/etc/ganglia/conf.d/*.pyconf')
    Params specifies the directory where the python module is stored.

    Include ('/etc/ganglia/conf. d/*. pyconf') specifies the directory of the python module configuration file.

  3. Modpython. so is available under/usr/lib/ganglia. This file is a dynamic library file extended by Ganglia Python.

  4. The/usr/lib/ganglia/python_modules folder exists. All python modules are stored in this location. The suffix is. py.

2.3 customize a pyphton Module

It is easy to customize a python module. You only need to compile the. py file according to a certain template, and then place this module (. py) under the/usr/lib/ganglia/python_modules directory. Put the corresponding configuration file (. pyconf) in the/etc/ganglia/conf. d/directory.

The python module may need to access multiple files on the server. Because the user running the python module is the same as the user running gmond, the user running gmond must have the permission to access these files.

After ganglia-gmond-python is installed, an example/usr/lib/ganglia/python_modules/example. py is provided. The following describes the format of the python module and its configuration file for example. py.

2.4 python module Template

Take example as an example (after installing ganglia-gmond-python, it is already included)

import random
descriptors = list()
Random_Max = 50
Constant_Value = 50

def Random_Numbers(name):
'''Return a random number.'''
global Random_Max
return int(random.uniform(0,Random_Max))

def Constant_Number(name):
'''Return a constant number.'''
global Constant_Value
return int(Constant_Value)

def metric_init(params):
'''Initialize the random number generator and create the
metric definition dictionary object for each metric.'''
global descriptors
global Random_Max
global Constant_Value
random.seed()

print '[pyexample] Received the following parameters'
print params

if 'RandomMax' in params:
Random_Max = int(params['RandomMax'])
if 'ConstantValue' in params:
Constant_Value = int(params['ConstantValue'])

d1 = {'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'}

d2 = {'name': 'PyConstant_Number',
'call_back': Constant_Number,
'time_max': 90,
'value_type': 'uint',
'units': 'N',
'slope': 'zero',
'format': '%hu',
'description': 'Example module constant (constant number)'}

descriptors = [d1,d2]
return descriptors

def metric_cleanup():
'''Clean up the metric module.'''
pass

#This code is for debugging and unit testing
if __name__ == '__main__':
params = {'RandomMax': '500',
'ConstantValue': '322'}
metric_init(params)
for d in descriptors:
v = d['call_back'](d['name'])
print 'value for %s is %u' % (d['name'], v)

The module must contain the following three methods:

  • Def metric_init (params ):

  • Def metric_cleanup ():

  • Def metric_handler (name ):

The names of the first two methods must be certain, and the last metric_handler can be named at will.

_ Main _ is easy to debug. You can debug this module separately to check for errors.

The functions of each method are explained below.

Def metric_init (params ):

Initialize the module and run it once when the gmond service is started.

This method must return a dictionary list, with each dictionary representing a metric. The format of each dictionary is as follows:

D1 = {'name': 'pyrandom _ Numbers ', # metric name
'Call _ back': Random_Numbers, # method called after data is collected
'Time _ max ': 90, # is useless...
'Value _ type': 'uint', # string | uint | float | double
'Units ': 'n', # metric unit
'Slope': 'both ', # zero | positive | negative | both
'Format': '% U', # must correspond to value_type (reference: http://docs.python.org/library/stdtypes.html#string-formatting)
'Description': 'example module metric (random numbers) ', # description of metric.
'Groupup': 'example, random '} # the group to which the metric belongs. If it is not defined, it will be allocated to the no_group metric.
Slope option zero | positive | negative | both
  • This value maps to the data source types defined for RRDTool

  • If 'positive 'indicates the Data change rate (calculating the rate of change)

  • If 'negative ',????

  • 'Both 'directly displays the value

  • If 'zero 'is displayed in "Time and String Metrics" or "Constant Metrics" (based on metric's value_type)

In the example, the slope of d2 is zero and is finally displayed in Constant Metrics, instead of in the following panel.

Def metric_cleanup ():

Gmond is executed when it is disabled, and the return value cannot be returned.

Def metric_handler (name ):

Any name can be called in call_back. The parameter name is defined in the metric dictionary.

2.4 pyconf Template

Pyconf is the configuration file of the python module. Its location is/Etc/ganglia/conf. d/example. pyconf(You must create your ownExample. pyconf),The Code is as follows:

Modules {

Module {

Name = "example"

Language = "python"

# The following params are examples only

# They are not actually used by the temp module

Param RandomMax {

Value = 600

}

Param ConstantValue {

Value = 112

}

}

}

Collection_group {

Collect_every = 10

Time_threshold = 50

Metric {

Name = "PyRandom_Numbers"
# Metric to be displayed, which corresponds to the d1 name in example. py
Title = "Random"
# Metric title displayed on the webpage
Value_threshold = 70

}

Metric {

Name = "PyConstant_Number"
# Metric to be displayed, which corresponds to the d2 name in example. py
Title = "Constant"
# Metric title displayed on the webpage
Value_threshold = 70

}

}
Pyconf The file name is best created with you. Python File Name. Contains two modules, Modules And Collection_group .

Modules:Configure each module

Name:Module name,ThePythonConsistent file name

Language:Language

Param:Parameter List. All parameters are used as oneDict (That isMap)PassPythonScriptMetric_init (params)Function.

In this example,Metric_initWhen calling,Params = {"RandomMax": "600", "ConstantValue": "112 "}

Collection_group:TheMetricList, which can be expanded in one moduleMetric

Collect_every:Reporting cycle, in seconds.

Metric: Can have multiple, define eachMetric.

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.