def info(ses, fn, t, prt, kind): class Opt: def __init__(self, t): self.after = t self.before = float('inf') self.overview = 'none' # xxx assumes this exists time_metric = util.join('serverStatus', 'localTime') # find and print the first sample after t (only) for metrics in read(ses, fn, Opt(t), progress=False): if kind=='raw': for sample, sample_time in enumerate(metrics[time_metric]): sample_time = sample_time / 1000.0 if sample_time >= t: break prt('%s at t=%.3f (%s)' % (fn, t, util.f2s(t))) util.print_sample(metrics, sample, prt) break elif kind=='metadata': prt('metadata at t=%.3f (%s)' % (t, util.f2s(t))) if metrics.metadata: util.print_bson_doc(metrics.metadata, prt, ' ') else: prt(' NOT AVAILABLE') break
def info(ses, fn, t, prt, kind): class Opt: def __init__(self, t): self.after = t self.before = float('inf') self.overview = 'none' # xxx assumes this exists time_metric = util.join('serverStatus', 'localTime') # find and print the first sample after t (only) for metrics in read(ses, fn, Opt(t), progress=False): if kind == 'raw': for sample, sample_time in enumerate(metrics[time_metric]): sample_time = sample_time / 1000.0 if sample_time >= t: break prt('%s at t=%.3f (%s)' % (fn, t, util.f2s(t))) util.print_sample(metrics, sample, prt) break elif kind == 'metadata': prt('metadata at t=%.3f (%s)' % (t, util.f2s(t))) if metrics.metadata: util.print_bson_doc(metrics.metadata, prt, ' ') else: prt(' NOT AVAILABLE') break
def info(cls, ses, fn, t, kind): if kind != 'raw': return def putln(*s): ses.put(' '.join(str(ss) for ss in s) + '\n') file = cls.get(fn) for chunk in file.chunks: if t >= chunk[file.time_key][0]: for sample, sample_time in enumerate(chunk[file.time_key]): if sample_time >= t: putln('%s at t=%.3f (%s)' % (fn, t, util.f2s(t))) util.print_sample(chunk, sample, putln) return
def info(ses, t): _head(ses) ses.put('data as displayed at %s<br/><br/>\n' % util.f2s(t)) ses.elt('table') for s in ses.series: for name, value in s.info(ses, t): ses.elt('tr') ses.td('info-data', '{:,.3f}'.format(value)) ses.td('desc', name) ses.end('tr') ses.end('table')
def data_point_after_splits(self, t, d, get_field, set_field): # may not have data in case of a count, so just use 0 try: d = float(d) except: d = 0 # wrapping 32-bit counter hack if self.wrap: if self.last_d > self.wrap / 2 and d < -self.wrap / 2: self.wrap_offset += 2 * self.wrap util.dbg('wrap', d, self.last_d, self.wrap_offset) elif self.last_d < -self.wrap / 2 and d > self.wrap / 2: self.wrap_offset -= 2 * self.wrap util.dbg('wrap', d, self.last_d, self.wrap_offset) self.last_d = d d += self.wrap_offset # compute a rate if self.rate: if self.last_t == t: return if self.last_t: dd = d - self.last_d if self.rate != 'delta': dd /= t - self.last_t self.last_t = t self.last_d = d d = dd else: self.last_t = t self.last_d = d return if d < 0: self.wrapped = True if not self.rate: util.msg('possible wrap detected in', self.get('name'), 'at', util.f2s(t)) # scale - xxx need general computation mechanism here instead if self.scale_field: scale_field = self.scale_field.format(**self.descriptor) try: div = float(get_field(scale_field)) except: return if div: d /= div d /= self.scale # record the data if self.buckets: s0 = t s1 = s0 // self.buckets * self.buckets t = s1 self.ys[t] = self.op(self.ys, t, d) elif self.queue: if d > self.queue_min_ms: ms = datetime.timedelta(0, d / 1000.0) self.queue_times.append((t - ms, +1)) self.queue_times.append((t, -1)) else: self.ys[t] = d # make data available for computation if self.set_field and set_field: set_field(self.set_field, d) # tell our caller what we recorded return d
def data_point_after_splits(self, t, d, get_field, set_field): # may not have data in case of a count, so just use 0 try: d = float(d) except: d = 0 # wrapping 32-bit counter hack if self.wrap: if self.last_d > self.wrap/2 and d < -self.wrap/2: self.wrap_offset += 2 * self.wrap util.dbg('wrap', d, self.last_d, self.wrap_offset) elif self.last_d < -self.wrap/2 and d > self.wrap/2: self.wrap_offset -= 2 * self.wrap util.dbg('wrap', d, self.last_d, self.wrap_offset) self.last_d = d d += self.wrap_offset # compute a rate if self.rate: if self.last_t==t: return if self.last_t: dd = d - self.last_d if self.rate != 'delta': dd /= t - self.last_t self.last_t = t self.last_d = d d = dd else: self.last_t = t self.last_d = d return if d < 0: self.wrapped = True if not self.rate: util.msg('possible wrap detected in', self.get('name'), 'at', util.f2s(t)) # scale - xxx need general computation mechanism here instead if self.scale_field: scale_field = self.scale_field.format(**self.descriptor) try: div = float(get_field(scale_field)) except: return if div: d /= div d /= self.scale # record the data if self.buckets: s0 = t s1 = s0 // self.buckets * self.buckets t = s1 self.ys[t] = self.op(self.ys, t, d) elif self.queue: if d>self.queue_min_ms: ms = datetime.timedelta(0, d/1000.0) self.queue_times.append((t-ms,+1)) self.queue_times.append((t,-1)) else: self.ys[t] = d # make data available for computation if self.set_field and set_field: set_field(self.set_field, d) # tell our caller what we recorded return d