Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 859085f

Browse files
committed
first commit
0 parents  commit 859085f

File tree

1,051 files changed

+141295
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,051 files changed

+141295
-0
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#create a new repository on the command line
2+
touch README.md
3+
git init
4+
git add README.md
5+
git commit -m "first commit"
6+
git remote add origin https://github.com/coolcoding/python_project.git
7+
git push -u origin master
8+
9+
#push an existing repository from the command line
10+
git remote add origin https://github.com/coolcoding/python_project.git
11+
git push -u origin master

monitor_web/getMonitorInfo.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!pyenv/bin/python
2+
import re
3+
import time
4+
import inspect
5+
import urllib2
6+
import json
7+
import socket
8+
9+
class getMonitorInfo():
10+
11+
def getTime(self):
12+
return str(int(time.time()) + 8 * 3600)
13+
14+
def getHost(self):
15+
return socket.gethostname()
16+
17+
def getMemTotal(self):
18+
with open('/proc/meminfo') as men_total:
19+
a = int(men_total.readline().split()[1])
20+
return a/1024
21+
22+
23+
def getMemFree(self,noBufferCache=True):
24+
if noBufferCache:
25+
with open('/proc/meminfo') as men_open:
26+
T = int(men_open.readline().split()[1])
27+
F = int(men_open.readline().split()[1])
28+
B = int(men_open.readline().split()[1])
29+
C = int(men_open.readline().split()[1])
30+
return (F+B+C)/1024
31+
else:
32+
with open('/proc/meminfo') as men_open:
33+
T = men_open.readline()
34+
return T/1024
35+
36+
def getLoadAvg(self):
37+
with open('/proc/loadavg') as loadavg_open:
38+
lo = loadavg_open.read().split()[:3]
39+
return ','.join(lo)
40+
41+
def getMemUsage(self,noBufferCache=True):
42+
if noBufferCache:
43+
with open('/proc/meminfo') as men_open:
44+
T = int(men_open.readline().split()[1])
45+
F = int(men_open.readline().split()[1])
46+
B = int(men_open.readline().split()[1])
47+
C = int(men_open.readline().split()[1])
48+
return (T-F-B-C)/1024
49+
else:
50+
with open('/proc/meminfo') as men_open:
51+
T = int(men_open.readline().split()[1])
52+
F = int(men_open.readline().split()[1])
53+
return (T-F)/1024
54+
55+
56+
57+
def runAllGet(self):
58+
data = {}
59+
for func in inspect.getmembers(self,predicate=inspect.ismethod):
60+
if func[0][:3] == 'get':
61+
data[func[0][3:]] = func[1]()
62+
63+
return data
64+
65+
if __name__ == '__main__':
66+
men = getMonitorInfo()
67+
while True:
68+
data = men.runAllGet()
69+
print data
70+
req = urllib2.Request("http://127.0.0.1:8888",json.dumps(data),{'Content-Type': 'application/json'})
71+
f = urllib2.urlopen(req)
72+
response = f.read()
73+
f.close()
74+
time.sleep(120)

monitor_web/log.file

Lines changed: 233 additions & 0 deletions
Large diffs are not rendered by default.

monitor_web/log.gile

Lines changed: 282 additions & 0 deletions
Large diffs are not rendered by default.

monitor_web/monitor.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!pyenv/bin/python
2+
import os
3+
import re
4+
import MySQLdb
5+
from flask import Flask,request,render_template
6+
import json
7+
8+
app = Flask(__name__)
9+
db = MySQLdb.connect(user='root',passwd='root',db='falcon',charset='utf8')
10+
db.autocommit(True)
11+
cur = db.cursor()
12+
13+
@app.route('/',methods=['GET','POST'])
14+
def index():
15+
if request.method == 'POST':
16+
data = request.json
17+
try:
18+
sql = "INSERT INTO `stat` (`host`,`mem_free`,`mem_usage`,`mem_total`,`load_avg`,`time`) VALUES('%s', '%d', '%d', '%d', '%s', '%d')" % (data['Host'], data['MemFree'], data['MemUsage'], data['MemTotal'], data['LoadAvg'], int(data['Time']))
19+
ret = cur.execute(sql)
20+
except MySQLdb.IntegrityError:
21+
pass
22+
return 'ok'
23+
else:
24+
return render_template('index.html')
25+
26+
@app.route('/data',methods=['GET'])
27+
def getData():
28+
cur.execute("select `time`,`mem_usage` from `stat`")
29+
one_res = [[i[0]*1000,i[1]] for i in cur.fetchall()]
30+
return "%s(%s);" % (request.args.get('callback'), json.dumps(one_res))
31+
32+
if __name__ == '__main__':
33+
app.run(host='0.0.0.0',port=8888,debug=True)

