def __init__(self): self.settings = settings # 加载设置 self.redis_obj = redis_conn(self.settings) # 获取redis连接实例 self.alert_counter_dict_key = settings.ALERT_COUNTER_REDIS_KEY # 报警计数字典key name alter_counter_dict = self.redis_obj.get(self.alert_counter_dict_key) if not alter_counter_dict: self.redis_obj.set(self.alert_counter_dict_key, json.dumps({})) '''alert_counter_dict = {
def __init__(self, redis_obj=None): self.settings = settings # 加载配置文件 self.config_update_interval = 120 # 每120s重新从数据库加载一次配置数据 self.config_last_loading_time = time.time() # 配置最后加载时间 self.host_alive_application_name = 'AgentPing' self.data_api = settings.DATA_API # 获取提交监控数据api self.key = settings.KEY # key self.key_name = settings.AUTH_KEY_NAME # key_name if redis_obj: # 没有传入redis连接就重新连接redis self.redis_obj = redis_obj else: self.redis_obj = redis_conn(settings)
from django.conf import settings from django.shortcuts import render, redirect from django.contrib.auth.decorators import login_required from django.db import transaction from django.core.exceptions import ValidationError from django.utils.translation import ugettext as _ from django.http import JsonResponse from monitor_data import models from monitor_web.forms import application_form from utils.pagination import Page from utils.log import Logger from utils.web_response import WebResponse from utils.redis_conn import redis_conn from utils.permissions import check_permission REDIS_OBJ = redis_conn(settings) @login_required @check_permission def application(request): """应用集视图""" template_id = request.GET.get('templateid') if template_id: template_id = int(template_id) else: template_id = 0 template_obj_list = models.Template.objects.all() template_obj = models.Template.objects.filter(id=template_id).first() current_page = request.GET.get("p", 1) current_page = int(current_page)