mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-08-04 08:50:27 +00:00
Add raw memory visualization tool to redbean
This change introduces a `-W /dev/pts/1` flag to redbean. What it does is use the mincore() system call to create a dual-screen terminal display that lets you troubleshoot the virtual address space. This is useful since page faults are an important thing to consider when using a forking web server. Now we have a colorful visualization of which pages are going to fault and which ones are resident in memory. The memory monitor, if enabled, spawns as a thread that just outputs ANSI codes to the second terminal in a loop. In order to make this happen using the new clone() polyfill, stdio is now thread safe. This change also introduces some new demo pages to redbean. It also polishes the demos we already have, to look a bit nicer and more presentable for the upcoming release, with better explanations too.
This commit is contained in:
parent
578cb21591
commit
80b211e314
106 changed files with 1483 additions and 592 deletions
|
@ -1,3 +1,6 @@
|
|||
-- redbean maxmind demo
|
||||
-- by justine tunney
|
||||
|
||||
local maxmind = require "maxmind"
|
||||
|
||||
local kMetroCodes = {
|
||||
|
@ -258,7 +261,7 @@ local function main()
|
|||
local ip = nil
|
||||
local geo = nil
|
||||
local asn = nil
|
||||
local value = ''
|
||||
local value = '8.8.8.8'
|
||||
if HasParam('ip') then
|
||||
local geodb = maxmind.open('/usr/local/share/maxmind/GeoLite2-City.mmdb')
|
||||
local asndb = maxmind.open('/usr/local/share/maxmind/GeoLite2-ASN.mmdb')
|
||||
|
@ -279,18 +282,58 @@ local function main()
|
|||
end
|
||||
end
|
||||
|
||||
SetHeader('Content-Type', 'text/html; charset=utf-8')
|
||||
Write('<!doctype html>\n')
|
||||
Write([[
|
||||
<title>maxmind redbean demo</title>
|
||||
Write([[<!doctype html>
|
||||
<title>redbean maxmind demo</title>
|
||||
<style>
|
||||
body { padding: 1em; }
|
||||
h1 a { color: inherit; text-decoration: none; }
|
||||
h1 img { border: none; vertical-align: middle; }
|
||||
input { margin: 1em; padding: .5em; }
|
||||
pre { margin-left: 2em; }
|
||||
p { word-break: break-word; max-width: 650px; }
|
||||
dt { font-weight: bold; }
|
||||
dd { margin-top: 1em; margin-bottom: 1em; }
|
||||
.hdr { text-indent: -1em; padding-left: 1em; }
|
||||
</style>
|
||||
<h1>
|
||||
<a href="/"><img src="/redbean.png"></a>
|
||||
<a href="maxmind.lua">redbean maxmind demo</a>
|
||||
</h1>
|
||||
<p>
|
||||
Your redbean supports MaxMind GeoLite2 which is a free database
|
||||
you have to download separately, at their <a
|
||||
href="https://www.maxmind.com/en/geolite2/signup">website
|
||||
here</a>. It's worth doing because it lets you turn IP addresses
|
||||
into geographical coordinates, addresses, name it. Being able to
|
||||
Lua script this database is going to help you address things like
|
||||
online fraud and abuse.
|
||||
</p>
|
||||
<p>
|
||||
This script is hard coded to assume the database is at the
|
||||
following paths:
|
||||
<ul>
|
||||
<li><code>/usr/local/share/maxmind/GeoLite2-City.mmdb</code>
|
||||
<li><code>/usr/local/share/maxmind/GeoLite2-ASN.mmdb</code>
|
||||
</ul>
|
||||
<p>
|
||||
Which on Windows basically means the same thing as:
|
||||
</p>
|
||||
<ul>
|
||||
<li><code>C:\usr\local\share\maxmind\GeoLite2-City.mmdb</code>
|
||||
<li><code>C:\usr\local\share\maxmind\GeoLite2-ASN.mmdb</code>
|
||||
</ul>
|
||||
<p>
|
||||
Once you've placed it there, you can fill out the form below to
|
||||
have fun crawling all the information it provides!
|
||||
</p>
|
||||
<form action="maxmind.lua" method="get">
|
||||
<input type="text" id="ip" name="ip" placeholder="8.8.8.8"
|
||||
value="]] .. value .. [[">
|
||||
value="%s" onfocus="this.select()" autofocus>
|
||||
<label for="ip">ip address</label>
|
||||
<br>
|
||||
<input type="submit" value="Lookup">
|
||||
<input type="submit" value="Lookup" autofocus>
|
||||
</form>
|
||||
]])
|
||||
]] % {EscapeHtml(value)})
|
||||
|
||||
if ip then
|
||||
Write('<h3>Maxmind Geolite DB</h3>')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue