多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > 服務器 > fedora下ganglia安裝、配置及python模塊擴展

fedora下ganglia安裝、配置及python模塊擴展

來源:程序員人生   發布時間:2014-04-05 03:18:29 閱讀次數:3728次

1 安裝ganglia

1.1安裝環境

CentOS, fedora

1.2單機版安裝步驟

假設機器的IP地址是192.168.1.253, 首先安裝好所需要的軟件

rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpmyum install rrdtool ganglia ganglia-gmetad ganglia-gmond ganglia-web httpd php apr apr-util

1.3 設置

1 gmond的設置文件位置是/etc/gmond.conf,打開其進行編輯,只需修改下面的內容:

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 gmetad的設置文件位置是/etc/gmetad.conf,打開其進行編輯,只需修改下面的內容:

data_source "my cluster" 192.168.1.253:8649

1.4 啟動服務

1 啟動gmond

chkconfig gmond on

service gmond start

2 啟動gmetad

chkconfig gmetad on

service gmetad start

3啟動httpd

chkconfig httpd on

service httpd start

1.5 觀察結果

打開localhost/ganglia就可以看到結果了。

2 python模塊擴展

2.1 安裝python模塊進行功能擴展

yum install ganglia-gmond-python

2.2 檢查是否安裝成功

  1. gmond.conf 有這一行代碼include ("/etc/ganglia/conf.d/*.conf").這個目錄是放模塊的配置文件的,python模塊的配置文件的后綴名應該是.pyconf

  2. /etc/ganglia/conf.d下有modpython.conf。這個文件的內容是:

    /*

    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指明了python模塊存放的目錄。

    include ('/etc/ganglia/conf.d/*.pyconf') 指明了python模塊配置文件的目錄。

  3. /usr/lib/ganglia下有modpython.so。該文件是 Ganglia Python 擴展的動態庫文件。

  4. /usr/lib/ganglia/python_modules文件夾存在。所有的python模塊存放在這個位置,后綴名是.py 

2.3 定制一個pyphton模塊

定制一個python模塊很簡單,只需按照一定的模板編寫.py文件,然后將這個模塊(.py)放在 /usr/lib/ganglia/python_modules 目錄下。對應的配置文件(.pyconf)放在/etc/ganglia/conf.d/目錄下。

python模塊可能要訪問服務器的多個文件,由于運行python模塊的用戶和運行gmond的用戶是一致的,所以必須保證運行gmond的用戶有訪問這些文件的權限。

在安裝好ganglia-gmond-python后,已經自帶了一個例子/usr/lib/ganglia/python_modules/example.py。下面將針對example.py解釋python模塊的格式,以及它的配置文件。

2.4 python模塊模板

example為例(安裝完ganglia-gmond-python 后已經自帶)

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)

模塊中必須包含的三個方法是:

  • def metric_init(params):

  • def metric_cleanup():

  • def metric_handler(name):

前面兩個方法的名字必須是一定的,而最后一個 metric_handler可以任意命名。

__main__是便于debug用,可以單獨調試該模塊,以檢測是否有錯。

下面將對每個方法的功能做解釋。

def metric_init(params):

對模塊的初始化,在gmond服務被啟動的時候,運行一次。

該方法必須返回一個詞典列表,每個詞典表示了一個metric的信息。每個詞典的格式如下:

     d1 = {'name': 'PyRandom_Numbers',             #metric的名字
'call_back': Random_Numbers, #收集到數據后調用的方法
'time_max': 90, #沒有什么用。。。
'value_type': 'uint', #string | uint | float | double
'units': 'N', # metric的單位
'slope': 'both', #zero | positive | negative | both
'format': '%u', #必須和value_type對應 (reference: http://docs.python.org/library/stdtypes.html#string-formatting)
'description': 'Example module metric (random numbers)', #對metric的描述,在前端可以看到
'groups': 'example,random'} #這個metric屬于的組,如果沒有定義,會分到no_group metric中
slope的選項 zero | positive | negative | both
  • This value maps to the data source types defined for RRDTool

  • If 'positive',表示數據的變化率(calculating the rate of change)

  • If 'negative', ????

  • 'both' 直接顯示值

  • If 'zero', 將顯示在 "Time and String Metrics" 或者 "Constant Metrics"中(根據metric的value_type)

example這個例子中,d2的slope是zero,最后顯示在Constant Metrics中,而不顯示在下面的面板里。

def metric_cleanup():

gmond關掉的時候執行,不能返回值。

def metric_handler(name):

可以取任何的名字,要在call_back中調用,參數name在是metric字典里定義的name。

2.4 pyconf模板

pyconf是python模塊的配置文件,位置是/etc/ganglia/conf.d/example.pyconf(沒有自帶,需自己創建example.pyconf, 代碼如下

 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,與example.py中的d1名字對應
title = "Random"
#metric在網頁上顯示的標題
value_threshold = 70

}

metric {

name = "PyConstant_Number"
#要顯示的metric,與example.py中的d2名字對應
title = "Constant"
#metric在網頁上顯示的標題
value_threshold = 70

}

}
pyconf的文件名最好和你建立的python文件名對應。包含兩個模塊, modules collection_group

Modules:對每個模塊進行配置

name:模塊名,同時必須與創建的python文件名一致

language: 語言

param:參數列表,所有的參數作為一個dict(map)傳給python腳本的metric_init(params)函數。

本例中,metric_init調用時, params={“RandomMax”:”600”,”ConstantValue”:”112”}

collection_group:需要收集的metric列表,一個模塊中可以擴展任意個metric

collect_every: 匯報周期,以秒為單位。

metric:可以有多個,定義每個metric的信息。

生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 五月婷婷视频在线观看 | 亚洲资源站资源网在线 | 亚洲第一页中文字幕 | 真人毛片免费全部播放完整 | 国产亚洲精品激情一区二区三区 | 美女私人影院 | 国产主播福利一区二区 | 国产亚洲精品久久综合影院 | 最新国产中文字幕 | 国人精品视频在线观看 | 羞羞色院91蜜桃在线观看 | 日韩一区国产一级 | 一本综合久久国产二区 | 国产最新进精品视频 | 欧美成人性色生活18黑人 | 国产午夜精品久久久久九九 | 中文在线播放 | 韩国午夜理伦三级2020豆豌 | 国产一区在线播放 | 91se在线看片国产免费观看 | 欧美最猛性xxxxx亚洲精品 | 亚洲欧美日本韩国 | 久久精品国产免费中文 | 国产 | 久而欧洲野花视频欧洲1 | 欧美一级视频高清片 | 亚洲全网成人资源在线观看 | 亚洲一区在线播放 | 日韩欧美一区二区在线观看 | 亚洲大成色www永久网 | 日本在线高清 | 精品成人在线 | 成人影院久久久久久影院 | 国产综合亚洲欧美日韩一区二区 | 久久www免费人成精品 | 日韩国产欧美在线观看 | 国产日韩久久久精品影院首页 | 最近更新中文字幕7 | 国产视频一区在线播放 | 在线视频一区二区三区在线播放 | 亚洲高清综合 | 国产永久免费高清在线观看视频 |