
관련 없는 행이 제거된 로그 파일(auth.log)이 있습니다. 시간/일당 라인을 플롯에 집계하고 싶습니다. 즉, 동일한 시간 또는 날짜 내에 있는 각 라인이 플롯에서 하나의 틱으로 집계된다는 의미입니다.
기능을 조사해 봤는데 계속 막히네요.
이것이 지금까지 가지고 있는 것이지만 로그 파일의 각 줄에 "변수"가 있는 경우에만 작동합니다.
#!/usr/bin/env gnuplot
set terminal png size 1200,800
set output "graph.png"
set title "Breakin Attempts"
set key top right box
set style data lines
set border 3
set grid
set pointsize 3
set xlabel "Number of breakin attempts"
set xtics nomirror
set xdata time
set timefmt "%b %d %H:%M:%S"
set format x "%m/%d"
set ylabel "Time"
set ytics nomirror
plot "pc1.log" using 1:4 title "PC1" linecolor rgb "red", \
"pc2.log" using 1:4 title "PC2" linecolor rgb "blue", \
"pc3.log" using 1:4 title "PC3" linecolor rgb "green"
다음은 데이터의 예입니다.
Sep 18 11:26:30 root 60.191.36.196
Sep 18 11:26:34 root 60.191.36.196
Sep 18 11:26:37 root 60.191.36.196
Sep 18 19:21:31 root 198.56.193.74
Sep 18 19:21:33 root 198.56.193.74
이 경우 19:21:xx에 있는 두 항목은 2의 1틱이 되고 11:26:xx에 있는 3개의 항목은 3의 틱이 됩니다.
답변1
시간 단위(귀하의 예에서는 분)당 항목 수를 원한다고 가정합니다. gnuplot이 이런 방식으로 줄을 셀 수 있는지 여부는 모르겠습니다. awk
대신 데이터를 누적하기 위해 (또는 귀하에게 편리한 언어)를 사용하겠습니다 . 다음과 같은 작업이 수행됩니다.
스크립트 = '{시간 = $3; gsub(/:[0-9][0-9]$/, "", 시간); date=sprintf("%s %s %s", $1, $2, time)} date==last{count++} date!=last{print date, count; 개수=0}'
파이프(파일) = sprintf("< awk '%s' %s", 스크립트, 파일) 플롯 파이프("pc1.log") 제목 "PC1"
답변2
귀하의 질문은 그다지 명확하지 않습니다. Hannes로서 나는 당신이 특정 날짜에 해당하는 줄 수를 표시하고 싶다고 가정합니다.
Gnuplot은 이에 적합하지 않으므로 파일을 사전 처리하는 것이 좋습니다.
그러나 gnuplot 3.4 이상에서는 카운터를 전역 변수로 프로그래밍할 수 있으므로 다음과 같은 결과를 얻을 수 있습니다.
currentx=1/0
currentn=0
increaseandreturn(returnvalue)=(currentn=currentn+1,returnvalue)
startnewxandreturn(x,returnvalue)=(currentx=x,currentn=0,returnvalue)
count(x)=((x==currentx)?increaseandreturn(1/0):startnewxandreturn(x,currentn))
plot "file.gdat" using ($1-1):(count($1)) with points
정렬된 파일에 대해서만 작동하며(비연속 항목이 아닌 연속 항목을 추가함) currentx
첫 번째 값을 포함해야 합니다(또는 더 많은 테스트를 삽입해야 함). 날짜의 경우 스크립트를 약간 조정해야 합니다.
예를 들어 다음과 같이 gnuplot에 의해 생성된 파일을 사용하여 테스트할 수 있습니다.
set table "file.gdat"
set parametric
plot [0:20] floor(exp(t/10)),t
unset table