⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rrd.py

📁 Network Administration Visualized 网络管理可视化源码
💻 PY
字号:
# -*- coding: ISO8859-1 -*-## Copyright 2003, 2004 Norwegian University of Science and Technology## This file is part of Network Administration Visualized (NAV)## NAV is free software; you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation; either version 2 of the License, or# (at your option) any later version.## NAV is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with NAV; if not, write to the Free Software# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA### $Id: $# Authors: Magnus Nordseth <magnun@itea.ntnu.no>#          Erik Gorset	<erikgors@stud.ntnu.no>#"""Module for creating and updating rrd-objects"""import osimport eventfrom debug import debugimport rrdtool as rrdimport dbimport configtry:	import nav.path	RRDDIR = nav.path.localstatedir + '/rrd'except:	# Not properly installed	RRDDIR = '/var/rrd'database = db.db(config.dbconf())def create(filename, netboxid, serviceid=None, handler=""):	step = 300		if RRDDIR and not os.path.exists(RRDDIR):		os.mkdir(RRDDIR)	tupleFromHell = ('%s' % (os.path.join(RRDDIR,filename)),			 '-s %s' % step,			 'DS:STATUS:GAUGE:600:0:1',			 'DS:RESPONSETIME:GAUGE:600:0:300',			 'RRA:AVERAGE:0.5:1:288',			 'RRA:AVERAGE:0.5:6:336',			 'RRA:AVERAGE:0.5:12:720',			 'RRA:MAX:0.5:12:720',			 'RRA:AVERAGE:0.5:288:365',			 'RRA:MAX:0.5:288:365',			 'RRA:AVERAGE:0.5:288:1095',			 'RRA:MAX:0.5:288:1095')	rrd.create(*tupleFromHell)	debug("Created rrd file %s" % filename)	# a bit ugly...	if serviceid:		key="serviceid"		val=serviceid		subsystem = "serviceping"		statusdescr = "%s availability" % handler		responsedescr = "%s responsetime" % handler		unit = '-100%'	else:		key=""		val=""		subsystem= "pping"		statusdescr = "Packet loss"		responsedescr = "Roundtrip time"		unit = '100%'	rrd_fileid = database.registerRrd(RRDDIR, filename, step, netboxid,					  subsystem, key, val)	database.registerDS(rrd_fileid, "RESPONSETIME",			    responsedescr, "GAUGE", "s")	database.registerDS(rrd_fileid, "STATUS", statusdescr, "GAUGE", unit)def update(netboxid,sysname,time,status,responsetime,serviceid=None,handler=""):	"""	time: 'N' or time.time()	status: 'UP' or 'DOWN' (from Event.status)	responsetime: 0-300 or '' (undef)	"""	if serviceid:		filename = '%s.%s.rrd' % (sysname, serviceid)		# typically ludvig.ntnu.no.54.rrd	else:		filename = '%s.rrd' % (sysname)		# typically ludvig.ntnu.no.rrd		os.path.exists(os.path.join(RRDDIR, filename)) or \		       create(filename, netboxid, serviceid,handler)	if status == event.Event.UP:		rrdstatus = 0	else:		rrdstatus = 1		rrdParam = (os.path.join(RRDDIR,filename),		    '%s:%i:%s' % (time, rrdstatus, responsetime))	rrd.update(*rrdParam)	debug("Updated %s" % filename, 7)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -