Hi, htop author here: this brought a smile to my face! Wondering if I should do the same in htop's own website. Would be fun to follow the activity spike when the new major release comes later this year! Major kudos to the author for the idea!
You can make it more efficient by capturing the images to a buffer and rendering a low FPS h264 stream, serving it as HLS fragments and displaying it with hls.js ( <a href="https://github.com/dailymotion/hls.js" rel="nofollow">https://github.com/dailymotion/hls.js</a> ) as a background element. There is a lot of inter frame compression benefits to be had from this sort of content + it will look more nice with a constant stream of frames. With a low FPS, the CPU usage should be low enough to not be noticeable and also, you can serve a static JPEG as a "preview" when loading the stream in the background for having a background picture on load.
Neat thanks!<p>You can generate HTML (and from that png or whatever) with <a href="http://www.pixelbeat.org/scripts/ansi2html.sh" rel="nofollow">http://www.pixelbeat.org/scripts/ansi2html.sh</a> like<p><pre><code> $ COLUMNS=80 timeout 1 htop > t.ansi
$ ansi2html.sh --bg=dark < t.ansi > t.html
</code></pre>
I've requested a -b, --batch option for htop, to simplify this mode of operation. <a href="https://github.com/hishamhm/htop/issues/282" rel="nofollow">https://github.com/hishamhm/htop/issues/282</a> Then you could just:<p><pre><code> $ COLUMNS=80 htop -b | ansi2html.sh ...</code></pre>
Direct link to the generated background image: <a href="http://104.233.86.94/background/background.png" rel="nofollow">http://104.233.86.94/background/background.png</a>
I studied the line
read _ _ sid < <(2>&1 strace -esetsid setsid sh -c "exec $PROGRAM <> /dev/tty2 >&0 2>&1 ")<p><( is an example of process substitution, in case anyone is interested. Basically it feeds the stdout of the subshell into the stdin of the read (previous) command.
Here is a detailed explanation:
<a href="http://www.tldp.org/LDP/abs/html/abs-guide.html#PROCESS-SUB" rel="nofollow">http://www.tldp.org/LDP/abs/html/abs-guide.html#PROCESS-SUB</a>
I wrote a tiny program that captures the content of a Linux virtual console and prints it to stdout.[1] I forgot why I wrote it, but the source code shows how to access foreground color, background color and the font weight.[2] You could hack it to print everything in a format that's easily parsable, write it to a file every second and do the rendering on the client side with JavaScript.<p>[1] <a href="https://github.com/slyrz/peep/" rel="nofollow">https://github.com/slyrz/peep/</a><p>[2] <a href="https://github.com/slyrz/peep/blob/master/peep.c#L165" rel="nofollow">https://github.com/slyrz/peep/blob/master/peep.c#L165</a>
Great idea! But wouldn't it be best to restrain the output of htop to a few interesting processes that are running without root privileges. It seems to me that it could be possible to bubble up processes that can leak information, especially at startup and when you put the server under load externally...
I wonder how <a href="https://github.com/ansilove/AnsiLove-C" rel="nofollow">https://github.com/ansilove/AnsiLove-C</a> would fare for generating the PNG compared to the current solution.
I've used this to show live htop on a web page: <a href="https://github.com/dtinth/ttycast" rel="nofollow">https://github.com/dtinth/ttycast</a>
Not sure I understand why there's 4 nginx processes, 4 php-fpm processes and like 20 mysql processes, why so many, don't you need like 1 (or 4 if there' no pooling)?
Nice idea although a bit dangerous! I wonder if it would be better to use as background the output of a program like gotty, which streams a terminal's output as a web page.
Interesting, thanks! Probably not as cool, but you could also just get the output of the regular top, parse it and generate HTML from it (a bit like <a href="http://tracesof.net/uebersicht/" rel="nofollow">http://tracesof.net/uebersicht/</a>)
Nice. Always meant to try and do something similar myself using <a href="https://github.com/joewalnes/websocketd" rel="nofollow">https://github.com/joewalnes/websocketd</a>