VPS访问IP统计

简单统计下VPS访问日志

正常日志300MB

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import org.scalatest.FunSuite

import java.nio.file.{Files, Paths}

test("normal log"){
import collection.JavaConverters._
val lines = Files.readAllLines(Paths.get("/var/logs/v2ray/access.log")).asScala.toSeq
val res = lines.filter(line => {
val str = line.split("(tcp:)|(udp:)")
str.length > 1
}
).map(line =>
(line.split("(tcp:)|(udp:)")(1).split(":")(0), 1)
).groupBy(_._1).mapValues(r => r.map(_._2).sum).toSeq.sortWith((x1, x2) => x2._2 > x1._2)
res.foreach(println)
}

错误日志3G

//TODO