|
|
|
@ -7,9 +7,20 @@ timestamp_prev=$(date -d '1 min ago' +'%s') |
|
|
|
|
lf_now=$(date +'%d/%b/%Y:%H:%M:' -d @$timestamp_now) |
|
|
|
|
lf_prev=$(date +'%d/%b/%Y:%H:%M:' -d @$timestamp_prev) |
|
|
|
|
|
|
|
|
|
# tail the logs and get a count of viewers per streamer |
|
|
|
|
# tail the logs and get a count of viewers per streamer. the pipeline is: |
|
|
|
|
# lines with hls or dash urls |
|
|
|
|
# between the start and end times |
|
|
|
|
# print the ip and stream stream .m3u8/mpd |
|
|
|
|
# sort them |
|
|
|
|
# uniq to deduplicate |
|
|
|
|
# print just the stream names now |
|
|
|
|
# cut off the .m3u8/mpd so we have just the name |
|
|
|
|
# sort again (because ip is removed) |
|
|
|
|
# uniq with counts this time |
|
|
|
|
# remove non alphanumeric or space |
|
|
|
|
# remove leading whitespace from uniq |
|
|
|
|
viewers=`tail -n 10000 /var/log/nginx/access.log \ |
|
|
|
|
| grep -E 'GET /(hls|dash)/[a-z0-9]+.m3u8' \ |
|
|
|
|
| grep -E 'GET /(hls|dash)/[a-z0-9]+.(m3u8|mpd)' \ |
|
|
|
|
| grep -E "${lf_now}|${lf_prev}" \ |
|
|
|
|
| awk '{print $3 " " $7}' \ |
|
|
|
|
| sort \ |
|
|
|
@ -30,4 +41,4 @@ do |
|
|
|
|
done <<< "$viewers" |
|
|
|
|
|
|
|
|
|
# delete any not updated viewer files (no longer live) |
|
|
|
|
find /var/www/stream/viewers/* -mmin +0.5 -exec rm {} \; |
|
|
|
|
bash -c 'find /var/www/stream/viewers/*.txt -mmin +0.5 -exec rm {} \;' |
|
|
|
|