Fri, 07 Aug 2020 04:03:21 -0600
- Add index page generation
lua/genstats.lua | file | annotate | diff | comparison | revisions | |
lua/htmltemplates.lua | file | annotate | diff | comparison | revisions | |
lua/panels.lua | file | annotate | diff | comparison | revisions |
--- a/lua/genstats.lua Fri Aug 07 02:27:15 2020 -0600 +++ b/lua/genstats.lua Fri Aug 07 04:03:21 2020 -0600 @@ -3,13 +3,15 @@ ---------------------------------------------------------------------------]]-- -- Ugly stuff to let us load packages from our passed file directory. -local function FilePath() - local str = debug.getinfo(2, "S").source:sub(2) - return str:match("(.*[/\\])") or "." +local function GetFilePath() + local path = debug.getinfo(2, "S").source:sub(2) + return path:match("(.*[/\\])") or "." -- Windows hack stuff end -package.path = package.path .. ";" .. FilePath() .. "/?.lua" +-- So we can load modules from the directory this script is in... +package.path = package.path .. ";" .. GetFilePath() .. "/?.lua" local HTML = require("htmltemplates") -- HTML is messy, hide it away. +local panels = require("panels") -- Loads all the panels to populate. local timeScales = {} timeScales[1] = {"24 Hours", "now-24h", "now"} @@ -18,29 +20,13 @@ timeScales[4] = {"1 Year", "now-1y", "now"} timeScales[5] = {"2 Years", "now-2y", "now"} -local panels = {} --- Transit -panels[1] = {name="Cogent", id="24", type="transit"} -panels[2] = {name="Comcast", id="26", type="transit"} -panels[3] = {name="NTT", id="30", url="NTT", type="transit"} -panels[4] = {name="XO", id="2", type="transit"} --- Exchanges -panels[5] = {name="Any2", id="13", type="exchange"} -panels[6] = {name="SIX", id="34", url="SIX", type="exchange"} -panels[7] = {name="SLIX", id="28", url="SLIX", type="exchange"} -panels[8] = {name="HE", id="63", url="HE", type="exchange"} --- Endpoints -panels[9] = {name="Colind", id="38", type="endpoint"} -panels[10] = {name="Google DNS", id="42", url="google", type="endpoint"} -panels[11] = {name="DAL05 (Softlayer)", id="46", url="dal05", type="endpoint"} -panels[12] = {name="NFO (LA)", id="51", url="nfola", type="endpoint"} -panels[13] = {name="NFO (SJ)", id="52", url="nfosj", type="endpoint"} -panels[14] = {name="C7 (SLC)", id="56", url="c7slc", type="endpoint"} -panels[15] = {name="Zarth (CHI)", id="60", url="zarth", type="endpoint"} - +--[[ + Latency Pages +--]] local function GenerateSection(timescale, panel) local section = "" .. HTML.section + -- This is probably a really slow way to do this, but it isn't an issue yet section = string.gsub(section, "$TIMESCALEENGLISH", tostring(timescale[1])) section = string.gsub(section, "$FROM", tostring(timescale[2])) section = string.gsub(section, "$TO", tostring(timescale[3])) @@ -71,21 +57,101 @@ end local function WriteHTML(panel) - local file, code = io.open( ( FilePath() .. "latency/" .. ( panel.url or string.lower(panel.name) ) ) .. ".html", "w") + local file, code = io.open( ( GetFilePath() .. "latency/" .. ( panel.url or string.lower(panel.name) ) ) .. ".html", "w") if not file then - return nil + return nil, code end file:write(GeneratePanel(panel)) return file, code end --- Do the do! +-- Generate Latency Pages for i=1, #panels do local panel = panels[i] local didWrite = WriteHTML(panel) + local code = "" if didWrite == nil then - os.execute("mkdir " .. FilePath() .. "latency") - WriteHTML(panel) + os.execute("mkdir " .. GetFilePath() .. "latency") -- Make the directory if it didn't exist + didWrite, code = WriteHTML(panel) + end + if didWrite == nil then -- Messy, but abort if something went really wrong. + error(code) end print("Wrote: " .. (panel.url or string.lower(panel.name)) .. ".html" ) -end \ No newline at end of file +end + +--[[ + Index/Landing Page +--]] + +-- Reusable code +local function GenerateFlexbox(i, max, panel) + local flexbox = "" .. HTML.index.flexgraph + flexbox = string.gsub(flexbox, "$PANELNAME", tostring(panel.name)) + flexbox = string.gsub(flexbox, "$URL", ( panel.url or string.lower(tostring(panel.name)) ) ) + flexbox = string.gsub(flexbox, "$PANELID", tostring(panel.id)) + local flextype = "graphs" + if i == 1 then + flextype = "start" + elseif i == max then + flextype = "end" + end + flexbox = string.gsub(flexbox, "$FLEXTYPE", flextype) + return flexbox +end + +local function GeneratePanelTable(ptab) + local newpanel = "" + for i=1, #ptab do + local panel = ptab[i] + newpanel = newpanel .. GenerateFlexbox(i, #ptab, panel) + end + return newpanel +end + +-- Didn't do all of this in a function because it wasn't really needed. + +local transits = {} +local exchanges = {} +local endpoints = {} + +-- Sort our panels into their types so we can build HTML sections. +for i=1, #panels do + local panel = panels[i] + if panel.type == "transit" then + transits[#transits + 1 ] = panel + elseif panel.type == "exchange" then + exchanges[#exchanges + 1 ] = panel + elseif panel.type == "endpoint" then + endpoints[#endpoints + 1 ] = panel + end +end + +-- This is ugly! +local output = "" .. HTML.index.header + +-- Transits +output = output .. HTML.index.linkboxhead +output = output .. HTML.index.h4transit +output = output .. HTML.index.flexcontainerhead +output = output .. GeneratePanelTable(transits) +output = output .. HTML.index.flexcontainertail +--Exchanges (part of the same linkbox) +output = output .. HTML.index.h4exchange +output = output .. HTML.index.flexcontainerhead +output = output .. GeneratePanelTable(exchanges) +output = output .. HTML.index.flexcontainertail +output = output .. HTML.index.linkboxtail +-- Endpoints (new linkbox) +output = output .. HTML.index.linkboxhead +output = output .. HTML.index.h4endpoint +output = output .. HTML.index.flexcontainerhead +output = output .. GeneratePanelTable(endpoints) +output = output .. HTML.index.flexcontainertail +output = output .. HTML.index.linkboxtail + +output = output .. HTML.index.footer + +local file = io.open( GetFilePath() .. "index.html", "w") +assert(file:write(output)) +print("\nWrote: " .. "index.html" )
--- a/lua/htmltemplates.lua Fri Aug 07 02:27:15 2020 -0600 +++ b/lua/htmltemplates.lua Fri Aug 07 04:03:21 2020 -0600 @@ -1,5 +1,7 @@ local templates = {} +-- Individual Pages + templates.header = [[ <!DOCTYPE html> <html> @@ -60,4 +62,107 @@ </section> ]] +-- Landing Page + +templates.index = {} +local index = templates.index + +index.header = [[ +<!DOCTYPE html> +<html> + +<head> +<meta name=viewport content="width=device-width, initial-scale=0.75" charset="UTF-8"> +<meta name="robots" content="noindex"> +<link rel="icon" type="image/png" href="https://static.glitchvid.com/favicon.png"> +<link rel="stylesheet" href="../styles.css"> +<link href="https://fonts.googleapis.com/css?family=Roboto:400,700&display=swap" rel="stylesheet"> + +<title>NACL STATS</title> +</head> + +<body bgcolor="#1a1a1a"> + <h1 class="gvidnet"> + NACL STATS + </h1> + + <div class="linkbox"> + <section class="links"> + <h4> + SYSTEM HEALTH + </h4> + <div class="flex-container"> + <div class="flex-graphs"><iframe src="https://grafana.nacl.glitchvid.com/d-solo/39mqm44Zz/render-template-dashboard?orgId=2&refresh=5m&var-interval=5m&from=now-30s&to=now&panelId=8" width="148" height="148" frameborder="0"></iframe></div> + <div class="flex-graphs"><iframe src="https://grafana.nacl.glitchvid.com/d-solo/39mqm44Zz/render-template-dashboard?orgId=2&refresh=5m&var-interval=5m&from=now-24h&to=now&panelId=9" width="148" height="148" frameborder="0"></iframe></div> + <div class="flex-graphs"><iframe src="https://grafana.nacl.glitchvid.com/d-solo/39mqm44Zz/render-template-dashboard?orgId=2&refresh=5m&var-interval=5m&from=now-24h&to=now&panelId=10" width="512" height="148" frameborder="0"></iframe></div> + <div class="flex-graphs"><iframe src="https://grafana.nacl.glitchvid.com/d-solo/39mqm44Zz/render-template-dashboard?orgId=2&refresh=5m&var-interval=5m&from=now-24h&to=now&panelId=11" width="512" height="148" frameborder="0"></iframe></div> + </div> + </div> +]] + +index.footer = [[ + + <table width=100% height=100%> + <tr tabrow> + <td style="text-align: center;vertical-align: middle;border-top: dotted;border-top-width: 1px;border-color: #272727;"> + <br> + <h4> + RETURN HOME: + </h4> + <gcomlink> + <a href="http://glitchvid.com">Glitchvid.com</a> + </gcomlink> + </td> + </tr> + </table> + +</body> +</html> +]] + +index.linkboxhead = [[ + <div class="linkbox"> + <section class="links"> +]] + +index.linkboxtail = [[ + + </section> + </div> +]] + +index.flexcontainerhead = [[ + <div class="flex-container"> +]] + +index.flexcontainertail = [[ + + </div> +]] + +index.flexgraph = [[ + <div class="flex-$FLEXTYPE"> + <h4> <a href="latency/$URL"> $PANELNAME </a> </h4> + <iframe src="https://grafana.nacl.glitchvid.com/d-solo/39mqm44Zz/render-template-dashboard?orgId=2&refresh=5m&var-interval=5m&from=now-24h&to=now&panelId=$PANELID" width="512" height="148" frameborder="0"></iframe> + </div> +]] + +index.h4transit = [[ + <h4> + TRANSIT LATENCY + </h4> +]] + +index.h4exchange = [[ + <h4> + EXCHANGE LATENCY + </h4> +]] + +index.h4endpoint = [[ + <h4> + ENDPOINT LATENCY + </h4> +]] + return templates \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lua/panels.lua Fri Aug 07 04:03:21 2020 -0600 @@ -0,0 +1,94 @@ +local panels = {} + +-- Transit +panels[1] = { + name = "Cogent", + id = "24", + type = "transit", +} +panels[2] = { + name = "Comcast", + id = "26", + type = "transit" +} +panels[3] = { + name = "NTT", + id = "30", + url = "NTT", + type = "transit" +} +panels[4] = { + name = "XO", + id = "2", + type = "transit" +} + +-- Exchanges +panels[5] = { + name = "Any2", + id = "13", + type = "exchange" +} +panels[6] = { + name = "SIX", + id = "34", + url = "SIX", + type = "exchange" +} +panels[7] = { + name = "SLIX", + id = "28", + url = "SLIX", + type = "exchange" +} +panels[8] = { + name = "HE", + id = "63", + url = "HE", + type = "exchange" +} + +-- Endpoints +panels[9] = { + name = "Colind", + id = "38", + type = "endpoint" +} +panels[10] = { + name = "Google DNS", + id = "42", + url = "google", + type = "endpoint" +} +panels[11] = { + name = "DAL05 (Softlayer)", + id = "46", + url = "dal05", + type="endpoint" +} +panels[12] = { + name = "NFO (LA)", + id = "51", + url = "nfola", + type = "endpoint" +} +panels[13] = { + name = "NFO (SJ)", + id = "52", + url = "nfosj", + type = "endpoint" +} +panels[14] = { + name = "C7 (SLC)", + id = "56", + url = "c7slc", + type = "endpoint" +} +panels[15] = { + name = "Zarth (CHI)", + id = "60", + url = "zarth", + type = "endpoint" +} + +return panels \ No newline at end of file