分析ngnix日志文件的开发程序记录

package com.school.statistics;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.RandomAccessFile;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.school.dao.CourseContentMapper;
import com.school.dao.StatisticsDurationCuMapper;
import com.school.dao.StatisticsDurationMapper;
import com.school.domain.CourseContent;
import com.school.domain.CourseContentJson;
import com.school.domain.CourseContentJson.Lecture;
import com.school.domain.CourseContentJson.Section;
import com.school.domain.StatisticsDuration;
import com.school.domain.StatisticsDurationCu;

public class AnalysisDurationLogs implements Runnable {

    private static ApplicationContext applicationContext = null;

    public static StatisticsDurationMapper statisticsDurationMapper;// 明细统计

    public static StatisticsDurationCuMapper statisticsDurationCuMapper;// 根据课程统计

    public static CourseContentMapper courseContentMapper;// 课时内容

    public static Integer sleepTime = 1 * 60 * 1000;// 时间(多少时间执行一次)

    public static String logFilePath = "/data/nginx/logs/vlms_access.log";

    public static String seekFilePath = "/data/nginx/logs/";

    // 构造函数
    public AnalysisDurationLogs() {
        if (applicationContext == null) {
            applicationContext = new ClassPathXmlApplicationContext(new String[] { "applicationContext-resources.xml",
                    "classpath:applicationContext-dao.xml" });
        }
        statisticsDurationMapper = (StatisticsDurationMapper) applicationContext.getBean("statisticsDurationMapper");
        statisticsDurationCuMapper = (StatisticsDurationCuMapper) applicationContext
                .getBean("statisticsDurationCuMapper");
        courseContentMapper = (CourseContentMapper) applicationContext.getBean("courseContentMapper");
    }

