blob: 75462d4eb029b27fae4ceecacf7cdce97e3db7c6 [file] [log] [blame]
Scott Bakerf2c26de2014-06-10 20:37:40 -07001from bigquery_analytics import BigQueryAnalytics, BIGQUERY_AVAILABLE
Scott Baker050b1b82014-03-27 09:13:41 -07002import datetime
3import re
Scott Bakerc527fda2014-03-20 17:14:52 -07004import os
5import sys
Scott Baker95b28d62014-04-18 10:45:26 -07006import time
Scott Baker43adf1b2014-03-19 21:54:55 -07007import json
Scott Baker78ab1012014-03-19 23:44:39 -07008import traceback
Scott Baker050b1b82014-03-27 09:13:41 -07009import urllib2
Scott Baker43adf1b2014-03-19 21:54:55 -070010
Scott Bakerc527fda2014-03-20 17:14:52 -070011if os.path.exists("/home/smbaker/projects/vicci/plstackapi/planetstack"):
12 sys.path.append("/home/smbaker/projects/vicci/plstackapi/planetstack")
13else:
14 sys.path.append("/opt/planetstack")
15
16os.environ.setdefault("DJANGO_SETTINGS_MODULE", "planetstack.settings")
Scott Baker584b37a2014-04-24 17:02:28 -070017from django.conf import settings
Scott Bakerc527fda2014-03-20 17:14:52 -070018from django import db
19from django.db import connection
20from core.models import Slice, Sliver, ServiceClass, Reservation, Tag, Network, User, Node, Image, Deployment, Site, NetworkTemplate, NetworkSlice, Service
21
22BLUE_LOAD=5000000
23RED_LOAD=15000000
24
Scott Baker95b28d62014-04-18 10:45:26 -070025glo_cached_queries = {}
26
Scott Baker43adf1b2014-03-19 21:54:55 -070027class PlanetStackAnalytics(BigQueryAnalytics):
Scott Baker584b37a2014-04-24 17:02:28 -070028 def __init__(self, tableName=None):
29 if not tableName:
30 tableName = settings.BIGQUERY_TABLE
31
Scott Baker43adf1b2014-03-19 21:54:55 -070032 BigQueryAnalytics.__init__(self, tableName)
33
Scott Bakerc527fda2014-03-20 17:14:52 -070034 def service_to_sliceNames(self, serviceName):
35 service=Service.objects.get(name=serviceName)
36 try:
37 slices = service.slices.all()
38 except:
39 # BUG in data model -- Slice.service has related name 'service' and
40 # it should be 'slices'
41 slices = service.service.all()
42
43 return [slice.name for slice in slices]
44
Scott Baker0fd787d2014-05-13 17:03:47 -070045 def compose_query(self, filter={}, timeBucket="60", avg=[], sum=[], count=[], computed=[], val=[], groupBy=["Time"], orderBy=["Time"], tableName=None, latest=False, maxAge=60*60):
Scott Baker584b37a2014-04-24 17:02:28 -070046 if tableName is None:
47 tableName = self.tableName
48
Scott Bakercdd2c822014-04-23 20:07:08 -070049 maxAge = maxAge * 1000
50 tablePart = "[%s.%s@-%d--1]" % ("vicci", tableName, maxAge)
Scott Baker43adf1b2014-03-19 21:54:55 -070051
52 fields = []
53 fieldNames = []
Scott Baker95b28d62014-04-18 10:45:26 -070054 srcFieldNames = ["time"]
Scott Baker43adf1b2014-03-19 21:54:55 -070055
Scott Baker050b1b82014-03-27 09:13:41 -070056 fields.append("SEC_TO_TIMESTAMP(INTEGER(TIMESTAMP_TO_SEC(time)/%s)*%s) as Time" % (str(timeBucket),str(timeBucket)))
57 #fields.append("INTEGER(TIMESTAMP_TO_SEC(time)/%s)*%s as Time" % (str(timeBucket),str(timeBucket)))
Scott Baker43adf1b2014-03-19 21:54:55 -070058
59 for fieldName in avg:
60 fields.append("AVG(%s) as avg_%s" % (fieldName, fieldName.replace("%","")))
61 fieldNames.append("avg_%s" % fieldName.replace("%",""))
Scott Baker95b28d62014-04-18 10:45:26 -070062 srcFieldNames.append(fieldName)
Scott Baker43adf1b2014-03-19 21:54:55 -070063
64 for fieldName in sum:
65 fields.append("SUM(%s) as sum_%s" % (fieldName, fieldName.replace("%","")))
66 fieldNames.append("sum_%s" % fieldName.replace("%",""))
Scott Baker95b28d62014-04-18 10:45:26 -070067 srcFieldNames.append(fieldName)
Scott Baker43adf1b2014-03-19 21:54:55 -070068
69 for fieldName in count:
70 fields.append("COUNT(distinct %s) as count_%s" % (fieldName, fieldName.replace("%","")))
71 fieldNames.append("count_%s" % fieldName.replace("%",""))
Scott Baker95b28d62014-04-18 10:45:26 -070072 srcFieldNames.append(fieldName)
73
74 for fieldName in val:
75 fields.append(fieldName)
76 fieldNames.append(fieldName)
77 srcFieldNames.append(fieldName)
Scott Baker43adf1b2014-03-19 21:54:55 -070078
79 for fieldName in computed:
80 operator = "/"
81 parts = fieldName.split("/")
82 computedFieldName = "computed_" + parts[0].replace("%","")+"_div_"+parts[1].replace("%","")
83 if len(parts)==1:
84 operator = "*"
85 parts = computed.split("*")
86 computedFieldName = "computed_" + parts[0].replace("%","")+"_mult_"+parts[1].replace("%","")
87 fields.append("SUM(%s)%sSUM(%s) as %s" % (parts[0], operator, parts[1], computedFieldName))
88 fieldNames.append(computedFieldName)
Scott Baker95b28d62014-04-18 10:45:26 -070089 srcFieldNames.append(parts[0])
90 srcFieldNames.append(parts[1])
Scott Baker43adf1b2014-03-19 21:54:55 -070091
Scott Bakerc527fda2014-03-20 17:14:52 -070092 for fieldName in groupBy:
Scott Baker050b1b82014-03-27 09:13:41 -070093 if (fieldName not in ["Time"]):
Scott Bakerc527fda2014-03-20 17:14:52 -070094 fields.append(fieldName)
95 fieldNames.append(fieldName)
Scott Baker95b28d62014-04-18 10:45:26 -070096 srcFieldNames.append(fieldName)
Scott Bakerc527fda2014-03-20 17:14:52 -070097
Scott Baker43adf1b2014-03-19 21:54:55 -070098 fields = ", ".join(fields)
99
100 where = []
101
Scott Baker0fd787d2014-05-13 17:03:47 -0700102 if filter.get("slice",None):
103 where.append("%%slice='%s'" % filter["slice"])
104 if filter.get("site",None):
105 where.append("%%site='%s'" % filter["site"])
106 if filter.get("node",None):
107 where.append("%%hostname='%s'" % filter["node"])
108 if filter.get("event",None):
109 where.append("event='%s'" % filter["event"])
110 if filter.get("service",None):
111 sliceNames = self.service_to_sliceNames(filter["service"])
Scott Bakerc527fda2014-03-20 17:14:52 -0700112 if sliceNames:
113 where.append("(" + " OR ".join(["%%slice='%s'" % sliceName for sliceName in sliceNames]) +")")
Scott Baker43adf1b2014-03-19 21:54:55 -0700114
115 if where:
116 where = " WHERE " + " AND ".join(where)
117 else:
118 where =""
119
120 if groupBy:
Scott Bakerc527fda2014-03-20 17:14:52 -0700121 groupBySub = " GROUP BY " + ",".join(groupBy + ["%hostname"])
Scott Baker43adf1b2014-03-19 21:54:55 -0700122 groupBy = " GROUP BY " + ",".join(groupBy)
123 else:
Scott Bakerc527fda2014-03-20 17:14:52 -0700124 groupBySub = " GROUP BY %hostname"
Scott Baker43adf1b2014-03-19 21:54:55 -0700125 groupBy = ""
126
127 if orderBy:
128 orderBy = " ORDER BY " + ",".join(orderBy)
129 else:
130 orderBy = ""
131
Scott Baker95b28d62014-04-18 10:45:26 -0700132 if latest:
133 latestFields = ["table1.%s as %s" % (x,x) for x in srcFieldNames]
134 latestFields = ", ".join(latestFields)
135 tablePart = """(SELECT %s FROM %s AS table1
136 JOIN
137 (SELECT %%hostname, event, max(time) as maxtime from %s GROUP BY %%hostname, event) AS latest
138 ON
139 table1.%%hostname = latest.%%hostname AND table1.event = latest.event AND table1.time = latest.maxtime)""" % (latestFields, tablePart, tablePart)
140
Scott Baker43adf1b2014-03-19 21:54:55 -0700141 if computed:
Scott Baker95b28d62014-04-18 10:45:26 -0700142 subQuery = "SELECT %%hostname, %s FROM %s" % (fields, tablePart)
Scott Baker43adf1b2014-03-19 21:54:55 -0700143 if where:
144 subQuery = subQuery + where
Scott Bakerc527fda2014-03-20 17:14:52 -0700145 subQuery = subQuery + groupBySub
Scott Baker43adf1b2014-03-19 21:54:55 -0700146
147 sumFields = []
148 for fieldName in fieldNames:
149 if fieldName.startswith("avg"):
150 sumFields.append("AVG(%s) as avg_%s"%(fieldName,fieldName))
Scott Bakerc527fda2014-03-20 17:14:52 -0700151 sumFields.append("MAX(%s) as max_%s"%(fieldName,fieldName))
152 elif (fieldName.startswith("count")) or (fieldName.startswith("sum")) or (fieldName.startswith("computed")):
Scott Baker43adf1b2014-03-19 21:54:55 -0700153 sumFields.append("SUM(%s) as sum_%s"%(fieldName,fieldName))
Scott Bakerc527fda2014-03-20 17:14:52 -0700154 else:
155 sumFields.append(fieldName)
Scott Baker43adf1b2014-03-19 21:54:55 -0700156
157 sumFields = ",".join(sumFields)
158
Scott Baker050b1b82014-03-27 09:13:41 -0700159 query = "SELECT %s, %s FROM (%s)" % ("Time", sumFields, subQuery)
Scott Baker43adf1b2014-03-19 21:54:55 -0700160 if groupBy:
161 query = query + groupBy
162 if orderBy:
163 query = query + orderBy
164 else:
Scott Baker95b28d62014-04-18 10:45:26 -0700165 query = "SELECT %s FROM %s" % (fields, tablePart)
Scott Baker43adf1b2014-03-19 21:54:55 -0700166 if where:
167 query = query + " " + where
168 if groupBy:
169 query = query + groupBy
170 if orderBy:
171 query = query + orderBy
172
173 return query
174
175 def get_list_from_req(self, req, name, default=[]):
176 value = req.GET.get(name, None)
177 if not value:
178 return default
Scott Baker050b1b82014-03-27 09:13:41 -0700179 value=value.replace("@","%")
Scott Baker43adf1b2014-03-19 21:54:55 -0700180 return value.split(",")
181
Scott Baker050b1b82014-03-27 09:13:41 -0700182 def format_result(self, format, result, query, dataSourceUrl):
Scott Bakerf2c26de2014-06-10 20:37:40 -0700183 if not BIGQUERY_AVAILABLE:
184 msg = "BigQuery Statistics Unavaiable"
185 else:
186 msg = None
187
Scott Baker43adf1b2014-03-19 21:54:55 -0700188 if (format == "json_dicts"):
Scott Bakerf2c26de2014-06-10 20:37:40 -0700189 result = {"query": query, "rows": result, "dataSourceUrl": dataSourceUrl, "msg": msg}
Scott Baker43adf1b2014-03-19 21:54:55 -0700190 return ("application/javascript", json.dumps(result))
191
192 elif (format == "json_arrays"):
193 new_result = []
194 for row in result:
195 new_row = []
196 for key in sorted(row.keys()):
197 new_row.append(row[key])
198 new_result.append(new_row)
Scott Bakerf2c26de2014-06-10 20:37:40 -0700199 new_result = {"query": query, "rows": new_result, "msg": msg}
Scott Baker43adf1b2014-03-19 21:54:55 -0700200 return ("application/javascript", json.dumps(new_result))
201
202 elif (format == "html_table"):
203 new_rows = []
204 for row in result:
205 new_row = []
206 for key in sorted(row.keys()):
207 new_row.append("<TD>%s</TD>" % str(row[key]))
208 new_rows.append("<TR>%s</TR>" % "".join(new_row))
209
210 new_result = "<TABLE>%s</TABLE>" % "\n".join(new_rows)
211
212 return ("text/html", new_result)
213
Scott Bakera5885442014-04-21 01:28:48 -0700214 def merge_datamodel_sites(self, rows, slice=None):
Scott Bakerc527fda2014-03-20 17:14:52 -0700215 """ For a query that included "site" in its groupby, merge in the
216 opencloud site information.
217 """
Scott Bakera5885442014-04-21 01:28:48 -0700218
219 if slice:
220 try:
221 slice = Slice.objects.get(name=slice)
222 except:
223 slice = None
224
Scott Bakerc527fda2014-03-20 17:14:52 -0700225 for row in rows:
226 sitename = row["site"]
227 try:
228 model_site = Site.objects.get(name=sitename)
229 except:
230 # we didn't find it in the data model
231 continue
232
Scott Bakera5885442014-04-21 01:28:48 -0700233 allocated_slivers = 0
234 if model_site and slice:
235 for sliver in slice.slivers.all():
236 if sliver.node.site == model_site:
237 allocated_slivers = allocated_slivers + 1
238
Scott Bakerc527fda2014-03-20 17:14:52 -0700239 row["lat"] = float(model_site.location.latitude)
240 row["long"] = float(model_site.location.longitude)
241 row["url"] = model_site.site_url
242 row["numNodes"] = model_site.nodes.count()
Scott Bakera5885442014-04-21 01:28:48 -0700243 row["allocated_slivers"] = allocated_slivers
Scott Bakerc527fda2014-03-20 17:14:52 -0700244
Scott Baker95b28d62014-04-18 10:45:26 -0700245 max_cpu = row.get("max_avg_cpu", row.get("max_cpu",0))
246 cpu=float(max_cpu)/100.0
247 row["hotness"] = max(0.0, ((cpu*RED_LOAD) - BLUE_LOAD)/(RED_LOAD-BLUE_LOAD))
248
Scott Baker0fd787d2014-05-13 17:03:47 -0700249 def compose_cached_query(self, querySpec='default'):
Scott Baker95b28d62014-04-18 10:45:26 -0700250 """ Compose a query that returns the 'most recent' row for each (hostname, event)
251 pair.
Scott Baker0fd787d2014-05-13 17:03:47 -0700252
253 Note that groupByFields cannot contain any values that are 'Null' or those
254 rows will be excluded. For example, if groupByFields includes cp, then
255 there will be no libvirt_event rows, since libvirt_event does not have
256 cp.
257
258 This means we can't really have 'one query to rule them'. Settle on
259 having a couple of different queries, and have the caller specify
260 which one he wants.
Scott Baker95b28d62014-04-18 10:45:26 -0700261 """
262
Scott Baker0fd787d2014-05-13 17:03:47 -0700263 fieldNames = ["%hostname", "%bytes_sent", "%bytes_hit", "%healthy", "time", "event", "%site", "%elapsed", "%cpu"]
264
265 if querySpec=="default":
266 groupByFields = ["%hostname", "event"]
267 elif (querySpec=="hpc"):
268 fieldNames.append("%cp")
269 groupByFields = ["%hostname", "event", "%cp"]
270 else:
271 raise ValueError("Unknown queryspec %s" % querySpec)
Scott Baker95b28d62014-04-18 10:45:26 -0700272
273 fields = ["table1.%s AS %s" % (x,x) for x in fieldNames]
274 fields = ", ".join(fields)
275
276 tableDesc = "%s.%s" % (self.projectName, self.tableName)
277
278 groupByOn = ["table1.time = latest.maxtime"]
279 for field in groupByFields:
280 groupByOn.append("table1.%s = latest.%s" % (field, field))
281
282 groupByOn = " AND ".join(groupByOn)
283 groupByFields = ", ".join(groupByFields)
284
285 base_query = "SELECT %s FROM [%s@-3600000--1] AS table1 JOIN (SELECT %s, max(time) as maxtime from [%s@-3600000--1] GROUP BY %s) AS latest ON %s" % \
286 (fields, tableDesc, groupByFields, tableDesc, groupByFields, groupByOn)
287
288 return base_query
289
Scott Baker75095b62014-04-21 17:32:09 -0700290 def get_cached_query_results(self, q, wait=True):
Scott Baker95b28d62014-04-18 10:45:26 -0700291 global glo_cached_queries
292
293 if q in glo_cached_queries:
294 if (time.time() - glo_cached_queries[q]["time"]) <= 60:
295 print "using cached query"
296 return glo_cached_queries[q]["rows"]
297
Scott Baker75095b62014-04-21 17:32:09 -0700298 if not wait:
299 return None
300
Scott Baker95b28d62014-04-18 10:45:26 -0700301 print "refreshing cached query"
302 result = self.run_query(q)
303 glo_cached_queries[q] = {"time": time.time(), "rows": result}
304
305 return result
Scott Bakerc527fda2014-03-20 17:14:52 -0700306
Scott Baker43adf1b2014-03-19 21:54:55 -0700307 def process_request(self, req):
308 print req.GET
309
Scott Baker050b1b82014-03-27 09:13:41 -0700310 tqx = req.GET.get("tqx", None)
Scott Baker43adf1b2014-03-19 21:54:55 -0700311
312 slice = req.GET.get("slice", None)
313 site = req.GET.get("site", None)
314 node = req.GET.get("node", None)
Scott Bakerc527fda2014-03-20 17:14:52 -0700315 service = req.GET.get("service", None)
Scott Baker584b37a2014-04-24 17:02:28 -0700316 event = req.GET.get("event", "libvirt_heartbeat")
Scott Baker0fd787d2014-05-13 17:03:47 -0700317 cp = req.GET.get("cp", None)
Scott Baker43adf1b2014-03-19 21:54:55 -0700318
319 format = req.GET.get("format", "json_dicts")
320
Scott Bakercdd2c822014-04-23 20:07:08 -0700321 timeBucket = int(req.GET.get("timeBucket", 60))
Scott Baker43adf1b2014-03-19 21:54:55 -0700322 avg = self.get_list_from_req(req, "avg")
323 sum = self.get_list_from_req(req, "sum")
324 count = self.get_list_from_req(req, "count")
325 computed = self.get_list_from_req(req, "computed")
Scott Baker050b1b82014-03-27 09:13:41 -0700326 groupBy = self.get_list_from_req(req, "groupBy", ["Time"])
327 orderBy = self.get_list_from_req(req, "orderBy", ["Time"])
Scott Baker43adf1b2014-03-19 21:54:55 -0700328
329 maxRows = req.GET.get("maxRows", None)
Scott Bakerc527fda2014-03-20 17:14:52 -0700330 mergeDataModelSites = req.GET.get("mergeDataModelSites", None)
Scott Baker43adf1b2014-03-19 21:54:55 -0700331
Scott Bakercdd2c822014-04-23 20:07:08 -0700332 maxAge = int(req.GET.get("maxAge", 60*60))
333
Scott Baker95b28d62014-04-18 10:45:26 -0700334 cached = req.GET.get("cached", None)
Scott Baker4e025af2014-04-28 23:31:29 -0700335 cachedGroupBy = self.get_list_from_req(req, "cachedGroupBy", ["doesnotexist"])
Scott Baker95b28d62014-04-18 10:45:26 -0700336
Scott Baker0fd787d2014-05-13 17:03:47 -0700337 filter={}
338 if slice:
339 filter["slice"] = slice
340 if site:
341 filter["site"] = site
342 if node:
343 filter["hostname"] = node
344 if event:
345 filter["event"] = event
346 if cp:
347 filter["cp"] = cp
348
349 q = self.compose_query(filter, timeBucket, avg, sum, count, computed, [], groupBy, orderBy, maxAge=maxAge)
Scott Baker43adf1b2014-03-19 21:54:55 -0700350
351 print q
Scott Baker95b28d62014-04-18 10:45:26 -0700352
Scott Baker050b1b82014-03-27 09:13:41 -0700353 dataSourceUrl = "http://" + req.META["SERVER_NAME"] + ":" + req.META["SERVER_PORT"] + req.META["PATH_INFO"] + "?" + req.META["QUERY_STRING"].replace("format=","origFormat=").replace("%","%25") + "&format=charts";
Scott Baker43adf1b2014-03-19 21:54:55 -0700354
Scott Baker050b1b82014-03-27 09:13:41 -0700355 if (format=="dataSourceUrl"):
356 result = {"dataSourceUrl": dataSourceUrl}
357 return ("application/javascript", result)
358
359 elif (format=="raw"):
Scott Baker43adf1b2014-03-19 21:54:55 -0700360 result = self.run_query_raw(q)
Scott Baker050b1b82014-03-27 09:13:41 -0700361 result["dataSourceUrl"] = dataSourceUrl
362
363 result = json.dumps(result);
364
365 return ("application/javascript", result)
366
Scott Baker95b28d62014-04-18 10:45:26 -0700367 elif (format=="nodata"):
368 result = {"dataSourceUrl": dataSourceUrl, "query": q}
369 result = json.dumps(result);
370 return {"application/javascript", result}
371
Scott Baker050b1b82014-03-27 09:13:41 -0700372 elif (format=="charts"):
373 bq_result = self.run_query_raw(q)
374
375 # cloudscrutiny code is probably better!
376 table = {}
377 table["cols"] = self.schema_to_cols(bq_result["schema"])
378 rows = []
Scott Bakerf96a3f02014-04-21 00:27:56 -0700379 if "rows" in bq_result:
380 for row in bq_result["rows"]:
381 rowcols = []
382 for (colnum,col) in enumerate(row["f"]):
383 if (colnum==0):
384 dt = datetime.datetime.fromtimestamp(float(col["v"]))
385 rowcols.append({"v": 'new Date("%s")' % dt.isoformat()})
386 else:
387 try:
388 rowcols.append({"v": float(col["v"])})
389 except:
390 rowcols.append({"v": col["v"]})
391 rows.append({"c": rowcols})
Scott Baker050b1b82014-03-27 09:13:41 -0700392 table["rows"] = rows
393
394 if tqx:
395 reqId = tqx.strip("reqId:")
396 else:
397 reqId = "0"
398
399 result = {"status": "okColumnChart", "reqId": reqId, "table": table, "version": "0.6"}
400
401 result = "google.visualization.Query.setResponse(" + json.dumps(result) + ");"
402
403 def unquote_it(x): return x.group()[1:-1].replace('\\"', '"')
404
405 p = re.compile(r'"new Date\(\\"[^"]*\\"\)"')
406 result=p.sub(unquote_it, result)
407
408 return ("application/javascript", result)
409
Scott Baker43adf1b2014-03-19 21:54:55 -0700410 else:
Scott Baker95b28d62014-04-18 10:45:26 -0700411 if cached:
Scott Baker0fd787d2014-05-13 17:03:47 -0700412 results = self.get_cached_query_results(self.compose_cached_query(cached))
Scott Bakerc527fda2014-03-20 17:14:52 -0700413
Scott Baker4e025af2014-04-28 23:31:29 -0700414 result = self.postprocess_results(results, filter=filter, sum=sum, count=count, avg=avg, computed=computed, maxDeltaTime=120, groupBy=cachedGroupBy)
Scott Baker95b28d62014-04-18 10:45:26 -0700415 else:
416 result = self.run_query(q)
Scott Bakerc527fda2014-03-20 17:14:52 -0700417
Scott Baker43adf1b2014-03-19 21:54:55 -0700418 if maxRows:
419 result = result[-int(maxRows):]
420
Scott Baker95b28d62014-04-18 10:45:26 -0700421 if mergeDataModelSites:
422 self.merge_datamodel_sites(result)
Scott Baker43adf1b2014-03-19 21:54:55 -0700423
Scott Baker95b28d62014-04-18 10:45:26 -0700424 return self.format_result(format, result, q, dataSourceUrl)
Scott Baker43adf1b2014-03-19 21:54:55 -0700425
426def DoPlanetStackAnalytics(request):
427 bq = PlanetStackAnalytics()
428 result = bq.process_request(request)
429
430 return result
431
432def main():
Scott Baker584b37a2014-04-24 17:02:28 -0700433 bq = PlanetStackAnalytics(tableName="demoevents")
Scott Baker43adf1b2014-03-19 21:54:55 -0700434
Scott Baker0fd787d2014-05-13 17:03:47 -0700435 q = bq.compose_cached_query()
Scott Baker95b28d62014-04-18 10:45:26 -0700436 results = bq.run_query(q)
437
Scott Baker75095b62014-04-21 17:32:09 -0700438 #results = bq.postprocess_results(results,
439 # filter={"slice": "HyperCache"},
440 # groupBy=["site"],
441 # computed=["bytes_sent/elapsed"],
442 # sum=["bytes_sent", "computed_bytes_sent_div_elapsed"], avg=["cpu"],
443 # maxDeltaTime=60)
444
Scott Baker0fd787d2014-05-13 17:03:47 -0700445 #results = bq.postprocess_results(results, filter={"slice": "HyperCache"}, maxi=["cpu"], count=["hostname"], computed=["bytes_sent/elapsed"], groupBy=["Time", "site"], maxDeltaTime=80)
446
447 results = bq.postprocess_results(results,filter={"event": "libvirt_heartbeat"}, avg=["cpu"], count=["hostname"], groupBy=["doesnotexist"])
Scott Baker95b28d62014-04-18 10:45:26 -0700448
449 bq.dump_table(results)
450
Scott Baker75095b62014-04-21 17:32:09 -0700451 sys.exit(0)
452
Scott Baker95b28d62014-04-18 10:45:26 -0700453 q=bq.compose_query(sum=["%bytes_sent"], avg=["%cpu"], latest=True, groupBy=["Time", "%site"])
454 print q
455 bq.dump_table(bq.run_query(q))
456
Scott Baker050b1b82014-03-27 09:13:41 -0700457 q=bq.compose_query(avg=["%cpu","%bandwidth"], count=["%hostname"], slice="HyperCache")
Scott Baker43adf1b2014-03-19 21:54:55 -0700458 print q
459 bq.dump_table(bq.run_query(q))
460
461 q=bq.compose_query(computed=["%bytes_sent/%elapsed"])
462 print
463 print q
464 bq.dump_table(bq.run_query(q))
Scott Baker43adf1b2014-03-19 21:54:55 -0700465
Scott Baker050b1b82014-03-27 09:13:41 -0700466 q=bq.compose_query(timeBucket=60*60, avg=["%cpu"], count=["%hostname"], computed=["%bytes_sent/%elapsed"])
Scott Baker43adf1b2014-03-19 21:54:55 -0700467 print
468 print q
469 bq.dump_table(bq.run_query(q))
Scott Bakerc527fda2014-03-20 17:14:52 -0700470
Scott Baker43adf1b2014-03-19 21:54:55 -0700471if __name__ == "__main__":
472 main()
473
474
475
476
477