Как получить количество записей журнала за предыдущую минуту для графической иллюстрации. Пример для DHCPREQUESTS в журнале службы ISC DHCP. (Note: This translation is SEO optimized for an article about a terminal command life hack.)

DATE=`date +"%H:%M" --date '-1 min'`; egrep "\ $DATE\:..\ " /var/log/dhcpd.log |awk '/DHCPREQUEST/ {split($3,t,":"); printf("%02d:%02d\n",t[1],t[2]);}' |uniq -c;


The command uses the date command to get the current time, subtracts one minute from it, and stores it in the variable DATE. It then searches the /var/log/dhcpd.log file for lines containing the time stamp from one minute ago and the string «DHCPREQUEST». It uses awk to extract the hour and minute from the third column of each line and print them in the format HH:MM. The uniq -c command counts the number of occurrences of each unique time stamp.

This command can be useful for monitoring the rate of DHCPREQUESTS in the DHCP server log. An alternative approach could be using graphical log analysis tools like Kibana or Splunk. The command can be modified to search for other types of entries in the log file by changing the string «DHCPREQUEST» to the desired keyword.

Ответить

Ваш адрес email не будет опубликован. Обязательные поля помечены *