Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 181 lines (145 sloc) 6.128 kB
ff20af9 @alobbs Adds the new admin
alobbs authored
1 # -*- coding: utf-8 -*-
2 #
3 # Cherokee-admin
4 #
5 # Authors:
6 # Alvaro Lopez Ortega <alvaro@alobbs.com>
7 # Taher Shihadeh <taher@unixwars.com>
8 #
9 # Copyright (C) 2001-2010 Alvaro Lopez Ortega
10 #
11 # This program is free software; you can redistribute it and/or
12 # modify it under the terms of version 2 of the GNU General Public
13 # License as published by the Free Software Foundation.
14 #
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 # 02110-1301, USA.
24 #
25
26 import CTK
27 import Cherokee
28 import validations
29
30 from consts import *
31 from configured import *
32
33
34 URL_APPLY = '/graph/apply'
35
36 GRAPH_VSERVER = '/graphs/%(prefix)s_%(type)s_%(vserver)s_%(interval)s.png'
37 GRAPH_SERVER = '/graphs/%(prefix)s_%(type)s_%(interval)s.png'
38
39 GRAPH_TYPES = [('traffic', N_('Server Traffic')),
40 ('accepts', N_('Connections / Requests')),
41 ('timeouts', N_('Connection Timeouts')),]
42
43 GRAPH_INTERVALS = [('1h', N_('1 Hour')),
44 ('6h', N_('6 Hours')),
45 ('1d', N_('1 Day')),
46 ('1w', N_('1 Week')),
47 ('1m', N_('1 Month'))]
48
49 URL_RRD = '/general#Network-1'
71e2082 Gettext was having trouble with some rough edges
taher authored
50 RRD_NOTICE = N_('You need to enable the <a href="%s">Information Collector</a> setting in order to render usage graphics.')
ff20af9 @alobbs Adds the new admin
alobbs authored
51 NOTE_COLLECTOR = N_('Whether or not it should collect statistics about the traffic of this virtual server.')
52
53 UPDATE_JS = """
54 function updateGraph() {
55 var timeout = $(window).data('graph-timeout');
56
57 if ((timeout != null) &&
58 (timeout != undefined))
59 {
60 clearTimeout (timeout);
61 $(window).data('graph-timeout', null);
62 }
63
64 %s
65 }
66
67 var tmp = setTimeout (updateGraph, 60000);
68 $(window).data('graph-timeout', tmp);
69 """ #%(JS_to_refresh)
70
71 def apply ():
72 graph_type = CTK.post.get_val('graph_type')
73 if graph_type:
74 CTK.cfg['tmp!graph_type'] = graph_type
75 return CTK.cfg_reply_ajax_ok()
76
77 # Modifications
78 return CTK.cfg_apply_post()
79
80
81 class Graph (CTK.Box):
82 def __init__ (self, refreshable, **kwargs):
83 CTK.Box.__init__ (self)
84 self.graph = {}
85 self.graph['type'], self.graph['type_txt'] = GRAPH_TYPES[0]
86 self.refresh = refreshable
87
88 def build_graph (self):
89 if CTK.cfg.get_val('server!collector') != 'rrd':
90 notice = CTK.Notice()
71e2082 Gettext was having trouble with some rough edges
taher authored
91 notice += CTK.RawHTML(_(RRD_NOTICE)%(URL_RRD))
ff20af9 @alobbs Adds the new admin
alobbs authored
92 self += CTK.Indenter(notice)
93 return False
94
95 tabs = CTK.Tab ()
96 for x in GRAPH_INTERVALS:
97 self.graph['interval'] = x[0]
98 props = {'src': self.template % self.graph,
99 'alt': '%s: %s' %(self.graph['type_txt'], x[1])}
100 image = CTK.Image(props)
101 tabs.Add (_(x[1]), image)
102 self += tabs
103 return True
104
105 def Render (self):
106 render = CTK.Box.Render (self)
107 render.js += UPDATE_JS % (self.refresh.JS_to_refresh())
108 return render
109
110
111 class GraphVServer_Instancer (CTK.Container):
112 class GraphVServer (Graph):
113 def __init__ (self, refreshable, vsrv_num, **kwargs):
114 Graph.__init__ (self, refreshable, **kwargs)
115 self.template = GRAPH_VSERVER
116 self.graph['prefix'] = 'vserver'
117 self.graph['vserver'] = CTK.cfg.get_val ("vserver!%s!nick" %(vsrv_num), _("Unknown"))
118 self.graph['num'] = vsrv_num
119 self.collector = bool(int(CTK.cfg.get_val ('vserver!%s!collector!enabled'%(vsrv_num),'0')))
120 self.build()
121
122 def build (self):
123 table = CTK.PropsTable()
124 table.Add (_('Collect Statistics'), CTK.CheckCfgText('vserver!%s!collector!enabled'%(self.graph['num']), self.collector), _(NOTE_COLLECTOR))
125
126 submit = CTK.Submitter (URL_APPLY)
127 submit += table
128 submit.bind('submit_success', self.refresh.JS_to_refresh())
129
130 if self.collector:
131 self.build_graph ()
132 props = {'class': 'graph_props_bottom'}
133 else:
134 props = {'class': 'graph_props_top'}
135
136 if CTK.cfg.get_val('server!collector') == 'rrd':
137 self += CTK.Indenter (CTK.Box(props, submit))
138
139 def __init__ (self, vserver):
140 CTK.Container.__init__ (self)
141
142 # Refresher
143 refresh = CTK.Refreshable ({'id': 'grapharea'})
144 refresh.register (lambda: self.GraphVServer(refresh, vserver).Render())
145 self += refresh
146
147
148 class GraphServer_Instancer (CTK.Container):
149 class GraphServer (Graph):
150 def __init__ (self, refreshable, **kwargs):
151 Graph.__init__ (self, refreshable, **kwargs)
152 self.template = GRAPH_SERVER
153 self.graph['prefix'] = 'server'
154 self.graph['type'] = CTK.cfg.get_val('tmp!graph_type', self.graph['type'])
155 self.build()
156
157 def build (self):
158 rrd = self.build_graph ()
159 if rrd:
160 props = {'class': 'graph_type', 'name': 'graph_type', 'selected': self.graph['type']}
161 combo = CTK.Combobox (props, GRAPH_TYPES)
162 submit = CTK.Submitter (URL_APPLY)
163 submit += combo
164 submit.bind('submit_success', self.refresh.JS_to_refresh())
165
166 for x in GRAPH_TYPES:
167 if x[0] == self.graph['type']:
168 self.graph['type_txt'] = x[1]
169
170 self += submit
171
172 def __init__ (self):
173 CTK.Container.__init__ (self)
174
175 # Refresher
176 refresh = CTK.Refreshable ({'id': 'grapharea'})
177 refresh.register (lambda: self.GraphServer(refresh).Render())
178 self += refresh
179
180 CTK.publish ('^%s'%(URL_APPLY), apply, method="POST")
Something went wrong with that request. Please try again.