def handle_rtopology(start_response, feedtype): """handler.""" headers = [("Content-type", "text/html")] start_response("200 OK", headers) req = requests.get(("http://rtstatstest/services/feedtype/%s/" "rtopology.json") % (feedtype, )) if req.status_code != 200: return [b"API Service Failure..."] j = req.json() if not isinstance(j, dict): view = myview.MyView() view.vars["content"] = "No topology found for host" return [view.render("main.html").encode("ascii", "ignore")] downstreams = j["downstreams"] content = u"<pre>\n" for hostname, ar in downstreams.items(): if len(ar) == 0 or (len(ar) == 1 and ar[0] == hostname): content += ('<a href="iddstats_topo_nc?%s+%s">%s</a>\n') % ( feedtype, hostname, hostname, ) continue nodedict = dict() nodedict[hostname] = Node(hostname) def get_node(host, parent): """Recursive method to find tree""" if host in nodedict: return nodedict[host] # we add the node nodedict[host] = Node(host, parent) # If nothing upstream, we can terminate and return for upstream in downstreams.get(host, []): get_node(upstream, nodedict[host]) for host in downstreams.get(hostname, []): if host in nodedict: nodedict.pop(host) nodedict[host] = get_node(host, nodedict[hostname]) for pre, _, node in RenderTree(nodedict[hostname]): content += ('%s<a href="iddstats_topo_nc?%s+%s">%s</a>\n') % ( pre, feedtype, node.name, node.name, ) content += u"</pre>\n" view = myview.MyView() view.vars["content"] = content return [view.render("main.html").encode("ascii", "ignore")]
def handle_topology(start_response, hostname, feedtype): """handler.""" headers = [("Content-type", "text/html")] start_response("200 OK", headers) URI = ("http://rtstatstest/services/feedtype/%s/topology.json") % ( feedtype, ) req = requests.get(URI) if req.status_code != 200: return [b"API Service Failure..."] j = req.json() if not isinstance(j, dict): view = myview.MyView() view.vars["content"] = "No topology found for host" return [view.render("main.html").encode("ascii", "ignore")] upstreams = j["upstreams"] nodedict = dict() nodedict[hostname] = Node(hostname) def get_node(host, parent): if host in nodedict: return nodedict[host] # we add the node nodedict[host] = Node(host, parent) # If nothing upstream, we can terminate and return for upstream in upstreams.get(host, []): get_node(upstream, nodedict[host]) for host in upstreams.get(hostname, []): if host in nodedict: nodedict.pop(host) nodedict[host] = get_node(host, nodedict[hostname]) content = u""" <h3>LDM Feedtype: %s Topology for Host: %s</h3> <p>Click on the hostname for topology for that host or the <i>view stats</i> link for detailed statistics for the host.</p> <pre>\n""" % ( feedtype, hostname, ) for pre, _, node in RenderTree(nodedict[hostname]): content += ('%s<a href="iddstats_topo_nc?%s+%s">%s</a> ' '(<a href="siteindex?%s">view stats</a>)\n') % ( pre, feedtype, node.name, node.name, node.name) content += "</pre>\n" content += timing(j, URI) view = myview.MyView() view.vars["content"] = content return [view.render("main.html").encode("ascii", "ignore")]
def handle_topology(hostname, feedtype): sys.stdout.write("Content-type: text/html\n\n") URI = ("http://rtstats.local/services/feedtype/%s/topology.json" ) % (feedtype, ) req = requests.get(URI) if req.status_code != 200: sys.stdout.write("API Service Failure...") return j = req.json() if isinstance(j, unicode): view = myview.MyView() view.vars['content'] = "No topology found for host" sys.stdout.write(view.render('main.html')) return upstreams = j['upstreams'] nodedict = dict() nodedict[hostname] = Node(hostname) def get_node(host, parent): if host in nodedict: return nodedict[host] # we add the node nodedict[host] = Node(host, parent) # If nothing upstream, we can terminate and return for upstream in upstreams.get(host, []): get_node(upstream, nodedict[host]) for host in upstreams.get(hostname, []): if host in nodedict: nodedict.pop(host) nodedict[host] = get_node(host, nodedict[hostname]) content = u""" <h3>LDM Feedtype: %s Topology for Host: %s</h3> <p>Click on the hostname for topology for that host or the <i>view stats</i> link for detailed statistics for the host.</p> <pre>\n""" % (feedtype, hostname) for pre, _, node in RenderTree(nodedict[hostname]): content += ("%s<a href=\"iddstats_topo_nc?%s+%s\">%s</a> " "(<a href=\"siteindex?%s\">view stats</a>)\n" ) % (pre, feedtype, node.name, node.name, node.name) content += "</pre>\n" content += timing(j, URI) view = myview.MyView() view.vars['content'] = content sys.stdout.write(view.render('main.html').encode('utf-8'))
def handle_sitesummary(hostname): sys.stdout.write("Content-type: text/html\n\n") req = requests.get(("http://rtstats.local/services/host/%s/feedtypes.json" ) % (hostname, )) if req.status_code != 200: sys.stdout.write("API Service Failure...") return j = req.json() content = ("<table border=\"1\" cellpadding=\"2\" cellspacing=\"0\"" "><thead><tr><h3>FEED NAME</h3></td><td> </td>" "<td> </td><td> </td>" "</tr></thead>") for feedtype in j['feedtypes']: content += ("<tr><th>%s</th>") % (feedtype,) content += """ <td><a href="%(p)s/iddstats_vol_nc1?%(f)s+%(h)s">Hourly volume</a></td> <td><a href="%(p)s/iddstats_vol_nc1?%(f)s+%(h)s+-b 86400">Daily volume</a></td> <td><a href="%(p)s/iddstats_vol_nc1?%(f)s+%(h)s+-b 604800">Weekly volume</a> </td> """ % dict(h=hostname, f=feedtype, p="/cgi-bin/rtstats") content += "</tr>" content += "</table>" content += """<p> <a href="%(p)s?%(h)s">Cumulative volume summary</a> <a href="%(p)s?%(h)s+GRAPH">Cumulative volume summary graph</a> """ % dict(h=hostname, p="/cgi-bin/rtstats/rtstats_summary_volume1") view = myview.MyView() view.vars['content'] = content sys.stdout.write(view.render('main.html'))
def handle_topoindex(start_response, link="rtstats_feedtree"): """Handler.""" headers = [("Content-type", "text/html")] start_response("200 OK", headers) req = requests.get("http://rtstatstest/services/feedtypes.json") if req.status_code != 200: res = b"API Service Failure..." return [res] j = req.json() listing = "" for feedtype in j["feedtypes"]: listing += ('<br /><a href="%s?%s">%s</a>\n') % ( link, feedtype, feedtype, ) view = myview.MyView() view.vars["content"] = """ <h2>RTSTATS Index by Sites Reporting Feeds</h2> <p> For information regarding the type of data contained within a feed type or feed set listed below, see the <a href="fixme">LDM Feedtypes</a> documentation.</p> <p> <h2>IDD Topology Feed List</h2> %s """ % (listing, ) return [view.render("main.html").encode("ascii", "ignore")]
def handle_sitesummary(start_response, hostname): """Handler.""" headers = [("Content-type", "text/html")] start_response("200 OK", headers) req = requests.get( ("http://rtstatstest/services/host/%s/feedtypes.json") % (hostname, )) if req.status_code != 200: return [b"API Service Failure..."] j = req.json() content = ('<table border="1" cellpadding="2" cellspacing="0"' "><thead><tr><h3>FEED NAME</h3></td><td> </td>" "<td> </td><td> </td>" "</tr></thead>") for feedtype in j["feedtypes"]: content += ("<tr><th>%s</th>") % (feedtype, ) content += """ <td><a href="%(p)s/iddstats_vol_nc1?%(f)s+%(h)s">Hourly volume</a></td> <td><a href="%(p)s/iddstats_vol_nc1?%(f)s+%(h)s+-b 86400">Daily volume</a></td> <td><a href="%(p)s/iddstats_vol_nc1?%(f)s+%(h)s+-b 604800">Weekly volume</a> </td> """ % dict(h=hostname, f=feedtype, p="/cgi-bin/rtstats") content += "</tr>" content += "</table>" content += """<p> <a href="%(p)s?%(h)s">Cumulative volume summary</a> <a href="%(p)s?%(h)s+GRAPH">Cumulative volume summary graph</a> """ % dict(h=hostname, p="/cgi-bin/rtstats/rtstats_summary_volume1") view = myview.MyView() view.vars["content"] = content return [view.render("main.html").encode("ascii", "ignore")]
def handle_rtopology(feedtype): sys.stdout.write("Content-type: text/html\n\n") req = requests.get(("http://rtstats.local/services/feedtype/%s/" "rtopology.json" ) % (feedtype, )) if req.status_code != 200: sys.stdout.write("API Service Failure...") return j = req.json() if isinstance(j, unicode): view = myview.MyView() view.vars['content'] = "No topology found for host" sys.stdout.write(view.render('main.html')) return downstreams = j['downstreams'] content = u"<pre>\n" for hostname, ar in downstreams.iteritems(): if len(ar) == 0 or (len(ar) == 1 and ar[0] == hostname): content += ("<a href=\"iddstats_topo_nc?%s+%s\">%s</a>\n" ) % (feedtype, hostname, hostname) continue nodedict = dict() nodedict[hostname] = Node(hostname) def get_node(host, parent): if host in nodedict: return nodedict[host] # we add the node nodedict[host] = Node(host, parent) # If nothing upstream, we can terminate and return for upstream in downstreams.get(host, []): get_node(upstream, nodedict[host]) for host in downstreams.get(hostname, []): if host in nodedict: nodedict.pop(host) nodedict[host] = get_node(host, nodedict[hostname]) for pre, _, node in RenderTree(nodedict[hostname]): content += ("%s<a href=\"iddstats_topo_nc?%s+%s\">%s</a>\n" ) % (pre, feedtype, node.name, node.name) content += u"</pre>\n" view = myview.MyView() view.vars['content'] = content sys.stdout.write(view.render('main.html').encode('utf-8'))
def handle_volume_stats(start_response, hostname): """handler.""" headers = [("Content-type", "text/html")] start_response("200 OK", headers) req = requests.get(("http://rtstatstest/services/host/%s/" "hourly.json") % (hostname, )) if req.status_code != 200: return [b"API Service Failure..."] j = req.json() df = pd.DataFrame(j["data"], columns=j["columns"]) df["valid"] = pd.to_datetime(df["valid"]) maxbytes = df[["valid", "nbytes"]].groupby("valid").sum().max()["nbytes"] avgbytes = df[["valid", "nbytes"]].groupby("valid").sum().mean()["nbytes"] avgprods = df[["valid", "nprods"]].groupby("valid").sum().mean()["nprods"] feedtypetots = (df.groupby("feedtype").sum()["nbytes"].sort_values( ascending=False)) total = float(feedtypetots.sum()) listing = "" for feedtype, nbytes in feedtypetots.items(): fdf = df[df["feedtype"] == feedtype] avgbyteshr = (fdf[["valid", "nbytes"]].groupby("valid").sum().mean()["nbytes"]) maxbyteshr = (fdf[["valid", "nbytes"]].groupby("valid").sum().max()["nbytes"]) avgprodshr = (fdf[["valid", "nprods"]].groupby("valid").sum().mean()["nprods"]) listing += ("%-18s %12.3f [%7.3f%%] %12.3f %12.3f\n") % ( feedtype, avgbyteshr / 1000000.0, nbytes / total * 100.0, maxbyteshr / 1000000.0, avgprodshr, ) content = """<pre> Data Volume Summary for %s Maximum hourly volume %10.3f M bytes/hour Average hourly volume %10.3f M bytes/hour Average products per hour %10.0f prods/hour Feed Average Maximum Products (M byte/hour) (M byte/hour) number/hour %s </pre> """ % ( hostname, maxbytes / 1000000.0, avgbytes / 1000000.0, avgprods, listing, ) view = myview.MyView() view.vars["content"] = content return [view.render("main.html").encode("ascii", "ignore")]
def handle_volume_stats(hostname): sys.stdout.write("Content-type: text/html\n\n") req = requests.get(("http://rtstats.local/services/host/%s/" "hourly.json" ) % (hostname, )) if req.status_code != 200: sys.stdout.write("API Service Failure...") return j = req.json() df = pd.DataFrame(j['data'], columns=j['columns']) df['valid'] = pd.to_datetime(df['valid']) maxbytes = df[['valid', 'nbytes']].groupby('valid').sum().max()['nbytes'] avgbytes = df[['valid', 'nbytes']].groupby('valid').sum().mean()['nbytes'] avgprods = df[['valid', 'nprods']].groupby('valid').sum().mean()['nprods'] feedtypetots = df.groupby('feedtype').sum()['nbytes'].sort_values( ascending=False) total = float(feedtypetots.sum()) listing = "" for feedtype, nbytes in feedtypetots.iteritems(): fdf = df[df['feedtype'] == feedtype] avgbyteshr = fdf[['valid', 'nbytes']].groupby('valid').sum( ).mean()['nbytes'] maxbyteshr = fdf[['valid', 'nbytes']].groupby('valid').sum( ).max()['nbytes'] avgprodshr = fdf[['valid', 'nprods']].groupby('valid').sum( ).mean()['nprods'] listing += ("%-18s %12.3f [%7.3f%%] %12.3f %12.3f\n" ) % (feedtype, avgbyteshr / 1000000., nbytes / total * 100., maxbyteshr / 1000000., avgprodshr) content = """<pre> Data Volume Summary for %s Maximum hourly volume %10.3f M bytes/hour Average hourly volume %10.3f M bytes/hour Average products per hour %10.0f prods/hour Feed Average Maximum Products (M byte/hour) (M byte/hour) number/hour %s </pre> """ % (hostname, maxbytes / 1000000., avgbytes / 1000000., avgprods, listing) view = myview.MyView() view.vars['content'] = content sys.stdout.write(view.render('main.html'))
def handle_siteindex(link, feedtype=None): sys.stdout.write("Content-type: text/html\n\n") URI = "/services/hosts.geojson" if feedtype is not None: URI += "?feedtype=%s" % (feedtype,) req = requests.get("http://rtstats.local" + URI) if req.status_code != 200: sys.stdout.write("API Service Failure...") return j = req.json() domains = dict() for feature in j['features']: host = feature['properties']['hostname'] ldmversion = feature['properties']['ldmversion'] d = get_domain(host) d2 = domains.setdefault(d, dict()) d2[host] = ldmversion content = """ <h3>Sites Receiving %s Feedtype</h3> <table border="1" cellpadding="2" cellspacing="0"> <thead> <tr><th>Domain</th><th>Hosts</th></tr> </thead> """ % ('ANY' if feedtype is None else feedtype,) keys = domains.keys() keys.sort() for d in keys: domain = domains[d] dkeys = domain.keys() dkeys.sort() content += ("<tr><th>%s</th><td>") % (d,) for h in dkeys: content += ("<a href=\"/cgi-bin/rtstats/%s?%s\">" "%s</a> [%s]<br />" ) % (link, h, h, domain[h]) content += "</td></tr>" content += "</table>" content += timing(j, URI) view = myview.MyView() view.vars['content'] = content sys.stdout.write(view.render('main.html'))
def handle_siteindex(start_response, link, feedtype=None): """Handler.""" headers = [("Content-type", "text/html")] start_response("200 OK", headers) URI = "/services/hosts.geojson" if feedtype is not None: URI += "?feedtype=%s" % (feedtype, ) req = requests.get("http://rtstatstest" + URI) if req.status_code != 200: return [b"API Service Failure..."] j = req.json() domains = dict() for feature in j["features"]: host = feature["properties"]["hostname"] ldmversion = feature["properties"]["ldmversion"] d = get_domain(host) d2 = domains.setdefault(d, dict()) d2[host] = ldmversion content = """ <h3>Sites Receiving %s Feedtype</h3> <table border="1" cellpadding="2" cellspacing="0"> <thead> <tr><th>Domain</th><th>Hosts</th></tr> </thead> """ % ("ANY" if feedtype is None else feedtype, ) keys = list(domains.keys()) keys.sort() for d in keys: domain = domains[d] dkeys = list(domain.keys()) dkeys.sort() content += ("<tr><th>%s</th><td>") % (d, ) for h in dkeys: content += ('<a href="/cgi-bin/rtstats/%s?%s">' "%s</a> [%s]<br />") % (link, h, h, domain[h]) content += "</td></tr>" content += "</table>" content += timing(j, URI) view = myview.MyView() view.vars["content"] = content return [view.render("main.html").encode("ascii", "ignore")]
def handle_site(hostname): sys.stdout.write("Content-type: text/html\n\n") URI = ("http://rtstats.local/services/host/%s/feedtypes.json" ) % (hostname, ) req = requests.get(URI) if req.status_code != 200: sys.stdout.write("API Service Failure...") return j = req.json() content = """ <h3>Available Realtime Stats for Hostname: %s</h3> <table border="1" cellpadding="2" cellspacing="0"> <thead> <tr><th>Feed Name</th> <td> </td><td> </td><td> </td> <td> </td><td> </td><td> </td> </tr> </thead> """ % (hostname,) for feedtype in j['feedtypes']: content += ("<tr><th>%s</th>") % (feedtype,) content += """ <td><a href="%(p)s/iddstats_nc?%(f)s+%(h)s">latency</a></td> <td><a href="%(p)s/iddstats_nc?%(f)s+%(h)s+LOG">log(latency)</a></td> <td><a href="%(p)s/iddbinstats_nc?%(f)s+%(h)s">histogram</a></td> <td><a href="%(p)s/iddstats_vol_nc?%(f)s+%(h)s">volume</a></td> <td><a href="%(p)s/iddstats_num_nc?%(f)s+%(h)s">products</a></td> <td><a href="%(p)s/iddstats_topo_nc?%(f)s+%(h)s">topology</a></td> """ % dict(h=hostname, f=feedtype, p="/cgi-bin/rtstats") content += "</tr>" content += "</table>" content += """<p> <a href="%(p)s?%(h)s">Cumulative volume summary</a> <a href="%(p)s?%(h)s+GRAPH">Cumulative volume summary graph</a> """ % dict(h=hostname, p="/cgi-bin/rtstats/rtstats_summary_volume") content += timing(j, URI) view = myview.MyView() view.vars['content'] = content sys.stdout.write(view.render('main.html'))
def handle_site(start_response, hostname): """Handler.""" headers = [("Content-type", "text/html")] start_response("200 OK", headers) URI = ("http://rtstatstest/services/host/%s/feedtypes.json") % (hostname, ) req = requests.get(URI) if req.status_code != 200: return [b"API Service Failure..."] j = req.json() content = """ <h3>Available Realtime Stats for Hostname: %s</h3> <table border="1" cellpadding="2" cellspacing="0"> <thead> <tr><th>Feed Name</th> <td> </td><td> </td><td> </td> <td> </td><td> </td><td> </td> </tr> </thead> """ % (hostname, ) for feedtype in j["feedtypes"]: content += ("<tr><th>%s</th>") % (feedtype, ) content += """ <td><a href="%(p)s/iddstats_nc?%(f)s+%(h)s">latency</a></td> <td><a href="%(p)s/iddstats_nc?%(f)s+%(h)s+LOG">log(latency)</a></td> <td><a href="%(p)s/iddbinstats_nc?%(f)s+%(h)s">histogram</a></td> <td><a href="%(p)s/iddstats_vol_nc?%(f)s+%(h)s">volume</a></td> <td><a href="%(p)s/iddstats_num_nc?%(f)s+%(h)s">products</a></td> <td><a href="%(p)s/iddstats_topo_nc?%(f)s+%(h)s">topology</a></td> """ % dict(h=hostname, f=feedtype, p="/cgi-bin/rtstats") content += "</tr>" content += "</table>" content += """<p> <a href="%(p)s?%(h)s">Cumulative volume summary</a> <a href="%(p)s?%(h)s+GRAPH">Cumulative volume summary graph</a> """ % dict(h=hostname, p="/cgi-bin/rtstats/rtstats_summary_volume") content += timing(j, URI) view = myview.MyView() view.vars["content"] = content return [view.render("main.html").encode("ascii", "ignore")]
def handle_topoindex(link='rtstats_feedtree'): sys.stdout.write("Content-type: text/html\n\n") req = requests.get("http://rtstats.local/services/feedtypes.json") if req.status_code != 200: sys.stdout.write("API Service Failure...") return j = req.json() listing = "" for feedtype in j['feedtypes']: listing += ("<br /><a href=\"%s?%s\">%s</a>\n" ) % (link, feedtype, feedtype) view = myview.MyView() view.vars['content'] = """ <h2>RTSTATS Index by Sites Reporting Feeds</h2> <p> For information regarding the type of data contained within a feed type or feed set listed below, see the <a href="fixme">LDM Feedtypes</a> documentation.</p> <p> <h2>IDD Topology Feed List</h2> %s """ % (listing,) sys.stdout.write(view.render('main.html'))
spos_data = spos_data[:].copy() if not vtk_export_mode: for mu in cf_prov._mu_coefs: renderer.AddActor(gactor[mu]) renderer.AddActor(cactor[mu]) renderer.AddActor(clactor[mu]) renderer.AddActor(sactora[mu]) renderer.AddActor(sactorb[mu]) import imp try: imp.load_source('myview', 'myview.py') import myview this_view = myview.MyView(renderer) except IOError as e: pass id_t0 = numpy.where(dpos_data[:, 0] == min(dpos_data[:, 0])) # set_positionv(spos_data[:, 1], spos_data[:, 2], spos_data[:, 3], # spos_data[:, 4], spos_data[:, 5], spos_data[:, 6], # spos_data[:, 7], spos_data[:, 8]) set_positionv(pos_data[id_t0, 1], pos_data[id_t0, 2], pos_data[id_t0, 3], pos_data[id_t0, 4], pos_data[id_t0, 5], pos_data[id_t0, 6], pos_data[id_t0, 7], pos_data[id_t0, 8])