| Trees | Indices | Help |
|
|---|
|
|
1 ###########################################################################
2 #
3 # This program is part of Zenoss Core, an open source monitoring platform.
4 # Copyright (C) 2007, Zenoss Inc.
5 #
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License version 2 as published by
8 # the Free Software Foundation.
9 #
10 # For complete information please visit: http://www.zenoss.com/oss/
11 #
12 ###########################################################################
13
14 __doc__="""PerformanceConf
15
16 The configuration object for Performance servers
17
18
19 $Id: PerformanceConf.py,v 1.30 2004/04/06 18:16:30 edahl Exp $"""
20
21 __version__ = "$Revision: 1.30 $"[11:-2]
22
23 import os
24 import zlib
25 import transaction
26 import logging
27 log = logging.getLogger("zen.PerformanceConf")
28
29 try:
30 from base64 import urlsafe_b64encode
31 raise ImportError
32 except ImportError, ex:
34 import base64
35 s = base64.encodestring(s)
36 s = s.replace('+','-')
37 s = s.replace('/','_')
38 s = s.replace('\n','')
39 return s
40
41 import xmlrpclib
42
43 from ZODB.POSException import POSError
44 from AccessControl import ClassSecurityInfo
45 from Globals import DTMLFile
46 from Globals import InitializeClass
47
48 from Products.PythonScripts.standard import url_quote
49 from AccessControl import Permissions as permissions
50
51 from Products.ZenRelations.RelSchema import *
52
53 from Products.ZenUtils.Exceptions import ZentinelException
54 from Products.ZenUtils.Utils import basicAuthUrl, zenPath
55 from Products.ZenEvents.ZenEventClasses import Status_Snmp
56
57 from Monitor import Monitor
58 from StatusColor import StatusColor
59
60 from ZenDate import ZenDate
61
62 PERF_ROOT=None
63
65 global PERF_ROOT
66 if PERF_ROOT is None:
67 PERF_ROOT = zenPath("perf")
68 if target.startswith("/"): target = target[1:]
69 return os.path.join(PERF_ROOT, target)
70
72 """make a device class"""
73 dc = PerformanceConf(id)
74 context._setObject(id, dc)
75
76 if REQUEST is not None:
77 REQUEST['RESPONSE'].redirect(context.absolute_url() + '/manage_main')
78
79 addPerformanceConf = DTMLFile('dtml/addPerformanceConf',globals())
80
82 '''Configuration for Performance servers'''
83 portal_type = meta_type = "PerformanceConf"
84
85 monitorRootName = "Performance"
86
87 security = ClassSecurityInfo()
88 security.setDefaultAccess('allow')
89
90 eventlogCycleInterval = 60
91 perfsnmpCycleInterval = 300
92 processCycleInterval = 180
93 statusCycleInterval = 60
94 winCycleInterval = 60
95 winmodelerCycleInterval = 60
96
97 configCycleInterval = 6*60
98
99 renderurl = '/zport/RenderServer'
100 renderuser = ''
101 renderpass = ''
102
103 # defaultRRDCreateCommand = (
104 # 'RRA:AVERAGE:0.5:1:2016', # every 5 mins for 7 days
105 # 'RRA:AVERAGE:0.5:4:2016', # every 20 mins for 4 weeks
106 # 'RRA:AVERAGE:0.5:24:1488', # every 2 hours for 4 months
107 # 'RRA:AVERAGE:0.5:288:730', # every 1 day for 2 years
108 # 'RRA:MAX:0.5:4:2016',
109 # 'RRA:MAX:0.5:24:1488',
110 # 'RRA:MAX:0.5:288:730',
111 # )
112
113 # make the default rrdfile size smaller
114 # we need the space to live within the disk cache
115 defaultRRDCreateCommand = (
116 'RRA:AVERAGE:0.5:1:600', # every 5 mins for 2 days
117 'RRA:AVERAGE:0.5:6:600', # every 30 mins for 12 days
118 'RRA:AVERAGE:0.5:24:600', # every 2 hours for 50 days
119 'RRA:AVERAGE:0.5:288:600', # every day for 600 days
120 'RRA:MAX:0.5:6:600',
121 'RRA:MAX:0.5:24:600',
122 'RRA:MAX:0.5:288:600',
123 )
124
125 _properties = (
126 {'id':'eventlogCycleInterval','type':'int','mode':'w'},
127 {'id':'perfsnmpCycleInterval','type':'int','mode':'w'},
128 {'id':'processCycleInterval','type':'int','mode':'w'},
129 {'id':'statusCycleInterval','type':'int','mode':'w'},
130 {'id':'winCycleInterval','type':'int','mode':'w'},
131 {'id':'winmodelerCycleInterval','type':'int','mode':'w'},
132 {'id':'configCycleInterval','type':'int','mode':'w'},
133 {'id':'renderurl','type':'string','mode':'w'},
134 {'id':'renderuser','type':'string','mode':'w'},
135 {'id':'renderpass','type':'string','mode':'w'},
136 {'id':'defaultRRDCreateCommand','type':'lines','mode':'w'},
137 )
138 _relations = Monitor._relations + (
139 ("devices", ToMany(ToOne,"Products.ZenModel.Device","perfServer")),
140 )
141
142 # Screen action bindings (and tab definitions)
143 factory_type_information = (
144 {
145 'immediate_view' : 'viewPerformanceConfOverview',
146 'actions' :
147 (
148 { 'id' : 'overview'
149 , 'name' : 'Overview'
150 , 'action' : 'viewPerformanceConfOverview'
151 , 'permissions' : (
152 permissions.view, )
153 },
154 { 'id' : 'edit'
155 , 'name' : 'Edit'
156 , 'action' : 'editPerformanceConf'
157 , 'permissions' : ("Manage DMD",)
158 },
159 { 'id' : 'viewHistory'
160 , 'name' : 'Modifications'
161 , 'action' : 'viewHistory'
162 , 'permissions' : (
163 permissions.view, )
164 },
165 )
166 },
167 )
168
169 security.declareProtected('View','getDefaultRRDCreateCommand')
171 """Get the default RRD Create Command, as a string.
172 For example:
173 '''RRA:AVERAGE:0.5:1:600
174 RRA:AVERAGE:0.5:6:600
175 RRA:AVERAGE:0.5:24:600
176 RRA:AVERAGE:0.5:288:600
177 RRA:MAX:0.5:288:600'''
178 """
179 return "\n".join(self.defaultRRDCreateCommand)
180
181
183 ''' Return a url for the given graph options and date range
184 '''
185 newOpts = []
186 width = 0
187 for o in gopts:
188 if o.startswith('--width'):
189 width = o.split('=')[1].strip()
190 continue
191 newOpts.append(o)
192 encodedOpts = urlsafe_b64encode(zlib.compress('|'.join(newOpts), 9))
193 url = "%s/render?gopts=%s&drange=%d&width=%s" % (
194 self.renderurl, encodedOpts, drange, width)
195 if self.renderurl.startswith("proxy"):
196 url = url.replace("proxy", "http")
197 return "/zport/RenderServer/render" \
198 "?remoteUrl=%s&gopts=%s&drange=%d&width=%s" % (
199 url_quote(url), encodedOpts, drange, width)
200 else:
201 return url
202
203
206 """set the full path of the target and send to view"""
207 targetpath = performancePath(targetpath)
208 gopts = view.getGraphCmds(context, targetpath)
209 return self.buildGraphUrlFromCommands(gopts, drange)
210
211
213 """set the full paths for all targts in map and send to view"""
214 ntm = []
215 for target, targettype in targetsmap:
216 if target.find('.rrd') == -1: target += '.rrd'
217 fulltarget = performancePath(target)
218 ntm.append((fulltarget, targettype))
219 gopts = view.multiGraphOpts(context, ntm)
220 gopts = url_quote('|'.join(gopts))
221 url = "%s/render?gopts=%s&drange=%d" % (self.renderurl,gopts,drange)
222 if self.renderurl.startswith("http"):
223 return "/zport/RenderServer/render?remoteUrl=%s&gopts=%s&drange=%d" % (url_quote(url),gopts,drange)
224 else:
225 return url
226
228 "return the for a list of custom gopts for a graph"
229 gopts = self._fullPerformancePath(gopts)
230 gopts = url_quote('|'.join(gopts))
231 url = "%s/render?gopts=%s&drange=%d" % (self.renderurl,gopts,drange)
232 if self.renderurl.startswith("http"):
233 return "/zport/RenderServer/render?remoteUrl=%s&gopts=%s&drange=%d" % (url_quote(url),gopts,drange)
234 else:
235 return url
236
238 "fill out full path for custom gopts and call to server"
239 gopts = self._fullPerformancePath(gopts)
240 renderurl = str(self.renderurl)
241 if renderurl.startswith("http"):
242 url = basicAuthUrl(str(self.renderuser),
243 str(self.renderpass),
244 renderurl)
245 server = xmlrpclib.Server(url)
246 else:
247 server = self.getObjByPath(renderurl)
248 return server.summary(gopts)
249
250
252 "fill out full path and call to server"
253 url = self.renderurl
254 if url.startswith('proxy'):
255 url = self.renderurl.replace('proxy','http')
256 if url.startswith("http"):
257 url = basicAuthUrl(self.renderuser, self.renderpass, self.renderurl)
258 server = xmlrpclib.Server(url)
259 else:
260 if not self.renderurl: raise KeyError
261 server = self.getObjByPath(self.renderurl)
262 return server.currentValues(map(performancePath, paths))
263
264
266 "add full path to a list of custom graph options"
267 for i in range(len(gopts)):
268 opt = gopts[i]
269 if opt.find("DEF") == 0:
270 opt = opt.split(':')
271 var, file = opt[1].split('=')
272 file = performancePath(file)
273 opt[1] = "%s=%s" % (var, file)
274 opt = ':'.join(opt)
275 gopts[i] = opt
276 return gopts
277
278
279 security.declareProtected('View','performanceDeviceList')
281 """Return a list of urls that point to our managed devices"""
282 devlist = []
283 for dev in self.devices():
284 dev = dev.primaryAq()
285 if not dev.pastSnmpMaxFailures() and dev.monitorDevice():
286 devlist.append(dev.getPrimaryUrlPath(full=True))
287 return devlist
288
289
290 security.declareProtected('View','performanceDataSources')
292 """Return a string that has all the definitions for the performance ds's.
293 """
294 dses = []
295 oidtmpl = "OID %s %s"
296 dstmpl = """datasource %s
297 rrd-ds-type = %s
298 ds-source = snmp://%%snmp%%/%s%s
299 """
300 rrdconfig = self.getDmdRoot("Devices").rrdconfig
301 for ds in rrdconfig.objectValues(spec="RRDDataSource"):
302 if ds.isrow:
303 inst = ".%inst%"
304 else:
305 inst = ''
306 dses.append(oidtmpl % (ds.getName(), ds.oid))
307 dses.append(dstmpl %(ds.getName(), ds.rrdtype, ds.getName(), inst))
308 return "\n".join(dses)
309
311 remoteUrl = None
312 if self.renderurl.startswith("http"):
313 if datapoint:
314 remoteUrl = "%s/deleteRRDFiles?device=%s&datapoint=%s" % (self.renderurl,device,datapoint)
315 else:
316 remoteUrl = "%s/deleteRRDFiles?device=%s&datasource=%s" % (self.renderurl,device,datasource)
317 rs = self.getDmd().getParentNode().RenderServer
318 rs.deleteRRDFiles(device, datasource, datapoint, remoteUrl)
319
320 - def setPerformanceMonitor(self,
321 performanceMonitor=None,
322 deviceNames=None,
323 REQUEST=None):
324 """ Provide a method to set performance monitor from any organizer """
325 if not performanceMonitor:
326 if REQUEST: REQUEST['message'] = "No Monitor Selected"
327 return self.callZenScreen(REQUEST)
328 if deviceNames is None:
329 if REQUEST: REQUEST['message'] = "No Devices Selected"
330 return self.callZenScreen(REQUEST)
331 for devName in deviceNames:
332 dev = self.devices._getOb(devName)
333 dev = dev.primaryAq()
334 dev.setPerformanceMonitor(performanceMonitor)
335 if REQUEST:
336 REQUEST['message'] = "Performance monitor set to %s" % (
337 performanceMonitor)
338 if REQUEST.has_key('oneKeyValueSoInstanceIsntEmptyAndEvalToFalse'):
339 return REQUEST['message']
340 else:
341 return self.callZenScreen(REQUEST)
342
343 InitializeClass(PerformanceConf)
344
| Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0beta1 on Thu Oct 25 16:28:50 2007 | http://epydoc.sourceforge.net |