    // 实现run方法
    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName());
        try {
            startFunction(sleepTime);// 启动10秒执行一次
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public static void main(String[] args) throws IOException {
        System.out.println("-------统计分析----------");
        AnalysisDurationLogs a1 = new AnalysisDurationLogs();
        Thread t1 = new Thread(a1);
        t1.start();
        // startFunction();
    }

    /**
     * 取出读取标记,进行文件读取分析-记录读取标记
     */
    private static void startFunction(int stopTime) throws IOException, FileNotFoundException {
        while (true) {
            try {
                Thread.sleep(stopTime);
                int row = 0;

                System.out.println("--------------------------------kai----------------------------------");
                System.out.println("---------------------------------------------------------------------");

                SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
                String datefile = sdf.format(new Date());
                String lineMarkFilePath = seekFilePath + datefile + "seek.txt";
                File file = new File(lineMarkFilePath);
                if (!file.exists()) {
                    file.createNewFile();
                }
                BufferedReader bufr = new BufferedReader(new InputStreamReader(new FileInputStream(lineMarkFilePath)));
                String rowStr = null;
                if ((rowStr = bufr.readLine()) != null) {
                    if (StringUtils.isNotBlank(rowStr) || "".equals(rowStr)) {
                        // row=Integer.valueOf(rowStr).intValue();
                        row = Integer.parseInt(rowStr.trim());
                        // row = bufr.read();
                    }

                }
                bufr.close();

                System.out.println("--------r1--------" + row);

                // 每隔10秒去分析一下日志文件
                Integer markline = getLogs(row);

                // FileOutputStream(lineMarkFilePath,false)//false为覆盖文本,true为追加文本
                BufferedWriter bufw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(lineMarkFilePath,
                        false), "UTF-8"));
                System.out.println("--------r2--------" + markline);
                String lineStr = null;
                lineStr = markline.toString();
                if ((lineStr) != null) {
                    bufw.write(lineStr);
                    // bufw.newLine();///换行
                    bufw.flush();// 刷新
                }
                bufw.close();

                // 筛选数据
                System.out.println("--------综合表--------");
                selectDurationData();

            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * 打开分析nginx文件
     */
    public static int getLogs(Integer row) throws FileNotFoundException, IOException {
        RandomAccessFile raf = new RandomAccessFile(logFilePath, "rw");
        raf.seek(row);// 移动文件指针位置
        String line = null;
        int i = row;
        Map<String, StatisticsDuration> map = new HashMap<String, StatisticsDuration>();
        while ((line = raf.readLine()) != null) {
            // i++;
            // System.out.println("----count------"+line);
            Pattern p = Pattern.compile("((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)");
            Matcher m = p.matcher(line);
            String ipv4 = "";
            if (m.find()) {
                // 找到ipv4//使用if而不使用while母的是只找第一个就结束寻找,因为ip放在前面,
                ipv4 = m.group();
                // System.out.println("get-----" +m.group());
            }

            String timeStr = "";
            timeStr = line.substring(line.indexOf("[") + 1, line.lastIndexOf("]"));
            String time = "";
            Pattern pt = Pattern.compile("(\\d{2})/([^&]*)/\\d{4}:\\d{2}:\\d{2}:\\d{2}");
            Matcher mt = pt.matcher(timeStr);
            while (mt.find()) {
                // 找到时间串
                time = mt.group();
                SimpleDateFormat sdf = new SimpleDateFormat("d/MMM/yyyy:K:m:s", Locale.ENGLISH);
                SimpleDateFormat sdfnew = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                Date d2 = null;
                try {
                    d2 = sdf.parse(time.trim());
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                time = sdfnew.format(d2);
            }

            i = (int) raf.getFilePointer();// 记录当前读取位置
            // 获取参数
            String pid = getParameterRex(line, "pid");
            String schoolID = getParameterRex(line, "schoolID");
            String courseID = getParameterRex(line, "courseID");

            String lectureID = getParameterRex(line, "lectureID");
            // String sectionID=getParameterRex(line, "sectionID");//参数正则获取法
            String sectionID = getSectionId(lectureID, 2);// 截取获取法(基于传过来的参数不正确)

            String userID = getParameterRex(line, "userID");
            String duration = getParameterRex(line, "duration");
            String Browser = getParameterRex(line, "Browser");
            String terminal = getParameterRex(line, "terminal");

            System.out.println(i + "---t---" + time + "---ip---" + ipv4 + "---pid----" + pid + "----s---" + schoolID
                    + "---c---" + courseID + "---s---" + sectionID + "---l---" + lectureID + "---u---" + userID
                    + "---b---" + Browser + "---t---terminal+----d----" + duration);
            StatisticsDuration statisticsDuration = new StatisticsDuration();
            if (StringUtils.isNotBlank(pid.trim())) {
                statisticsDuration.setPid(pid);
                statisticsDuration.setSchoolId(schoolID);
                statisticsDuration.setCourseId(courseID);
                statisticsDuration.setSectionId(sectionID);
                statisticsDuration.setLectureId(lectureID);
                statisticsDuration.setUserId(userID);
                statisticsDuration.setIpv4(ipv4);
                if (StringUtils.isNotBlank(duration.trim())) {
                    statisticsDuration.setDuration(Integer.parseInt(duration.trim()));
                }

                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                Date date = null;
                try {
                    date = sdf.parse(time);
                } catch (ParseException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                statisticsDuration.setDateEnd(date);
                statisticsDuration.setBrowser(Browser);
                statisticsDuration.setTerminal(terminal);
                map.put(pid, statisticsDuration);// 存进map集合
            }
        }
        raf.close();

        // 调用存进数据库
        System.out.println("-------insert明细表--------");
        insertData(map);

        map.clear();

        return i;
    }

    /**
     * 存进数据库 //入库操作
     */
    private static void insertData(Map<String, StatisticsDuration> map) {
        if (map.size() > 0) {
            Set<String> keyi = map.keySet();
            java.util.Iterator<String> it = keyi.iterator();
            while (it.hasNext()) {
                String key = it.next();
                // System.out.println(dbv.getPid());
                StatisticsDuration statisticsDuration = map.get(key);
                StatisticsDuration selectSD = statisticsDurationMapper.selectByPrimaryKey(statisticsDuration.getPid());// /查询是否存在
                if (selectSD != null) {
                    // 理论上不会执行
                    statisticsDurationMapper.updateByPrimaryKeySelective(statisticsDuration);// 更新操作
                } else {
                    statisticsDurationMapper.insertSelective(statisticsDuration);// 入库操作
                }
            }
        }
    }

    /**
     * 提取请求里的参数
     */
    public static String getParameterRex(String str, String name) {
        String rex = "(?:^|\\?|&)" + name + "=([^&]*)(?:&|$)";
        Pattern p = Pattern.compile(rex);
        Matcher m = p.matcher(str);
        String param = "";
        while (m.find()) {
            // 找到相应的参数
            param = m.group();
            // System.out.println("value-----" +m.group());
            if (StringUtils.isNotBlank(param)) {
                try {
                    param = param.substring(param.indexOf("=") + 1, param.lastIndexOf("&"));
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    param = "";
                }
            }
        }
        return param;
    }

    /**
     * 从lectureId里截取sectionId
     */
    private static String getSectionId(String lectureId, int index) {
        try {
            String[] ss = lectureId.split("\\.");
            StringBuffer sb = new StringBuffer();
            String result = "";
            for (int i = 0; i < 2; i++) {
                sb.append(ss[i]).append(".");
            }
            result = sb.toString();
            result = result.substring(0, result.length() - 2);
            return result;
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return "";
        }
    }

    /**
     * 筛选数据统计
     */
    public static void selectDurationData() {

        // 今天的日期
        // SimpleDateFormat sdfOne = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat sdfTwo = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
        String today = sdfTwo.format(new Date());
        // System.out.println("--------------"+today);

        // 明天的日期
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DAY_OF_YEAR, 1);
        Date date = calendar.getTime();
        String tomorrow = sdfTwo.format(date);
        // System.out.println("------m-------"+tomorrow);

        // 筛选当天的数据(根据传过去的时间),筛选明细表的数据,去插入综合表
        List<StatisticsDurationCu> list = statisticsDurationMapper.selectDurationCu(today, tomorrow);
        // System.out.println("------zzzsi------"+list.size());
        if (list.size() > 0) {
            for (int i = 0; i < list.size(); i++) {

                String schoolId = list.get(i).getSchoolId();
                String courseId = list.get(i).getCourseId();
                String lectureId = list.get(i).getLectureId();
                String userId = list.get(i).getUserId();
                String sectionId = list.get(i).getSectionId();
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
                String onlyDate = sdf.format(list.get(i).getDate());

                String sectionTitle = "";
                String lectureTitle = "";
                boolean insertMark = false;// 预防lecture_id不存在的情况,存在可以insert

                // 获取章节标题、与课时标题
                // CourseContentExample exampleC = new CourseContentExample();
                // exampleC.createCriteria().andSchoolIdEqualTo(schoolId).andCourseIdEqualTo(courseId);
                // List<CourseContent> courseContentList = courseContentMapper.selectByExample(exampleC);
                CourseContent courseContent = courseContentMapper.selectByPrimaryKey(courseId);

                if (courseContent != null) {
                    CourseContentJson ccj = courseContent.getCourseContentJson();
                    List<Section> sections = ccj.getSections();// 获取章节列表
                    if (sections.size() > 0) {
                        // 遍历章节
                        for (int j = 0; j < sections.size(); j++) {
                            if (insertMark) {
                                break;// 找到了课时title就没必要继续遍历其他的section
                            }
                            Section s = sections.get(j);
                            System.out.println("------secIdccc-------" + s.getSectionId());
                            // 因为拖动排序,没有章节概念,所以找课时标题,只能从所有的章节去找
                            List<Lecture> lecList = sections.get(j).getLectures();// 获取到课时列表
                            if (lecList.size() > 0) {
                                for (int k = 0; k < lecList.size(); k++) {
                                    if (lectureId.equals(lecList.get(k).getLectureId())) {
                                        sectionTitle = sections.get(j).getTitle();// 找到不一定是所需要的章节,并获取章节的标题
                                        lectureTitle = lecList.get(k).getTitle();
                                        insertMark = true;
                                        System.out.print("-------找到le-------" + lectureTitle);
                                        break;
                                    }
                                }
                                System.out.println("--------lecList结束--------");
                            }
                        }
                    }
                }

                // /insertMark为true表示在课程内容表(course_content)存在相应的lecture_id,
                if (insertMark) {
                    // 先去查询,该记录存不存在
                    List<StatisticsDurationCu> sdcu = statisticsDurationCuMapper.selectExistDurationCu(onlyDate,
                            schoolId, courseId, userId, lectureId);
                    if (sdcu.size() > 0) {
                        // 存在该条数据,去更新该条数据
                        StatisticsDurationCu statisticsDurationCu = sdcu.get(0);
                        float durationS = list.get(i).getDuration();
                        float durationH = durationS / 3600;
                        statisticsDurationCu.setDuration(durationH);// 新的时长替换旧的时长
                        statisticsDurationCu.setCount(list.get(i).getCount());
                        statisticsDurationCu.setSectionTitle(sectionTitle);
                        statisticsDurationCu.setLectureTitle(lectureTitle);
                        // 根据Id是唯一的,去更新时长、次数
                        statisticsDurationCuMapper.updateDurationCountToday(statisticsDurationCu);
                        System.out.println("-----updatezzzzz---------");
                    } else {
                        // 不存在该条数据,
                        StatisticsDurationCu sdc = new StatisticsDurationCu();
                        sdc = list.get(i);
                        float durationS = sdc.getDuration();
                        float durationH = durationS / 3600;
                        sdc.setDuration(durationH);
                        sdc.setSectionTitle(sectionTitle);
                        sdc.setLectureTitle(lectureTitle);
                        statisticsDurationCuMapper.insertSelective(sdc);
                        System.out.println("-----insertzzzz---------");
                    }
                }

            }
        }

    }

}

遇到故障重新找数据(根据时间)

package com.school.statistics;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.school.dao.CourseContentMapper;
import com.school.dao.StatisticsDurationCuMapper;
import com.school.dao.StatisticsDurationMapper;
import com.school.domain.CourseContent;
import com.school.domain.CourseContentJson;
import com.school.domain.CourseContentJson.Lecture;
import com.school.domain.CourseContentJson.Section;
import com.school.domain.StatisticsDurationCu;

/**
 * 遇到故障了,根据传过来的日期去筛选数据,insert到综合表
 */
public class FailureAndInsert {

    private static ApplicationContext applicationContext = null;

    public static StatisticsDurationMapper statisticsDurationMapper;// 明细统计

    public static StatisticsDurationCuMapper statisticsDurationCuMapper;// 根据课程统计

    public static CourseContentMapper courseContentMapper;// 课时内容

    public static String breakDate = "2014-10-10 00:00:00";// 故障日期

    // 构造函数
    public FailureAndInsert() {

    }

    public static void main(String[] args) {
        BreakDownInsert(breakDate);
        System.out.println("-------------------程序运行结束可以终止------------------------------");
    }

    /**
     * 遇到故障了,根据传过来的日期去筛选数据,insert到综合表
     */
    public static void BreakDownInsert(String breakDate) {

        if (applicationContext == null) {
            applicationContext = new ClassPathXmlApplicationContext(new String[] { "applicationContext-resources.xml",
                    "applicationContext-business.xml", "classpath:applicationContext-dao.xml" });
        }
        statisticsDurationMapper = (StatisticsDurationMapper) applicationContext.getBean("statisticsDurationMapper");
        statisticsDurationCuMapper = (StatisticsDurationCuMapper) applicationContext
                .getBean("statisticsDurationCuMapper");
        courseContentMapper = (CourseContentMapper) applicationContext.getBean("courseContentMapper");

        // 今天的日期
        // SimpleDateFormat sdfOne = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat sdfTwo = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
        Date todayStr = null;
        try {
            todayStr = sdfTwo.parse(breakDate);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        String today = sdfTwo.format(todayStr);
        System.out.println("------t--------" + today);

        // 明天的日期
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(todayStr);
        int day = calendar.get(Calendar.DATE);
        calendar.set(Calendar.DATE, day + 1);
        String tomorrow = new SimpleDateFormat("yyyy-MM-dd 00:00:00").format(calendar.getTime());
        System.out.println("------m-------" + tomorrow);

        // 筛选当天的数据(根据传过去的时间),筛选明细表的数据,去插入综合表
        List<StatisticsDurationCu> list = statisticsDurationMapper.selectDurationCu(today, tomorrow);
        System.out.println("------zzzsi------" + list.size());

        if (list.size() > 0) {
            for (Integer i = 0; i < list.size(); i++) {
                String schoolId = list.get(i).getSchoolId();
                String courseId = list.get(i).getCourseId();
                String lectureId = list.get(i).getLectureId();
                String userId = list.get(i).getUserId();
                String sectionId = list.get(i).getSectionId();

                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
                String onlyDate = sdf.format(list.get(i).getDate());

                String sectionTitle = "";
                String lectureTitle = "";
                boolean insertMark = false;// 预防lecture_id不存在的情况,存在可以insert

                System.out.print("-----m-------" + i);
                System.out.print("-----secid-------" + sectionId);
                System.out.println("-----lecid-------" + lectureId);

                // 获取章节标题、与课时标题
                // CourseContentExample exampleC = new CourseContentExample();
                // exampleC.createCriteria().andSchoolIdEqualTo(schoolId).andCourseIdEqualTo(courseId);
                // List<CourseContent> courseContentList = courseContentMapper.selectByExample(exampleC);
                CourseContent courseContent = courseContentMapper.selectByPrimaryKey(courseId);

                if (courseContent != null) {
                    CourseContentJson ccj = courseContent.getCourseContentJson();
                    List<Section> sections = ccj.getSections();// 获取章节列表
                    if (sections.size() > 0) {
                        // 遍历章节
                        for (int j = 0; j < sections.size(); j++) {
                            if (insertMark) {
                                break;// 找到了课时title就没必要继续遍历其他的section
                            }
                            Section s = sections.get(j);
                            System.out.println("------secIdccc-------" + s.getSectionId());
                            // 因为拖动排序,没有章节概念,所以找课时标题,只能从所有的章节去找
                            List<Lecture> lecList = sections.get(j).getLectures();// 获取到课时列表
                            if (lecList.size() > 0) {
                                for (int k = 0; k < lecList.size(); k++) {
                                    if (lectureId.equals(lecList.get(k).getLectureId())) {
                                        sectionTitle = sections.get(j).getTitle();// 找到不一定是所需要的章节,并获取章节的标题
                                        lectureTitle = lecList.get(k).getTitle();
                                        insertMark = true;
                                        System.out.print("-------le找到-------" + lectureTitle);
                                        break;
                                    }
                                }
                                System.out.println("--------lecList结束--------");
                            }
                        }
                    }
                }
                // ///--end

                System.out.println("---only------" + onlyDate);
                // /insertMark为true表示在课程内容表(course_content)存在相应的lecture_id,
                if (insertMark) {
                    // 先去查询,该记录存不存在
                    List<StatisticsDurationCu> sdcu = statisticsDurationCuMapper.selectExistDurationCu(onlyDate,
                            schoolId, courseId, userId, lectureId);
                    if (sdcu.size() > 0) {
                        // 存在该条数据,去更新该条数据
                        StatisticsDurationCu statisticsDurationCu = sdcu.get(0);
                        float durationS = list.get(i).getDuration();
                        float durationH = durationS / 3600;
                        statisticsDurationCu.setDuration(durationH);// 新的时长替换旧的时长
                        statisticsDurationCu.setCount(list.get(i).getCount());
                        statisticsDurationCu.setSectionTitle(sectionTitle);
                        statisticsDurationCu.setLectureTitle(lectureTitle);
                        // 根据Id是唯一的,去更新时长、次数
                        statisticsDurationCuMapper.updateDurationCountToday(statisticsDurationCu);
                        System.out.println("-----updatezzzzz---------");
                    } else {
                        // 不存在该条数据,
                        StatisticsDurationCu sdc = new StatisticsDurationCu();
                        sdc = list.get(i);
                        float durationS = sdc.getDuration();
                        float durationH = durationS / 3600;
                        sdc.setDuration(durationH);
                        sdc.setSectionTitle(sectionTitle);
                        sdc.setLectureTitle(lectureTitle);
                        statisticsDurationCuMapper.insertSelective(sdc);
                        System.out.println("-----insertzzzz---------");
                    }
                }

            }
        }
    }

}

某时间以前的删除记录

package com.school.statistics;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.school.dao.StatisticsDurationCuMapper;
import com.school.dao.StatisticsDurationMapper;
import com.school.domain.StatisticsDurationExample;

/*
 * 删除明细表的数据
 */
public class DeleteDetailData {

    private static ApplicationContext applicationContext = null;

    public static StatisticsDurationMapper statisticsDurationMapper;// 明细统计

    public static StatisticsDurationCuMapper statisticsDurationCuMapper;// 根据课程统计

    public static String breakDate = "2012-09-18 00:00:00";// 故障日期

    // 构造函数
    public DeleteDetailData() {

    }

    public static void main(String[] args) {
        deleteData(breakDate);
    }

    /**
     * 删除明细表的数据
     */
    public static void deleteData(String breakDate) {
        if (applicationContext == null) {
            applicationContext = new ClassPathXmlApplicationContext(new String[] { "applicationContext-resources.xml",
                    "classpath:applicationContext-dao.xml" });
        }
        statisticsDurationMapper = (StatisticsDurationMapper) applicationContext.getBean("statisticsDurationMapper");
        statisticsDurationCuMapper = (StatisticsDurationCuMapper) applicationContext
                .getBean("statisticsDurationCuMapper");

        // 把用户输入的日期转成 java 日期类
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
        Date deleteTime = null;
        try {
            deleteTime = df.parse(breakDate);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        // 删除小于这个时间的记录---明细表
        StatisticsDurationExample example = new StatisticsDurationExample();
        example.createCriteria().andDateEndLessThanOrEqualTo(deleteTime);
        statisticsDurationMapper.deleteByExample(example);
    }

}
时间: 2024-10-13 03:13:48

分析ngnix日志文件的开发程序记录的相关文章

awstats分析nginx日志文件

awstats分析nginx日志文件,将生成的结果(为txt文件)保存在/var/www/awstats目录下,通过apche来 显示生成的结果. nginx的域名为:www.a.com:80 LogFile="/usr/local/mybin/nginx/logs/access.log"  #nginx的日志文件路径 DirData="/var/www/awstats/" #awstats生成结果的保存路径 SiteDomain="www.a.com&q

如何分析网站日志文件

很多新手站长对于如何分析网站日志文件一筹莫展,打开.log日志文件看到的只有密密麻麻的数字和字母,细看能看出是什么含义,但是想要系统科学的去进行分析太耗时间,这时一般只能借助于第三方日志分析软件,而下面介绍一种不需要下载日志分析软件即可很有效率地分析log文件的方法: 步骤一:下载你的网站日志文件并打开,选择编辑替换功能,将空格替换成英文逗号: 步骤二:打开替换好的日志文件选择文件另存为,保存类型改成所有文件,文件名后缀为csv,比如log.csv,然后点击保存: 步骤三:新建一个excel表格

在Linux上使用logwatch分析监控日志文件

原文:http://seanlook.com/2014/08/23/linux-logwatch-usage/ 1. 介绍 在维护Linux服务器时,经常需要查看系统中各种服务的日志,以检查服务器的运行状态. 如登陆历史.邮件.软件安装等日志.系统管理员一个个去检查会十分不方便:且大多时候,这会是一种被动的检查,即只有在发现系统运行异常时才会想到去查看 日志以获取异常的信息.那么如何主动.集中的分析这些日志,并产生报告,定时发送给管理员就会显得十分重要. logwatch 是一款用 Perl 语

使用Mtools分析MongoDB日志文件

一 Mtools介绍 mtools是一组用来解析和过滤MongoDB日志文件的脚本.mtools包括以下几个工具: mlogfilter    可以根据时间切割日志文件,过滤慢查询等 mloginfo      返回日志文件信息,比如开始和结束时间等 mplotqueries   对日志文件进行视图展现 mlogvis      创建一个自定义html文件交互式展现 mlaunch      快速搭建本地测试环境,包括复制集合分片系统 mtools是用python写的,需要python2.6或者

分析IIS日志文件

"D:\Program Files (x86)\Log Parser 2.2\logparser.exe" "SELECT * FROM 'D:\u_ex160405.log' to MyMVC_WebLog" -i:IISW3C -o:SQL -oConnString:"Driver={SQL Server};server=RPBPC7OICVYFNTK\MSSQL2008R2;database=MyTestDb;Integrated Security=

centos下nohup日志文件过大问题解决记录

[出处]   https://blog.csdn.net/shawnhu007/article/details/50971084 [思考]   服务器项目运行几月后,日志文件大小达到G级别,导致查看过慢,占用磁盘空间,无法删除 [行动/反馈]  上网查看相同类型解决方法,引用上方连接博主的思路,先在这里感谢博主的分享 以下为本人的场景及实现: 通过在centos中设置定时任务,每天的凌晨零点零分进行日志分割操作,把当前日志文件分割备份后,清空当前的nohup日志文件. shell脚本代码 定时任

Nginx 分析access日志文件

Nginx Access Log日志统计分析常用命令 IP相关统计 统计IP访问量 awk '{print $1}' access.log | sort -n | uniq | wc -l 查看某一时间段的IP访问量(4-5点) grep "07/Apr/2017:0[4-5]" access.log | awk '{print $1}' | sort | uniq -c| sort -nr | wc -l 查看访问最频繁的前100个IP awk '{print $1}' access

ELK 分析nginx日志文件

注意:修改配置后建议重新创建index 1.nginx 日志文件格式 log_format elk "$http_clientip | $http_x_forwarded_for | $time_local | $request | $status | $body_bytes_sent | "  "$request_body | $content_length | $http_referer | $http_user_agent | "  "$http_c

从Apache的日志文件收集和提供统计数据(一个Python插件架构的简单实现)

从Apache的日志文件收集和提供统计数据 这一章我们将介绍基于插件程序的架构和实现.作为例子,我们将构建一个分析Apache服务器log文件的框架.这一次我们不再使用单片机的方式来创建,而是改为采用模块化的方式.一旦我们有了一个基本框架,我们就可以为它创建一个插件.这个插件可以基于请求者的地理位置执行分析. 程序的结构和功能 在数据维护和统计收集领域,很难有一个单一的应用程序可以适合多个用户的需求.让我们以分析Apache的web服务器日志文件为例.web服务器接受到的每一个请求都被记录在日志