def finish(self, data): self.correlator.setup(data) ts = time.time() metadata = dict(tsdb_flags=ROW_VALID) for oid in self.oidset.oids.all(): correlated_data = [] # qualified names are returned unqualified if "::" in oid.name: oid.name = oid.name.split("::")[-1] for var, val in filter_data(oid.name, data): try: varname = self.correlator.lookup(oid, var) except PollUnknownIfIndex: self.log.error("unknown ifIndex: %s %s" % (var, str(val))) continue if varname: correlated_data.append((varname, val)) else: if val != 0: pass #self.log.warning("ignoring: %s %s" % (var, str(val))) dataout = self.translator.translate(correlated_data) pr = PollResult(self.oidset.name, self.device.name, oid.name, ts, dataout, metadata) self.save(pr) self.log.debug( "grabbed %d saved %d vars in %f seconds" % (len(data), len(dataout), time.time() - self.begin_time))
def finish(self, data): dataout = {} for oid in self.oidset.oids.all(): dataout[oid.name] = filter_data(oid.name, data) if self.translator: dataout[oid.name] = self.translator.translate(dataout[oid.name]) pr = PollResult(self.oidset.name, self.device.name, "", time.time(), dataout, {}) self.save(pr) self.log.debug("grabbed %d vars in %f seconds" % (len(data), time.time() - self.begin_time))
def main(): usage = '%prog [ -r NUM | -i NUM | -o NUM | -l NUM | -v ]' usage += '\n\tAmount of data generated ~= r * i * (o * 2) * l' parser = OptionParser(usage=usage) parser.add_option('-r', '--routers', metavar='NUM_ROUTERS', type='int', dest='routers', default=1, help='Number of test "routers" to generate (default=%default).') parser.add_option('-i', '--interfaces', metavar='NUM_INTERFACES', type='int', dest='interfaces', default=2, help='Number of test interfaces to generate on each test router (default=%default).') parser.add_option('-o', '--oidsets', metavar='NUM_OIDSETS', type='int', dest='oidsets', default=2, help='Number of oidsets to assign to each fake device/router (default=%default).') parser.add_option('-l', '--loop', metavar='NUM_LOOPS', type='int', dest='loop', default=1, help='Number of times to send data for each "device (default=%default)."') parser.add_option('-p', '--prefix', metavar='PREFIX', type='string', dest='prefix', default='fake', help='Device name prefix - make new names (default=%default).') parser.add_option('-W', '--write', dest='write', action='store_true', default=False, help='Actually write the data to the memcache queue.') parser.add_option('-v', '--verbose', dest='verbose', action='count', default=False, help='Verbose output - -v, -vv, etc.') options, args = parser.parse_args() router_names = [] for i in range(1,5): for c in string.lowercase: router_names.append(c*i) if options.routers > 26*4: print 'There is an upper bound of {0} fake routers.'.format(26*4) return -1 config = get_config(get_config_path()) qs = TestQueues(config, options.write, options.verbose) oidset_oid = {} oid_count = 0 for oidset in OIDSet.objects.filter(frequency=30)[0:options.oidsets]: if not oidset_oid.has_key(oidset.name): oidset_oid[oidset.name] = [] for oid in oidset.oids.exclude(name='sysUpTime'): oidset_oid[oidset.name].append(oid.name) oid_count += 1 if options.verbose: print 'Using following oidsets/oids for fake devices:' pp.pprint(oidset_oid) loopcount = 0 ts = int(time.time()) val = 100 # 43200 - 12 hrs. 1440 loops - 1/2 day of data print 'Generating {0} data points.'.format( options.loop*options.routers*options.interfaces*oid_count) for iteration in xrange(options.loop): if options.verbose: print 'Loop {0}/{1}'.format(iteration, options.loop) for dn in router_names[0:options.routers]: device_name = '{0}_rtr_{1}'.format(options.prefix, dn) for oidset in oidset_oid.keys(): data = [] for oid in oidset_oid[oidset]: for i in xrange(options.interfaces): interface_name = 'fake_iface_{0}'.format(i) datum = [[oid, interface_name], val] data.append(datum) pr = PollResult( oidset_name=oidset, device_name=device_name, oid_name=oid, timestamp=ts, data=data, metadata={'tsdb_flags': 1} ) if options.verbose > 1: print pr.json() qs.put(pr) ts += 30 val += 50 loopcount += 1 pass