Skip to content
This repository has been archived by the owner on Jan 7, 2019. It is now read-only.

Encoding HTML entities #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@
# In Debian, you just need the mailx package installed for the above to work
# along with Ruby (of course).

require 'rubygems'
require 'htmlentities'
require 'erb'

ENV['COLUMNS'] = '200'

timestamp = Time.now.strftime("%B %d, %Y @ %I:%M%p %Z")
hostname = `hostname`
load_avg = `uptime | awk -F'average(s)?:' '{print $2}'`
coder = HTMLEntities.new

timestamp = coder.encode(Time.now.strftime("%B %d, %Y @ %I:%M%p %Z"))
hostname = coder.encode(`hostname`)
load_avg = coder.encode(`uptime | awk -F'average(s)?:' '{print $2}'`)

# Memory usage
totalmem = `free -m | grep Mem: | awk '{print $2}'`.to_i
Expand All @@ -23,15 +27,15 @@
actual_usedmem = usedmem - cachedmem
actual_freemem = totalmem - actual_usedmem

php_procs = `ps -ef | grep -v grep | grep -c php`
httpd_procs = `ps -ef|grep -v grep|grep -c httpd`
php_procs = coder.encode(`ps -ef | grep -v grep | grep -c php`)
httpd_procs = coder.encode(`ps -ef|grep -v grep|grep -c httpd`)
tcp_connections = `netstat -nat | grep tcp | awk '{ print $5}' | cut -d: -f1 | sed -e '/^$/d' | uniq | wc -l`

open_tcp_connections = `netstat -atun | grep tcp | awk '{print $5}' | cut -d: -f1 | sed -e '/^$/d' | sort | uniq -c | sort -n`
top_memory_procs = `ps aux --sort=-rss | head -11`.chomp.strip
top_cpu_procs = `ps aux --sort=-pcpu | grep -v grep | grep -E "(^([^ ]*?)[ ]*[0-9]*[ ]*(([0-9]{1,2}\.[1-9])|([1-9]{1,2}\.[0-9])))|USER" | head -11`.chomp.strip
netstat = `netstat -a --tcp | sort`.chomp.strip
top_snapshot = `top -c -b -n1`.chomp.strip
open_tcp_connections = coder.encode(`netstat -atun | grep tcp | awk '{print $5}' | cut -d: -f1 | sed -e '/^$/d' | sort | uniq -c | sort -n`)
top_memory_procs = coder.encode(`ps aux --sort=-rss | head -11`.chomp.strip)
top_cpu_procs = coder.encode(`ps aux --sort=-pcpu | grep -v grep | grep -E "(^([^ ]*?)[ ]*[0-9]*[ ]*(([0-9]{1,2}\.[1-9])|([1-9]{1,2}\.[0-9])))|USER" | head -11`.chomp.strip)
netstat = coder.encode(`netstat -a --tcp | sort`.chomp.strip)
top_snapshot = coder.encode(`top -c -b -n1`.chomp.strip)

# Determine graph color
memused_percent = ((actual_usedmem.to_f / totalmem.to_f) * 100).round
Expand Down