django使用日志和中间件模块应用

基于邮件通知的服务监控和告警系统

  • 主要功能点:

    • 配置专用日志格式记录耗时

      • 日志格式:

        'simple':{
        	'format':'%(asctimme)s %(message)s'
        }
        
      • 处理器

        'statistics_handler':{
        	'level':'DEBUG',
                  'class':'logging.handlers.RotatingFileHandler',
                    'filename':os.path.join(LOG_DIR,'backend.log')
                  'maxBytes':'1024*1024*1024' # class参数如果日志大小超了会新建文件
                  'backupCount':5 #备份数
                  'formatter':'simple',
                    'encoding':'utf-8'
        }
        
      • 日志实例

        ’statistics':{
        	'handlers':['statistics_handler'],
        	'level':'DEBUG'
        }
        
    • 编写请求耗时统计功能的中间件

      1. 获取日志实例
      2. 业务逻辑功能编写
        • request时间,路径,response时间
    • 配置定时任务统计指标并通过邮件发送

      1. 分析日志的任务函数业务逻辑文件
        • 请求时间的最大值,最小值,平均值
      2. 邮件发送的配置
      3. 配置django-crontab
posted @ 2019-07-28 19:14  Jimmyhe  阅读(565)  评论(0编辑  收藏  举报