First put the environment in place.
Django configuration no longer speaks of it.
Look at the log format, and what we need to do, an example
218.104.141.167 - - [26/jan/ 2014:06:46:30 +0800] "get /main/index.php?cmd=checkmob&useage=regist&mob=15377587416% 20alt= http/1.1 " 200 55 " http://www.zhasini.ml/ddos.php?hm=15377587416&c=281 " " mozilla/5.0 (windows nt 6.1; wow64; trident/7.0; rv:11.0) like Gecko " 90021175.41.23.251 - - [26/Jan/2014:06:46:31 +0800] "get /main/index.php? cmd=checkmob&useage=regist&mob=13276444989 http/1.1 " 200 55 "/http www.zhanimei.ga/mini/index.php?hm=13276444989&c=50689 " " mozilla/4.0 (compatible; msie 7.0; windows nt 5.2; trident/4.0; .net clr 1.1.4322; .net clr 2.0.50727; .net clr 3.0.4506.2152; .net clr 3.5.30729) " 65882
Here are 2 logs, is the log of my site, you can see I need to count my site is exactly how many numbers are directly input domain name access, how much is from other places referred come over, probably statistics.
How to count I will not say, directly on the result
d={' 1.htldxhzj.duapp.com ': 9398, ' gtxapi.cdn.duapp.com ': 79496, ' www.xxx.com ': 2477070, ' www.baidu.com ': 1465, ' Www.bing.com ': 777, ' www.aaa.com ': 1113101, ' www.ccc.net.cn ': 922, ' www.zhanimei.ga ': 29847, ' www.zhanimei.ml ': 40155, ' Www.zhasini.ml ': 373436}
I only took the first few, and organized it into a dictionary.
Start drawing
From pandas import Series,dataframeimport Matplotlib.pyplot as Pltplt.figure (figsize= (8,6), dpi=80) ts = Series (d) Ts.plot (kind= ' Barh ') plt.savefig ('/var/www/jastme/static/images/log.png ')
HTML to write the IMG call, the above code into the Django view, when you visit the page, you can get the picture.
Django+pandas+matplotlib log analysis, drawing, page display