Nginx log logs stored to MongoDB do video click Leaderboard

Source: Internet
Author: User

#!/bin/bash# this script run at 00:00# the nginx logs path#  Zhengyansheng time:2014-08-27# qq 467754239logs_path= "/usr/local/nginx/logs/" access_dir= "/usr/ Local/nginx/logs/insert_mongodb "mkdir -p ${logs_path}$ (date -d " Yesterday " +"%Y ")/$ ( date -d  "Yesterday"  + "%m" + "%d") mv  $logs _path/access_hktv.log ${logs_path}$ (date  -d  "Yesterday"  + "%Y")/$ (date -d  "Yesterday"  + "%m" + "%d")/access_$ (date -d  " Yesterday " +"%y%m%d%h%m "). logcat ${logs_path}$ (date -d " Yesterday " +"%Y ")/$ (date  -d  "Yesterday"  + "%m" + "%d")/access_$ (date -d  "Yesterday"  + "%y%m%d%h%m"). Log  >  $logs _path/access_mongo.log/usr/local/nginx/sbin/nginx -s reloadcat  $logs _path/ Access_mongo.log | while read line;docookieid= ' echo  $line  |awk -F  ' uid = "  ' {print $2} '  | awk  ' {print $1} '  | grep -v  ' ^$ ' ' ip= ' echo  $line  |  awk  ' {print $3} ' appkey= ' echo  $line  | awk  ' {print $1} ' visidate= ' echo  $line  | awk  ' {print $2} '  | awk -F  ' ['   ' {print $2} ' Browsertype= ' echo  $line  | awk -F  "\" "  ' {print $6} ' refer= ' echo  $line  | awk -F  "\" "  ' {print $4} ' os= ' echo  $line  | awk -F " \ " "  ' {print $6} '  |awk  ' {print $1} ' videoid= ' echo  $line  | gawk -f '? Id= '   ' { print $2 } '  |cut -d ' & '  -f1 ' sql= ' Db.user.visit.data.insert ({ BrowserType: ' $browsertype ', Cookieid: ' $cookieId ', AppKey: ' $appKey ', IP: ' $ip ' ', os: ' $os ' ', Referer: ' $refer ', VideoID: ' $videoID ', visitdate:isodate (' $visidate ')}) "echo " $sql " >>  $logs _path/nginx_log_ mongo.txtdonecat  $logs _path/nginx_log_mongo.txt | mongo 192.168.0.100:27017/hktv_tv -u hktv -p  cdvcloud#123mv  $logs _path/nginx_log_mongo.txt  $logs _path/nginx_log_mongo_bak.txt

Mission Plan! The log is cut, then stored in the MongoDB database,

*/5 * * * */bin/bash/usr/local/nginx/logs/nginx_mongo.sh

This script has been optimized several times and the thread has run successfully! If there are deficiencies please also point out, thank you


This article is from the "Zheng" blog, make sure to keep this source http://467754239.blog.51cto.com/4878013/1548026

Nginx log logs stored to MongoDB do video click Leaderboard

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.