Compare commits

..

No commits in common. "master" and "gh-pages" have entirely different histories.

20 changed files with 723 additions and 212 deletions

0
README
View File

BIN
images/bg_hr.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 B

BIN
images/blacktocat.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 463 B

BIN
images/body-bg.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

BIN
images/highlight-bg.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

BIN
images/hr.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 B

BIN
images/icon_download.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 216 B

BIN
images/octocat-icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 477 B

BIN
images/sprite_download.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
images/tar-gz-icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 741 B

BIN
images/zip-icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 735 B

51
index.html Normal file
View File

@ -0,0 +1,51 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<link href='https://fonts.googleapis.com/css?family=Chivo:900' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="stylesheets/stylesheet.css" media="screen">
<link rel="stylesheet" type="text/css" href="stylesheets/pygment_trac.css" media="screen">
<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print">
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<title>Swapwatch by tfmm</title>
</head>
<body>
<div id="container">
<div class="inner">
<header>
<h1>Swapwatch</h1>
<h2>swap, linux, server, cpanel</h2>
</header>
<section id="downloads" class="clearfix">
<a href="https://github.com/tfmm/swapwatch/zipball/master" id="download-zip" class="button"><span>Download .zip</span></a>
<a href="https://github.com/tfmm/swapwatch/tarball/master" id="download-tar-gz" class="button"><span>Download .tar.gz</span></a>
<a href="https://github.com/tfmm/swapwatch" id="view-on-github" class="button"><span>View on GitHub</span></a>
</section>
<hr>
<section id="main_content">
<h1>
<a id="swapwatch" class="anchor" href="#swapwatch" aria-hidden="true"><span class="octicon octicon-link"></span></a>Swapwatch</h1>
<p>This script was built originally to gather server statistics during periods of high load and swap usage, and email them to a helpdesk. It is built for cPanel servers.</p>
<p>I re-wrote the script when my employer switched over to using Zendesk, which butchered the original formatting of the emails sent by the script. </p>
</section>
<footer>
Swapwatch is maintained by <a href="https://github.com/tfmm">tfmm</a><br>
This page was generated by <a href="https://pages.github.com">GitHub Pages</a>. Tactile theme by <a href="https://twitter.com/jasonlong">Jason Long</a>.
</footer>
</div>
</div>
</body>
</html>

1
javascripts/main.js Normal file
View File

@ -0,0 +1 @@
console.log('This would be the main JS file.');

1
params.json Normal file
View File

@ -0,0 +1 @@
{"name":"Swapwatch","tagline":"swap, linux, server, cpanel","body":"# Swapwatch\r\n\r\nThis script was built originally to gather server statistics during periods of high load and swap usage, and email them to a helpdesk. It is built for cPanel servers.\r\n\r\nI re-wrote the script when my employer switched over to using Zendesk, which butchered the original formatting of the emails sent by the script. ","google":"","note":"Don't delete this file! It's used internally to help with page regeneration."}

228
stylesheets/print.css Normal file
View File

