def main(self): netprof = self.netprofiler timefilter = TimeFilter.parse_range(self.options.timefilter) # Create and run a traffic summary report of all server ports in use report = TrafficSummaryReport(netprof) # Run the report report.run(groupby=netprof.groupbys.port, columns=[ netprof.columns.key.protoport, netprof.columns.key.protocol, netprof.columns.key.port, netprof.columns.value.avg_bytes ], sort_col=netprof.columns.value.avg_bytes, timefilter=timefilter) # Retrieve and print data ports_data = report.get_data()[:int(self.options.N)] report.delete() # Now create a new report using the ports_data report = TrafficTimeSeriesReport(netprof) # The format the query_columns for 'ports' is: # 'ports' = [{'name': 'tcp/80'}, # {'name': 'tcp/443'}, # {'name': 'icmp/0'}] # For most protocols, this works just fine from the report data, # but for icmp the result from data is 'icmp/0/0' -- where the two # zeros are type and code. This doesn't work for input to # netprofiler, it expects type and code to be smushed into a single # 16-bit number (type << 8 | code). query_columns = [] for (protoport, protocol, port, avgbytes) in ports_data: if protoport.startswith('icmp'): protoport = 'icmp/%s' % (port) query_columns.append({'name': protoport}) # Run the report report.run(columns=[ netprof.columns.key.time, netprof.columns.value.avg_bytes ], resolution='1 min', query_columns_groupby='ports', query_columns=query_columns, timefilter=timefilter) # Get the data! data = report.get_data() Formatter.print_table(data, padding=1, headers=(['time'] + [q['name'] for q in query_columns]))
def main(self): netprof = self.netprofiler timefilter = TimeFilter.parse_range(self.options.timefilter) # Create and run a traffic summary report of all server ports in use report = TrafficSummaryReport(netprof) # Run the report report.run( groupby=netprof.groupbys.port, columns=[netprof.columns.key.protoport, netprof.columns.key.protocol, netprof.columns.key.port, netprof.columns.value.avg_bytes], sort_col=netprof.columns.value.avg_bytes, timefilter=timefilter) # Retrieve and print data ports_data = report.get_data()[:int(self.options.N)] report.delete() # Now create a new report using the ports_data report = TrafficTimeSeriesReport(netprof) # The format the query_columns for 'ports' is: # 'ports' = [{'name': 'tcp/80'}, # {'name': 'tcp/443'}, # {'name': 'icmp/0'}] # For most protocols, this works just fine from the report data, # but for icmp the result from data is 'icmp/0/0' -- where the two # zeros are type and code. This doesn't work for input to # netprofiler, it expects type and code to be smushed into a single # 16-bit number (type << 8 | code). query_columns = [] for (protoport, protocol, port, avgbytes) in ports_data: if protoport.startswith('icmp'): protoport = 'icmp/%s' % (port) query_columns.append({'name': protoport}) # Run the report report.run(columns=[netprof.columns.key.time, netprof.columns.value.avg_bytes], resolution='1 min', query_columns_groupby='ports', query_columns=query_columns, timefilter=timefilter) # Get the data! data = report.get_data() Formatter.print_table( data, padding=1, headers=(['time'] + [q['name'] for q in query_columns]))
# connection information username = '******' password = '******' host = '<netprofiler.ip.address>' if (username == '<username>' or password == '<password>' or host == '<netprofiler.ip.address>'): print("Update the username, password, and netprofiler host values " "before running this script.") sys.exit(0) auth = UserAuth(username, password) p = NetProfiler(host, auth=auth) report = TrafficSummaryReport(p) columns = [ p.columns.key.host_ip, p.columns.value.avg_bytes, p.columns.value.network_rtt ] sort_column = p.columns.value.avg_bytes timefilter = TimeFilter.parse_range("last 15 m") report.run('hos', columns, timefilter=timefilter, sort_col=sort_column) data = report.get_data() legend = report.get_legend() report.delete() pprint.pprint(data[:10])
# connection information username = '******' password = '******' host = '<netprofiler.ip.address>' if (username == '<username>' or password == '<password>' or host == '<netprofiler.ip.address>'): print ("Update the username, password, and netprofiler host values " "before running this script.") sys.exit(0) auth = UserAuth(username, password) p = NetProfiler(host, auth=auth) report = TrafficSummaryReport(p) columns = [p.columns.key.host_ip, p.columns.value.avg_bytes, p.columns.value.network_rtt] sort_column = p.columns.value.avg_bytes timefilter = TimeFilter.parse_range("last 15 m") report.run('hos', columns, timefilter=timefilter, sort_col=sort_column) data = report.get_data() legend = report.get_legend() report.delete() pprint.pprint(data[:10])