【強(qiáng)悍】d3.js讓ssh暴破次數(shù)可視化
本博文出自51CTO博客老徐_kevin博主,有任何問題請進(jìn)入博主頁面互動(dòng)討論!
博文地址:http://laoxu.blog.51cto.com/4120547/1618400
一臺(tái)做手機(jī)app應(yīng)用的服務(wù)器在某云上,很好奇如果沒有修改ssh端口的情況下,每天會(huì)被暴力破解多少次呢?帶著這個(gè)疑問,查看一下/var/log/messages的日志,grep一下里面多少含有"Failed"的日志記錄。。。
由于messages日志會(huì)有l(wèi)ogrotate,所以:
- grep "^Mar 1" /var/log/messages* | grep "Failed" | wc -l
分別得到從本月1號(hào)到7號(hào)的暴力破解次數(shù),分別是:
- 2015-03-07,4126
- 2015-03-06,33499
- 2015-03-05,80096
- 2015-03-04,70208
- 2015-03-03,79273
- 2015-03-02,40995
- 2015-03-01,11845
除了7號(hào)比較安靜點(diǎn),平均每天5、6萬次,看來黑客每天都很忙碌。。。
雖然數(shù)據(jù)比較少,但是看起來比較枯燥,看不出趨勢,讓數(shù)據(jù)可視化,那就用d3.js吧,上代碼。。。
d3的庫文件直接從github上獲得即可。
index.html
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <link rel="stylesheet" href="css/style.css" media="screen" type="text/css" />
- <title>SSH爆破次數(shù)</title>
- </head>
- <body>
- <center><div id="container"></div></center>
- <script type="text/javascript" src="js/d3.v3.js"></script>
- <script type="text/javascript" src="js/index.js"></script>
- </body>
- </html>
style.css
- #container {
- background:#eee; //容器的背景色
- width:600px;
- height:270px;
- }
- body { font: 12px Arial;}
- path {
- stroke: mediumturquoise; //曲線的顏色,可以在chrome的控制臺(tái)里使用stroke TAB后調(diào)試
- stroke-width: 2;
- fill: none;
- }
- .axis path,
- .axis line {
- fill: none;
- stroke: gray;
- stroke-width: 1;
- shape-rendering: crispEdges;
- }
data.csv
- date,close
- 2015-03-07,4126
- 2015-03-06,33499
- 2015-03-05,80096
- 2015-03-04,70208
- 2015-03-03,79273
- 2015-03-02,40995
- 2015-03-01,11845
index.js
- var margin = {top: 30, right: 30, bottom: 50, left: 80},
- width = 600 - margin.left - margin.right,
- height = 270 - margin.top - margin.bottom;
- var parseDate = d3.time.format("%Y-%m-%d").parse;
- var x = d3.time.scale().range([0, width]);
- var y = d3.scale.linear().range([height, 0]);
- var xAxis = d3.svg.axis().scale(x)
- .orient("bottom").ticks(7)
- .tickFormat(d3.time.format("%b/%d"));
- var yAxis = d3.svg.axis().scale(y)
- .orient("left").ticks(10);
- var valueline = d3.svg.line()
- .x(function(d) { return x(d.date); })
- .y(function(d) { return y(d.close); })
- .interpolate("basis");
- var svg = d3.select("#container")
- .append("svg")
- .attr("width", width + margin.left + margin.right)
- .attr("height", height + margin.top + margin.bottom)
- .append("g")
- .attr("transform","translate(" + margin.left +"," + margin.top + ")");
- // Get the data
- d3.csv("data/data.csv", function(error, data) {
- data.forEach(function(d) {
- d.date = parseDate(d.date);
- d.close = +d.close;
- });
- // Scale the range of the data
- x.domain(d3.extent(data, function(d) { return d.date; }));
- y.domain([0, d3.max(data, function(d) { return d.close; })]);
- svg.append("path") // Add the valueline path.
- .attr("class", "line")
- .attr("d", valueline(data));
- svg.append("g") // Add the X Axis
- .attr("class", "x axis")
- .attr("transform", "translate(0," + height + ")")
- .call(xAxis);
- svg.append("text") // text label for the x axis
- .attr("x", 265 )
- .attr("y", 238 )
- .style("text-anchor", "middle")
- .text("日期");
- svg.append("g") // Add the Y Axis
- .attr("class", "y axis")
- .call(yAxis);
- svg.append("text")
- .attr("transform", "rotate(-90)")
- .attr("y",0 - margin.left)
- .attr("x",0 - (height / 2))
- .attr("dy", "1em")
- .style("text-anchor", "middle")
- .text("SSH爆破次數(shù)");
- });
以上就是一個(gè)頁面的代碼。訪問頁面看看d3.js的數(shù)據(jù)可視化效果吧。。。
效果如何?d3還是不錯(cuò)的吧?還有很多更c(diǎn)ool的效果。。。Keep trying。。