monitor_web/public/falcon.sql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CREATE TABLE `stat` (
2+
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
3+
`host` varchar(256) DEFAULT NULL,
4+
`mem_free` int(11) DEFAULT NULL,
5+
`mem_usage` int(11) DEFAULT NULL,
6+
`mem_total` int(11) DEFAULT NULL,
7+
`load_avg` varchar(128) DEFAULT NULL,
8+
`time` bigint(11) DEFAULT NULL,
9+
PRIMARY KEY (`id`),
10+
KEY `host` (`host`(255))
11+
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;

monitor_web/public/requirement.pip

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
mysql-python
2+
flask

monitor_web/pyenv/bin/activate

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# This file must be used with "source bin/activate" *from bash*
2+
# you cannot run it directly
3+
4+
deactivate () {
5+
unset pydoc
6+
7+
# reset old environment variables
8+
if [ -n "$_OLD_VIRTUAL_PATH" ] ; then
9+
PATH="$_OLD_VIRTUAL_PATH"
10+
export PATH
11+
unset _OLD_VIRTUAL_PATH
12+
fi
13+
if [ -n "$_OLD_VIRTUAL_PYTHONHOME" ] ; then
14+
PYTHONHOME="$_OLD_VIRTUAL_PYTHONHOME"
15+
export PYTHONHOME
16+
unset _OLD_VIRTUAL_PYTHONHOME
17+
fi
18+
19+
# This should detect bash and zsh, which have a hash command that must
20+
# be called to get it to forget past commands. Without forgetting
21+
# past commands the $PATH changes we made may not be respected
22+
if [ -n "$BASH" -o -n "$ZSH_VERSION" ] ; then
23+
hash -r 2>/dev/null
24+
fi
25+
26+
if [ -n "$_OLD_VIRTUAL_PS1" ] ; then
27+
PS1="$_OLD_VIRTUAL_PS1"
28+
export PS1
29+
unset _OLD_VIRTUAL_PS1
30+
fi
31+
32+
unset VIRTUAL_ENV
33+
if [ ! "$1" = "nondestructive" ] ; then
34+
# Self destruct!
35+
unset -f deactivate
36+
fi
37+
}
38+
39+
# unset irrelevant variables
40+
deactivate nondestructive
41+
42+
VIRTUAL_ENV="/root/git/pyrepo/pyenv"
43+
export VIRTUAL_ENV
44+
45+
_OLD_VIRTUAL_PATH="$PATH"
46+
PATH="$VIRTUAL_ENV/bin:$PATH"
47+
export PATH
48+
49+
# unset PYTHONHOME if set
50+
# this will fail if PYTHONHOME is set to the empty string (which is bad anyway)
51+
# could use `if (set -u; : $PYTHONHOME) ;` in bash
52+
if [ -n "$PYTHONHOME" ] ; then
53+
_OLD_VIRTUAL_PYTHONHOME="$PYTHONHOME"
54+
unset PYTHONHOME
55+
fi
56+
57+
if [ -z "$VIRTUAL_ENV_DISABLE_PROMPT" ] ; then
58+
_OLD_VIRTUAL_PS1="$PS1"
59+
if [ "x" != x ] ; then
60+
PS1="$PS1"
61+
else
62+
if [ "`basename \"$VIRTUAL_ENV\"`" = "__" ] ; then
63+
# special case for Aspen magic directories
64+
# see http://www.zetadev.com/software/aspen/
65+
PS1="[`basename \`dirname \"$VIRTUAL_ENV\"\``] $PS1"
66+
else
67+
PS1="(`basename \"$VIRTUAL_ENV\"`)$PS1"
68+
fi
69+
fi
70+
export PS1
71+
fi
72+
73+
alias pydoc="python -m pydoc"
74+
75+
# This should detect bash and zsh, which have a hash command that must
76+
# be called to get it to forget past commands. Without forgetting
77+
# past commands the $PATH changes we made may not be respected
78+
if [ -n "$BASH" -o -n "$ZSH_VERSION" ] ; then
79+
hash -r 2>/dev/null
80+
fi

monitor_web/pyenv/bin/activate.csh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# This file must be used with "source bin/activate.csh" *from csh*.
2+
# You cannot run it directly.
3+
# Created by Davide Di Blasi <[email protected]>.
4+
5+
alias deactivate 'test $?_OLD_VIRTUAL_PATH != 0 && setenv PATH "$_OLD_VIRTUAL_PATH" && unset _OLD_VIRTUAL_PATH; rehash; test $?_OLD_VIRTUAL_PROMPT != 0 && set prompt="$_OLD_VIRTUAL_PROMPT" && unset _OLD_VIRTUAL_PROMPT; unsetenv VIRTUAL_ENV; test "\!:*" != "nondestructive" && unalias deactivate && unalias pydoc'
6+
7+
# Unset irrelevant variables.
8+
deactivate nondestructive
9+
10+
setenv VIRTUAL_ENV "/root/git/pyrepo/pyenv"
11+
12+
set _OLD_VIRTUAL_PATH="$PATH"
13+
setenv PATH "$VIRTUAL_ENV/bin:$PATH"
14+
15+
16+
17+
if ("" != "") then
18+
set env_name = ""
19+
else
20+
if (`basename "$VIRTUAL_ENV"` == "__") then
21+
# special case for Aspen magic directories
22+
# see http://www.zetadev.com/software/aspen/
23+
set env_name = `basename \`dirname "$VIRTUAL_ENV"\``
24+
else
25+
set env_name = `basename "$VIRTUAL_ENV"`
26+
endif
27+
endif
28+
29+
# Could be in a non-interactive environment,
30+
# in which case, $prompt is undefined and we wouldn't
31+
# care about the prompt anyway.
32+
if ( $?prompt ) then
33+
set _OLD_VIRTUAL_PROMPT="$prompt"
34+
set prompt = "[$env_name] $prompt"
35+
endif
36+
37+
unset env_name
38+
39+
alias pydoc python -m pydoc
40+
41+
rehash
42+

monitor_web/pyenv/bin/activate.fish

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# This file must be used with "source bin/activate.fish" *from fish* (http://fishshell.com)
2+
# you cannot run it directly
3+
4+
function deactivate -d "Exit virtualenv and return to normal shell environment"
5+
# reset old environment variables
6+
if test -n "$_OLD_VIRTUAL_PATH"
7+
set -gx PATH $_OLD_VIRTUAL_PATH
8+
set -e _OLD_VIRTUAL_PATH
9+
end
10+
if test -n "$_OLD_VIRTUAL_PYTHONHOME"
11+
set -gx PYTHONHOME $_OLD_VIRTUAL_PYTHONHOME
12+
set -e _OLD_VIRTUAL_PYTHONHOME
13+
end
14+
15+
if test -n "$_OLD_FISH_PROMPT_OVERRIDE"
16+
# set an empty local fish_function_path, so fish_prompt doesn't automatically reload
17+
set -l fish_function_path
18+
# erase the virtualenv's fish_prompt function, and restore the original
19+
functions -e fish_prompt
20+
functions -c _old_fish_prompt fish_prompt
21+
functions -e _old_fish_prompt
22+
set -e _OLD_FISH_PROMPT_OVERRIDE
23+
end
24+
25+
set -e VIRTUAL_ENV
26+
if test "$argv[1]" != "nondestructive"
27+
# Self destruct!
28+
functions -e deactivate
29+
end
30+
end
31+
32+
# unset irrelevant variables
33+
deactivate nondestructive
34+
35+
set -gx VIRTUAL_ENV "/root/git/pyrepo/pyenv"
36+
37+
set -gx _OLD_VIRTUAL_PATH $PATH
38+
set -gx PATH "$VIRTUAL_ENV/bin" $PATH
39+
40+
# unset PYTHONHOME if set
41+
if set -q PYTHONHOME
42+
set -gx _OLD_VIRTUAL_PYTHONHOME $PYTHONHOME
43+
set -e PYTHONHOME
44+
end
45+
46+
if test -z "$VIRTUAL_ENV_DISABLE_PROMPT"
47+
# fish uses a function instead of an env var to generate the prompt.
48+
49+
# copy the current fish_prompt function as the function _old_fish_prompt
50+
functions -c fish_prompt _old_fish_prompt
51+
52+
# with the original prompt function copied, we can override with our own.
53+
function fish_prompt
54+
# Prompt override?
55+
if test -n ""
56+
printf "%s%s" "" (set_color normal)
57+
_old_fish_prompt
58+
return
59+
end
60+
# ...Otherwise, prepend env
61+
set -l _checkbase (basename "$VIRTUAL_ENV")
62+
if test $_checkbase = "__"
63+
# special case for Aspen magic directories
64+
# see http://www.zetadev.com/software/aspen/
65+
printf "%s[%s]%s " (set_color -b blue white) (basename (dirname "$VIRTUAL_ENV")) (set_color normal)
66+
_old_fish_prompt
67+
else
68+
printf "%s(%s)%s" (set_color -b blue white) (basename "$VIRTUAL_ENV") (set_color normal)
69+
_old_fish_prompt
70+
end
71+
end
72+
73+
set -gx _OLD_FISH_PROMPT_OVERRIDE "$VIRTUAL_ENV"
74+
end

0 commit comments

Comments
 (0)