def get_series_data(self, listdata): ymax = 0 data_list = [] for ls in listdata: dt = ls[1] millis = convert_to_CMS_TZ(dt) if ls[0] > ymax: ymax = ls[0] data_list.append(dict(metric=ls[0], millis=millis)) if ymax > 100: ymax = ymax + 10 else: if 100 - ymax <= 10: ymax = 100 else: ymax = ymax + 2 return (data_list, ymax)
def metrics(self, auth): node_id = '53c7a8bb-fc80-947d-f6c5-ab8f33d1be15' node_id = '04e059c6-264d-b1af-77dd-f0a62ae00c34' day1 = datetime.now() day2 = datetime.now() + timedelta(hours=-8) print day1, print '--------', print day2 result = self.service.getRawData(node_id, SERVER_RAW, day2, day1) data_list = [] for ls in result: print ls[0], print '--', print ls[1], print '--', print ls[len(ls) - 1] dt = ls[len(ls) - 1] millis = convert_to_CMS_TZ(dt) print millis data_list.append(dict(cpu=ls[0], mem=ls[1], millis=millis)) return data_list
def get_chart_data(self, auth, node_id, node_type, metric, period, offset, frm, to, chart_type=None, avg_fdate=None, avg_tdate=None): self.utcoffset = timedelta(milliseconds=long(offset)) print self.utcoffset, print datetime.now() per_type = 'ROLLUP' rollup_type = constants.HOURLY time_format = '%H:%M' (xlabel, ylabel, label) = ('', '', '') minTick = 'day' date2 = datetime.now() date1 = datetime.now() + timedelta(days=-1) if period == constants.CUSTOM: per_type = 'ROLLUP' date2 = constants.defaultDate + timedelta(milliseconds=long(to)) date1 = constants.defaultDate + timedelta(milliseconds=long(frm)) td = date2 - date1 if td.days > 3: rollup_type = constants.DAILY minTick = [1, 'day'] xlabel = 'Time(days)' time_format = '%b/%d' else: if self.timedelta_seconds(td) < 43200: per_type = 'RAW' rollup_type = constants.HOURLY minTick = [30, 'minute'] xlabel = 'Time(minutes)' time_format = '%H:%M' else: rollup_type = constants.HOURLY minTick = [2, 'hour'] xlabel = 'Time(hours)' time_format = '%H:%M' else: per_type = 'ROLLUP' if period == constants.HRS24: rollup_type = constants.HOURLY minTick = [2, 'hour'] xlabel = 'Time(hours)' time_format = '%H:%M' date1 = date2 + timedelta(days=-1) else: if period == constants.HRS12: per_type = 'RAW' rollup_type = constants.HOURLY minTick = [30, 'minute'] xlabel = 'Time(minutes)' time_format = '%H:%M' date1 = date2 + timedelta(seconds=-43200) else: if period == constants.DAYS7: rollup_type = constants.DAILY minTick = [1, 'day'] xlabel = 'Time(days)' time_format = '%b/%d' date1 = date2 + timedelta(weeks=-1) else: if period == constants.DAYS30: rollup_type = constants.DAILY minTick = [2, 'day'] xlabel = 'Time(days)' time_format = '%b/%d' date1 = date2 + timedelta(days=-31) else: if period == constants.DTD: date2 = constants.defaultDate + timedelta(milliseconds=long(to)) date2 = date2 + self.utcoffset date1 = datetime(date2.year, date2.month, date2.day) - self.utcoffset date2 = date2 - self.utcoffset rollup_type = constants.HOURLY minTick = [2, 'hour'] xlabel = 'Time(hours)' time_format = '%H:%M' else: if period == constants.WTD: rollup_type = constants.DAILY minTick = [1, 'day'] xlabel = 'Time(days)' time_format = '%b/%d' weekdays = date2.date().weekday() date1 = datetime(date2.year, date2.month, date2.day) + timedelta(days=-weekdays) - self.utcoffset diff = (date2 - date1).days if diff < 3: minTick = [4, 'hour'] time_format = '%b/%d:%H' xlabel = 'Time(hours)' if diff < 1: minTick = [1, 'hour'] time_format = '%b/%d:%H' xlabel = 'Time(hours)' else: if period == constants.MTD: rollup_type = constants.DAILY minTick = [1, 'day'] xlabel = 'Time(days)' time_format = '%b/%d' date1 = datetime(date2.year, date2.month, date2.day) + timedelta(days=-(date2.day - 1)) - self.utcoffset diff = (date2 - date1).days if diff > 8: minTick = [2, 'day'] xlabel = 'Time(days)' hr1 = to_str(date1.hour) hr2 = to_str(date2.hour) minute1 = to_str(date1.minute) minute2 = to_str(date2.minute) if date1.hour < 10: hr1 = '0' + hr1 if date2.hour < 10: hr2 = '0' + hr2 dt_str = to_str(date1.year) + '/' + to_str(date1.month) + '/' + to_str(date1.day) + ' ' + hr1 + ':' + minute1 + ' - ' + to_str(date2.year) + '/' + to_str(date2.month) + '/' + to_str(date2.day) + ' ' + hr2 + ':' + minute2 if metric == constants.METRIC_CPU: ylabel = 'cpu(%)' else: if metric == constants.METRIC_MEM: ylabel = 'memory(%)' else: if metric == constants.METRIC_VMCPU: ylabel = 'vm cpu(%)' else: if metric == constants.METRIC_NETWORKIN: ylabel = 'NetworkIn(max)' else: if metric == constants.METRIC_NETWORKOUT: ylabel = 'NetworkOut(max)' else: if metric == constants.METRIC_DISKREAD: ylabel = 'DiskReadBytes(max)' else: if metric == constants.METRIC_DISKWRITE: ylabel = 'DiskWriteBytes(max)' label = dt_str series = [] ymax = 1 avg = 0.0 show_avg = False if chart_type == constants.TOP5SERVERS: metric_type = self.get_metric_type(node_type, per_type) series,ymax = self.topNServers(auth, node_id, node_type, metric, metric_type, rollup_type, per_type, date1, date2, period) else: if chart_type == constants.TOP5VMS: metric_type = self.get_metric_type(node_type, per_type) series,ymax = self.topNVMS(auth, node_id, node_type, metric, metric_type, rollup_type, per_type, date1, date2, period) else: if chart_type == constants.COMPARISONCHART: series,ymax = self.comparison_chart(auth, node_id, node_type, metric, -1, rollup_type, per_type, date1, date2, period) else: metric_type = self.get_metric_type(node_type, per_type) series,ymax,avg,show_avg = self.chart_series_data(node_id, node_type, metric, metric_type, rollup_type, per_type, date1, date2, avg_fdate, avg_tdate, period) if len(series) == 0: series.append(dict(data=[], label='')) min = convert_to_CMS_TZ(date1) max = convert_to_CMS_TZ(date2) return dict(time_format=time_format, label=label, xlabel=xlabel, ylabel=ylabel, show_avg=show_avg, avg=avg, min=min, max=max, ymax=ymax, minTick=minTick, series=series)