zoukankan      html  css  js  c++  java
  • Log解析

    nginx

    
    public class NginxLogAll
    {
        [PrimaryKey,AutoIncrement]
        public long Id { get; set; }
        public string Ip { get; set; }
        public string User { get; set; }
        public string LogTime { get; set; }
        public string Method { get; set; }
        public string HttpUrl { get; set; }
        public string HttpCode { get; set; }
        public int HttpBytes { get; set; }
        public string HttpRef { get; set; }
        public string UserAgent { get; set; }
        public override string ToString()
        {
            return
                $"('{Ip}','{User}','{LogTime}','{Method}',{PostgreSqlDialectProvider.Instance.GetQuotedValue(HttpUrl)},'{HttpCode}',{HttpBytes},{PostgreSqlDialectProvider.Instance.GetQuotedValue(HttpRef)},{PostgreSqlDialectProvider.Instance.GetQuotedValue(UserAgent)})";
        }
    }
    private static string NginxLogPattern = "^(?\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) - (?.*?) (?\[.*?\+\d{4}\]) "(?.*?) (?.*) HTTP/\d\.\d" (?\d+) (?\d+) "(?.*)" "(?.*)"";
    
    int i;
    while (!sr.EndOfStream)
    {
        i++;
        string line = sr.ReadLine();
        if (line != null)
        {
            var m = Regex.Match(line, NginxLogPattern);
            if (m.Success)
            {
                var a=new NginxLogAll
                {
                    Ip = m.Groups["Ip"].Value,
                    User = m.Groups["User"].Value,
                    LogTime = FormatDate(m.Groups["LogTime"].Value[1..21]),
                    Method = m.Groups["Method"].Value,
                    HttpUrl = m.Groups["HttpUrl"].Value,
                    HttpCode = m.Groups["HttpCode"].Value,
                    HttpBytes = int.Parse(m.Groups["HttpBytes"].Value),
                    HttpRef = m.Groups["HttpRef"].Value,
                    UserAgent = m.Groups["UserAgent"].Value,
                };
                if (
                    a.HttpUrl.EndsWith(".jpg")||
                    a.HttpUrl.EndsWith(".png")||
                    a.HttpUrl.EndsWith(".js")||
                    a.HttpUrl.EndsWith(".css")||
                    a.HttpUrl.EndsWith(".ttf")||
                    a.HttpUrl.EndsWith(".gif")||
                    a.HttpUrl.EndsWith(".ico")
                    )
                {
                    continue;
                }
                //TODO:
            }else{
                //TODO:
            }
        }
    }
    
    
  • 相关阅读:
    2019阿里系电子书合集来了!
    FTP主动模式和被动模式的区别
    Vsftpd运行的两种模式-xinetd运行模式和 standalone模式
    Logstash组件详解(input、codec、filter、output)
    Docker入门-笔记-1
    K8S命令-Kubectl 命令大全
    Nginx-HTTP Strict Transport Security(HSTS)
    IPV6技术笔记(剖析IPv4toIPv6)
    一个交换机到底能带几台摄像头?结合生产经验咱们来分析!
    ELK查询命令详解
  • 原文地址:https://www.cnblogs.com/yzpopulation/p/13408164.html
Copyright © 2011-2022 走看看