@ -0,0 +1,228 @@
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
padding: 0;
margin: 0;
font: inherit;
font-size: 100%;
vertical-align: baseline;
border: 0;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-spacing: 0;
border-collapse: collapse;
}
body {
font-family: 'Helvetica Neue', Helvetica, Arial, serif;
font-size: 13px;
line-height: 1.5;
color: #000;
}
a {
font-weight: bold;
color: #d5000d;
}
header {
padding-top: 35px;
padding-bottom: 10px;
}
header h1 {
font-size: 48px;
font-weight: bold;
line-height: 1.2;
color: #303030;
letter-spacing: -1px;
}
header h2 {
font-size: 24px;
font-weight: normal;
line-height: 1.3;
color: #aaa;
letter-spacing: -1px;
}
#downloads {
display: none;
}
#main_content {
padding-top: 20px;
}
code, pre {
margin-bottom: 30px;
font-family: Monaco, "Bitstream Vera Sans Mono", "Lucida Console", Terminal;
font-size: 12px;
color: #222;
}
code {
padding: 0 3px;
}
pre {
padding: 20px;
overflow: auto;
border: solid 1px #ddd;
}
pre code {
padding: 0;
}
ul, ol, dl {
margin-bottom: 20px;
}
/* COMMON STYLES */
table {
width: 100%;
border: 1px solid #ebebeb;
}
th {
font-weight: 500;
}
td {
font-weight: 300;
text-align: center;
border: 1px solid #ebebeb;
}
form {
padding: 20px;
background: #f2f2f2;
}
/* GENERAL ELEMENT TYPE STYLES */
h1 {
font-size: 2.8em;
}
h2 {
margin-bottom: 8px;
font-size: 22px;
font-weight: bold;
color: #303030;
}
h3 {
margin-bottom: 8px;
font-size: 18px;
font-weight: bold;
color: #d5000d;
}
h4 {
font-size: 16px;
font-weight: bold;
color: #303030;
}
h5 {
font-size: 1em;
color: #303030;
}
h6 {
font-size: .8em;
color: #303030;
}
p {
margin-bottom: 20px;
font-weight: 300;
}
a {
text-decoration: none;
}
p a {
font-weight: 400;
}
blockquote {
padding: 0 0 0 30px;
margin-bottom: 20px;
font-size: 1.6em;
border-left: 10px solid #e9e9e9;
}
ul li {
list-style-position: inside;
list-style: disc;
padding-left: 20px;
}
ol li {
list-style-position: inside;
list-style: decimal;
padding-left: 3px;
}
dl dd {
font-style: italic;
font-weight: 100;
}
footer {
padding-top: 20px;
padding-bottom: 30px;
margin-top: 40px;
font-size: 13px;
color: #aaa;
}
footer a {
color: #666;
}
/* MISC */
.clearfix:after {
display: block;
height: 0;
clear: both;
visibility: hidden;
content: '.';
}
.clearfix {display: inline-block;}
* html .clearfix {height: 1%;}
.clearfix {display: block;}

View File

