Revision 2439c9d6 snf-stats-app/synnefo_stats/grapher.py

b/snf-stats-app/synnefo_stats/grapher.py
35 35

  
36 36
import gd
37 37
import os
38
import sys
39
import subprocess
40 38

  
41
from cgi import escape
42 39
from cStringIO import StringIO
43 40

  
44 41
import rrdtool
......
72 69

  
73 70
    try:
74 71
        values = rrdtool.fetch(fname, "AVERAGE")[2][-20:]
75
    except rrdtool.error, e:
72
    except rrdtool.error:
76 73
        values = [(0.0, )]
77 74

  
78 75
    v = [x[0] for x in values if x[0] is not None]
......
119 116

  
120 117
    try:
121 118
        values = rrdtool.fetch(fname, "AVERAGE")[2][-20:]
122
    except rrdtool.error, e:
119
    except rrdtool.error:
123 120
        values = [(0.0, 0.0)]
124 121

  
125 122
    v = [x for x in values if x[0] is not None and x[1] is not None]
......
175 172
                  #"-t", "CPU usage",
176 173
                  "-v", "%",
177 174
                  #"--lazy",
178
                  "DEF:cpu=%s:ns:AVERAGE" % fname,
175
                  "DEF:cpu=%s:value:AVERAGE" % fname,
179 176
                  "LINE1:cpu#00ff00:")
180 177

  
181 178
    return read_file(outfname)
......
189 186
                  #"-t", "CPU usage",
190 187
                  "-v", "%",
191 188
                  #"--lazy",
192
                  "DEF:cpu=%s:ns:AVERAGE" % fname,
189
                  "DEF:cpu=%s:value:AVERAGE" % fname,
193 190
                  "LINE1:cpu#00ff00:")
194 191

  
195 192
    return read_file(outfname)
......
200 197
    outfname += "-net.png"
201 198

  
202 199
    rrdtool.graph(outfname, "-s", "-1d", "-e", "-20s",
203
              "--units", "si",
204
              "-v", "Bits/s",
205
              "COMMENT:\t\t\tAverage network traffic\\n",
206
              "DEF:rx=%s:rx:AVERAGE" % fname,
207
              "DEF:tx=%s:tx:AVERAGE" % fname,
208
              "CDEF:rxbits=rx,8,*",
209
              "CDEF:txbits=tx,8,*",
210
              "LINE1:rxbits#00ff00:Incoming",
211
              "GPRINT:rxbits:AVERAGE:\t%4.0lf%sbps\t\g",
212
              "LINE1:txbits#0000ff:Outgoing",
213
              "GPRINT:txbits:AVERAGE:\t%4.0lf%sbps\\n")
200
                  "--units", "si",
201
                  "-v", "Bits/s",
202
                  "COMMENT:\t\t\tAverage network traffic\\n",
203
                  "DEF:rx=%s:rx:AVERAGE" % fname,
204
                  "DEF:tx=%s:tx:AVERAGE" % fname,
205
                  "CDEF:rxbits=rx,8,*",
206
                  "CDEF:txbits=tx,8,*",
207
                  "LINE1:rxbits#00ff00:Incoming",
208
                  "GPRINT:rxbits:AVERAGE:\t%4.0lf%sbps\t\g",
209
                  "LINE1:txbits#0000ff:Outgoing",
210
                  "GPRINT:txbits:AVERAGE:\t%4.0lf%sbps\\n")
214 211

  
215 212
    return read_file(outfname)
216 213

  
......
220 217
    outfname += "-net-weekly.png"
221 218

  
222 219
    rrdtool.graph(outfname, "-s", "-1w", "-e", "-20s",
223
              "--units", "si",
224
              "-v", "Bits/s",
225
              "COMMENT:\t\t\tAverage network traffic\\n",
226
              "DEF:rx=%s:rx:AVERAGE" % fname,
227
              "DEF:tx=%s:tx:AVERAGE" % fname,
228
              "CDEF:rxbits=rx,8,*",
229
              "CDEF:txbits=tx,8,*",
230
              "LINE1:rxbits#00ff00:Incoming",
231
              "GPRINT:rxbits:AVERAGE:\t%4.0lf%sbps\t\g",
232
              "LINE1:txbits#0000ff:Outgoing",
233
              "GPRINT:txbits:AVERAGE:\t%4.0lf%sbps\\n")
220
                  "--units", "si",
221
                  "-v", "Bits/s",
222
                  "COMMENT:\t\t\tAverage network traffic\\n",
223
                  "DEF:rx=%s:rx:AVERAGE" % fname,
224
                  "DEF:tx=%s:tx:AVERAGE" % fname,
225
                  "CDEF:rxbits=rx,8,*",
226
                  "CDEF:txbits=tx,8,*",
227
                  "LINE1:rxbits#00ff00:Incoming",
228
                  "GPRINT:rxbits:AVERAGE:\t%4.0lf%sbps\t\g",
229
                  "LINE1:txbits#0000ff:Outgoing",
230
                  "GPRINT:txbits:AVERAGE:\t%4.0lf%sbps\\n")
234 231

  
235 232
    return read_file(outfname)
236 233

  
......
243 240
    return aes.decrypt(urlsafe_b64decode(secret)).rstrip('\x00')
244 241

  
245 242

  
246
available_graph_types = {
247
        'cpu-bar': draw_cpu_bar,
248
        'net-bar': draw_net_bar,
249
        'cpu-ts': draw_cpu_ts,
250
        'net-ts': draw_net_ts,
251
        'cpu-ts-w': draw_cpu_ts_w,
252
        'net-ts-w': draw_net_ts_w,
253
        }
243
available_graph_types = {'cpu-bar': draw_cpu_bar,
244
                         'net-bar': draw_net_bar,
245
                         'cpu-ts': draw_cpu_ts,
246
                         'net-ts': draw_net_ts,
247
                         'cpu-ts-w': draw_cpu_ts_w,
248
                         'net-ts-w': draw_net_ts_w
249
                         }
254 250

  
255 251

  
256 252
@api_method(http_method='GET', token_required=False, user_required=False,

Also available in: Unified diff