var url = "http://www.inmon.com/tutorials2/customers.xml"; var rootdir = "/var/www/html/customers/"; var height = 200; var width = 400; // get customer data var customersString = readurl(url); var customers = new XML(customersString); var network = Network.current(); // create list of customer interfaces var ifs = new Array(); for each (var customer in customers..customer) { for each (var port in customer..port) { network.path = port.@agent + ">" + port.@ifName; var ifId = network.interfaceId(); if(ifId) ifs.push(ifId); } } // query for trends on each customer interface var query = Query.trend( "historycounters", "time,interface,rate(ifinoctets),rate(ifoutoctets)", "interface=" + ifs, "yesterday", 5); var table = query.run(); // split results by customer var trends = new Array(); var pvt = table.pivotTime(0,1,2); for(var j = 1; j < pvt.ncols; j++) { var t = new Table(); t.start = table.start; t.end = table.end; t.addColumn("Time","time",pvt.column(0)); t.addColumn("In","double",pvt.column(j)); t.scaleColumn(1,8); trends[pvt.cnames[j]] = t; } pvt = table.pivotTime(0,1,3); for(var j = 1; j < pvt.ncols; j++) { var t = trends[pvt.cnames[j]]; t.addColumn("Out","double",pvt.column(j)); } // create charts for each customer for each (var customer in customers..customer) { var n = 1; for each (var port in customer..port) { network.path = port.@agent + ">" + port.@ifName; var ifId = network.interfaceId(); if(ifId) { var t = trends[ifId]; var chart = Chart.multiSeries( "trend", "Interface:" + n++, t, "Time", 0, "Bits per Second", [1,2]); chart.height = height; chart.width = width; write( rootdir + customer.@id + "/" + port.@agent + "-" + port.@ifName + ".png", chart); } else println( "cannot find interface, agent=" + port.@agent + " ifName=" + port.@ifName); } }