@ -0,0 +1,69 @@
.highlight { background: #ffffff; }
.highlight .c { color: #999988; font-style: italic } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { font-weight: bold } /* Keyword */
.highlight .o { font-weight: bold } /* Operator */
.highlight .cm { color: #999988; font-style: italic } /* Comment.Multiline */
.highlight .cp { color: #999999; font-weight: bold } /* Comment.Preproc */
.highlight .c1 { color: #999988; font-style: italic } /* Comment.Single */
.highlight .cs { color: #999999; font-weight: bold; font-style: italic } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .gd .x { color: #000000; background-color: #ffaaaa } /* Generic.Deleted.Specific */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #999999 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .gi .x { color: #000000; background-color: #aaffaa } /* Generic.Inserted.Specific */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #800080; font-weight: bold; } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { font-weight: bold } /* Keyword.Constant */
.highlight .kd { font-weight: bold } /* Keyword.Declaration */
.highlight .kn { font-weight: bold } /* Keyword.Namespace */
.highlight .kp { font-weight: bold } /* Keyword.Pseudo */
.highlight .kr { font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #445588; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #009999 } /* Literal.Number */
.highlight .s { color: #d14 } /* Literal.String */
.highlight .na { color: #008080 } /* Name.Attribute */
.highlight .nb { color: #0086B3 } /* Name.Builtin */
.highlight .nc { color: #445588; font-weight: bold } /* Name.Class */
.highlight .no { color: #008080 } /* Name.Constant */
.highlight .ni { color: #800080 } /* Name.Entity */
.highlight .ne { color: #990000; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #990000; font-weight: bold } /* Name.Function */
.highlight .nn { color: #555555 } /* Name.Namespace */
.highlight .nt { color: #000080 } /* Name.Tag */
.highlight .nv { color: #008080 } /* Name.Variable */
.highlight .ow { font-weight: bold } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mf { color: #009999 } /* Literal.Number.Float */
.highlight .mh { color: #009999 } /* Literal.Number.Hex */
.highlight .mi { color: #009999 } /* Literal.Number.Integer */
.highlight .mo { color: #009999 } /* Literal.Number.Oct */
.highlight .sb { color: #d14 } /* Literal.String.Backtick */
.highlight .sc { color: #d14 } /* Literal.String.Char */
.highlight .sd { color: #d14 } /* Literal.String.Doc */
.highlight .s2 { color: #d14 } /* Literal.String.Double */
.highlight .se { color: #d14 } /* Literal.String.Escape */
.highlight .sh { color: #d14 } /* Literal.String.Heredoc */
.highlight .si { color: #d14 } /* Literal.String.Interpol */
.highlight .sx { color: #d14 } /* Literal.String.Other */
.highlight .sr { color: #009926 } /* Literal.String.Regex */
.highlight .s1 { color: #d14 } /* Literal.String.Single */
.highlight .ss { color: #990073 } /* Literal.String.Symbol */
.highlight .bp { color: #999999 } /* Name.Builtin.Pseudo */
.highlight .vc { color: #008080 } /* Name.Variable.Class */
.highlight .vg { color: #008080 } /* Name.Variable.Global */
.highlight .vi { color: #008080 } /* Name.Variable.Instance */
.highlight .il { color: #009999 } /* Literal.Number.Integer.Long */
.type-csharp .highlight .k { color: #0000FF }
.type-csharp .highlight .kt { color: #0000FF }
.type-csharp .highlight .nf { color: #000000; font-weight: normal }
.type-csharp .highlight .nc { color: #2B91AF }
.type-csharp .highlight .nn { color: #000000 }
.type-csharp .highlight .s { color: #A31515 }
.type-csharp .highlight .sc { color: #A31515 }

373
stylesheets/stylesheet.css Normal file
View File

@ -0,0 +1,373 @@
/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
*/
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
padding: 0;
margin: 0;
font: inherit;
font-size: 100%;
vertical-align: baseline;
border: 0;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-spacing: 0;
border-collapse: collapse;
}
/* LAYOUT STYLES */
body {
font-family: 'Helvetica Neue', Helvetica, Arial, serif;
font-size: 1em;
line-height: 1.5;
color: #6d6d6d;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.8);
background: #e7e7e7 url(../images/body-bg.png) 0 0 repeat;
}
a {
color: #d5000d;
}
a:hover {
color: #c5000c;
}
header {
padding-top: 35px;
padding-bottom: 25px;
}
header h1 {
font-family: 'Chivo', 'Helvetica Neue', Helvetica, Arial, serif;
font-size: 48px; font-weight: 900;
line-height: 1.2;
color: #303030;
letter-spacing: -1px;
}
header h2 {
font-size: 24px;
font-weight: normal;
line-height: 1.3;
color: #aaa;
letter-spacing: -1px;
}
#container {
min-height: 595px;
background: transparent url(../images/highlight-bg.jpg) 50% 0 no-repeat;
}
.inner {
width: 620px;
margin: 0 auto;
}
#container .inner img {
max-width: 100%;
}
#downloads {
margin-bottom: 40px;
}
a.button {
display: block;
float: left;
width: 179px;
padding: 12px 8px 12px 8px;
margin-right: 14px;
font-size: 15px;
font-weight: bold;
line-height: 25px;
color: #303030;
background: #fdfdfd; /* Old browsers */
background: -moz-linear-gradient(top, #fdfdfd 0%, #f2f2f2 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#fdfdfd), color-stop(100%,#f2f2f2)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #fdfdfd 0%,#f2f2f2 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #fdfdfd 0%,#f2f2f2 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #fdfdfd 0%,#f2f2f2 100%); /* IE10+ */
background: linear-gradient(top, #fdfdfd 0%,#f2f2f2 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#fdfdfd', endColorstr='#f2f2f2',GradientType=0 ); /* IE6-9 */
border-top: solid 1px #cbcbcb;
border-right: solid 1px #b7b7b7;
border-bottom: solid 1px #b3b3b3;
border-left: solid 1px #b7b7b7;
border-radius: 30px;
-webkit-box-shadow: 10px 10px 5px #888;
-moz-box-shadow: 10px 10px 5px #888;
box-shadow: 0px 1px 5px #e8e8e8;
-moz-border-radius: 30px;
-webkit-border-radius: 30px;
}
a.button:hover {
background: #fafafa; /* Old browsers */
background: -moz-linear-gradient(top, #fdfdfd 0%, #f6f6f6 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#fdfdfd), color-stop(100%,#f6f6f6)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #fdfdfd 0%,#f6f6f6 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #fdfdfd 0%,#f6f6f6 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #fdfdfd 0%,#f6f6f6 100%); /* IE10+ */
background: linear-gradient(top, #fdfdfd 0%,#f6f6f6, 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#fdfdfd', endColorstr='#f6f6f6',GradientType=0 ); /* IE6-9 */
border-top: solid 1px #b7b7b7;
border-right: solid 1px #b3b3b3;
border-bottom: solid 1px #b3b3b3;
border-left: solid 1px #b3b3b3;
}
a.button span {
display: block;
height: 23px;
padding-left: 50px;
}
#download-zip span {
background: transparent url(../images/zip-icon.png) 12px 50% no-repeat;
}
#download-tar-gz span {
background: transparent url(../images/tar-gz-icon.png) 12px 50% no-repeat;
}
#view-on-github span {
background: transparent url(../images/octocat-icon.png) 12px 50% no-repeat;
}
#view-on-github {
margin-right: 0;
}
code, pre {
margin-bottom: 30px;
font-family: Monaco, "Bitstream Vera Sans Mono", "Lucida Console", Terminal;
font-size: 14px;
color: #222;
}
code {
padding: 0 3px;
background-color: #f2f2f2;
border: solid 1px #ddd;
}
pre {
padding: 20px;
overflow: auto;
color: #f2f2f2;
text-shadow: none;
background: #303030;
}
pre code {
padding: 0;
color: #f2f2f2;
background-color: #303030;
border: none;
}
ul, ol, dl {
margin-bottom: 20px;
}
/* COMMON STYLES */
hr {
height: 1px;
padding-bottom: 1em;
margin-top: 1em;
line-height: 1px;
background: transparent url('../images/hr.png') 50% 0 no-repeat;
border: none;
}
strong {
font-weight: bold;
}
em {
font-style: italic;
}
table {
width: 100%;
border: 1px solid #ebebeb;
}
th {
font-weight: 500;
}
td {
font-weight: 300;
text-align: center;
border: 1px solid #ebebeb;
}
form {
padding: 20px;
background: #f2f2f2;
}
/* GENERAL ELEMENT TYPE STYLES */
h1 {
font-size: 32px;
}
h2 {
margin-bottom: 8px;
font-size: 22px;
font-weight: bold;
color: #303030;
}
h3 {
margin-bottom: 8px;
font-size: 18px;
font-weight: bold;
color: #d5000d;
}
h4 {
font-size: 16px;
font-weight: bold;
color: #303030;
}
h5 {
font-size: 1em;
color: #303030;
}
h6 {
font-size: .8em;
color: #303030;
}
p {
margin-bottom: 20px;
font-weight: 300;
}
a {
text-decoration: none;
}
p a {
font-weight: 400;
}
blockquote {
padding: 0 0 0 30px;
margin-bottom: 20px;
font-size: 1.6em;
border-left: 10px solid #e9e9e9;
}
ul li {
list-style-position: inside;
list-style: disc;
padding-left: 20px;
}
ol li {
list-style-position: inside;
list-style: decimal;
padding-left: 3px;
}
dl dt {
color: #303030;
}
footer {
padding-top: 20px;
padding-bottom: 30px;
margin-top: 40px;
font-size: 13px;
color: #aaa;
background: transparent url('../images/hr.png') 0 0 no-repeat;
}
footer a {
color: #666;
}
footer a:hover {
color: #444;
}
/* MISC */
.clearfix:after {
display: block;
height: 0;
clear: both;
visibility: hidden;
content: '.';
}
.clearfix {display: inline-block;}
* html .clearfix {height: 1%;}
.clearfix {display: block;}
/* #Media Queries
================================================== */
/* Smaller than standard 960 (devices and browsers) */
@media only screen and (max-width: 959px) { }
/* Tablet Portrait size to standard 960 (devices and browsers) */
@media only screen and (min-width: 768px) and (max-width: 959px) { }
/* All Mobile Sizes (devices and browser) */
@media only screen and (max-width: 767px) {
header {
padding-top: 10px;
padding-bottom: 10px;
}
#downloads {
margin-bottom: 25px;
}
#download-zip, #download-tar-gz {
display: none;
}
.inner {
width: 94%;
margin: 0 auto;
}
}
/* Mobile Landscape Size to Tablet Portrait (devices and browsers) */
@media only screen and (min-width: 480px) and (max-width: 767px) { }
/* Mobile Portrait Size to Mobile Landscape Size (devices and browsers) */
@media only screen and (max-width: 479px) { }

View File

@ -1,39 +0,0 @@
#!/bin/bash
#this script is run via cron and checks for updates to swapwatch
#unless the conf says not to
swapURL="http://DOMAIN.com/swapwatch.sh"
swapupdateURL="http://DOMAIN.com/swapupdate.sh"
APPDIR="/usr/local/sw/apps/swapwatch"
TMPDIR="/usr/local/sw/temp"
LOGDIR="/usr/local/sw/logs"
. /usr/local/sw/configs/swapwatch/swapwatch.conf
################################################################################
#if we are allowed to update
if [ $update = "yes" ]
then
#update swapwatch.sh
wget -O "$TMPDIR/swapwatch.tmp" $swapURL
#only overwrite if the dl worked
if [ "$?" -eq 0 ]
then
#just overwrite... probably with identical data. that's fine
mv -f "$TMPDIR/swapwatch.tmp" "$APPDIR/swapwatch.sh"
chmod +x "$APPDIR/swapwatch.sh"
fi
#update swapupdate.sh
wget -O "$TMPDIR/swapupdate.tmp" $swapupdateURL
if [ "$?" -eq 0 ]
then
mv -f "$TMPDIR/swapupdate.tmp" "$APPDIR/swapupdate.sh"
chmod +x "$APPDIR/swapupdate.sh"
#log
echo "[ $(date +%c) ] swapwatch checked for updates" >> $LOGDIR/swapwatch.log
else
echo "[ $(date +%c) ] swapwatch update failed" >> $LOGDIR/swapwatch.log
fi
fi
################################################################################

View File

@ -1,98 +0,0 @@
#!/bin/bash
#version number
#2.0.0
#rewrite by rlong
LOGDIR="/usr/local/sw/logs"
TMPFILE="/usr/local/sw/temp/swapwatch.results"
#Create and clear TMPFILE
touch $TMPFILE
cat /dev/null > $TMPFILE
#check if it's already running
if [ "$(ps ax | grep "$(basename $0)" -c )" -gt 4 ]
then
exit 1
else
#Find Current Load
load=$(awk '{print $1}' /proc/loadavg | cut -d. -f1)
#Find Current Free Swap
swap_free=$(grep SwapFree /proc/meminfo | awk '{print $2}')
#Find Swap Total
swap_total=$(grep SwapTotal /proc/meminfo | awk '{print $2}')
#get thresholds
source /usr/local/lp/configs/swapwatch/swapwatch.conf
#if that fails (file got rm'd?), use some defaults
if [ "$?" -ne 0 ]
then
loadthreshold=5
swapthreshold=524288
contact="support@DOMAIN.com"
fi
#check if we should run. either can trigger it
#make sure server has a swap partition > 0 too
if [[ "$load" -gt "$loadthreshold" || ("$swap_free" -lt "$swapthreshold" && "$swap_total" -ne 0) ]]
then
#Echo everything into a temp file, to help with ZD compatibility
echo "Load at $load" >> $TMPFILE
echo "" >> $TMPFILE
echo "Swap free at $swap_free" >> $TMPFILE
echo "" >> $TMPFILE
echo "Swap threshold is at $swapthreshold" >> $TMPFILE
echo "" >> $TMPFILE
echo "Apache Status" >> $TMPFILE
echo "" >> $TMPFILE
/usr/bin/lynx -dump -width 500 -connect_timeout=10 http://127.0.0.1/whm-server-status | grep -v ___ | grep -v OPTIONS >> $TMPFILE 2>&1
echo "" >> $TMPFILE
echo "" >> $TMPFILE
echo "Busiest Sites" >> $TMPFILE
echo "" >> $TMPFILE
/usr/bin/lynx -dump -width 500 -connect_timeout=5 http://127.0.0.1/whm-server-status | awk 'BEGIN { FS = " " } ; { print $12 }' | sed '/^$/d' | sort | uniq -c | sort -rn >> $TMPFILE 2>&1
echo "" >> $TMPFILE
echo "" >> $TMPFILE
echo "Netstat for Port 80 Abuse" >> $TMPFILE
echo "" >> $TMPFILE
netstat -tn 2>/dev/null | grep :80 | awk '{print $5}' | cut -f1 -d: | sort | uniq -c | sort -rn | head >> $TMPFILE 2>&1
echo "" >> $TMPFILE
echo "" >> $TMPFILE
echo "MySQL Process List" >> $TMPFILE
echo "" >> $TMPFILE
mysqladmin proc stat --verbose >> $TMPFILE 2>&1
echo "" >> $TMPFILE
echo "Process List" >> $TMPFILE
echo "" >> $TMPFILE
/bin/ps faux >> $TMPFILE 2>&1
echo "" >> $TMPFILE
echo "" >> $TMPFILE
echo "Processes sorted by RESIDENT memory" >> $TMPFILE
echo "" >> $TMPFILE
ps -e -o pid,rss,vsz,args --sort -rss,-vsz >> $TMPFILE 2>&1
#Send the email to the $contact address
subject="[LW] Swapwatch.sh on $(hostname)"
contents=$(cat $TMPFILE)
/usr/sbin/sendmail "$contact" <<EOF
subject:$subject
$contents
EOF
#restart apache to attempt to save server
/etc/init.d/httpd restart > /dev/null 2>&1
#log that swapwatch triggered
echo "[ $(date +%c) ] swapwatch triggered - Load $load - Free swap $swap_free" >> /usr/local/lp/logs/swapwatch.log
fi
#remove the tempfile
rm -f $TMPFILE
fi

View File

@ -1,75 +0,0 @@
#!/bin/bash
#this will create swapwatch.sh, swapwatch.conf, and crontab to run swapwatch.sh, and swapwatchupdater
###############################################################################
APPDIR="/usr/local/sw/apps/swapwatch"
LOGDIR="/usr/local/sw/logs"
CONFDIR="/usr/local/sw/configs/swapwatch"
swapurl="http://DOMAIN.COM/swapwatch.sh" #this will be appserv or nagilink
updateurl="http://DOMAIN.com/swapupdate.sh" #this will be appserv or nagilink
###############################################################################
#set default values, these can be changed in swapwatch.conf, but they are
#better than ridgid default values
#cpus is an easy count
cpus=$(grep processor /proc/cpuinfo -c)
#memory in kB
memory=$(grep MemTotal /proc/meminfo |awk '{print $2}')
#load trigger is 5 * CPUs
loadthresh=$( expr $cpus \* 5 )
#memory is: 2G thresh for 7+, 1G for 2+, .5G for less than that
G=1048576 #your a gigabyte
if [ $memory -gt $( expr 7 \* $G ) ]
then
swapthresh=$( expr 2 \* $G )
elif [ $memory -gt $( expr 2 \* $G ) ]
then
swapthresh=$G
else
swapthresh=$( expr $G / 2 )
fi
###############################################################################
##create the config file
#loadthreshold=5
#swapthreshold=1048576
#update=yes
mkdir -p "$CONFDIR"
cat > "$CONFDIR/swapwatch.conf" << EOM
loadthreshold=$loadthresh
swapthreshold=$swapthresh
update=yes
contact="support@liquidweb.com"
EOM
###############################################################################
#install
mkdir -p "$APPDIR"
echo "downloading swapwatch.sh"
wget -O "$APPDIR/swapwatch.sh" $swapurl
chmod +x "$APPDIR/swapwatch.sh"
echo "*/3 * * * * root $APPDIR/swapwatch.sh > /dev/null 2>&1" > /etc/cron.d/swapwatch
###############################################################################
##get update script
wget -O "$APPDIR/swapupdate.sh" $updateurl
chmod +x "$APPDIR/swapupdate.sh"
##check randomly once a week, to prevent tons of simmul conns to appserv
min=$[ ( $RANDOM % 60 ) ] #0-59
hour=$[ ( $RANDOM % 24 ) ] #0-23
dow=$[ ( $RANDOM % 7 ) ] #0-6
# $min $hour * * $dow
echo "$min $hour * * $dow root $APPDIR/swapupdate.sh > /dev/null 2>&1" > /etc/cron.d/swapupdate
###############################################################################
#log install
echo "[ $(date +%c) ] Swapwatch installed" >> $LOGDIR/swapwatch.log