コード例 #1
0
 def add(cls,msg):
     _ip = msg.get('ip')
     _cpu = msg.get('cpu')
     _ram = msg.get('ram')
     _time = msg.get('time')
     sql = 'insert into performs(ip,cpu,ram,time) values(%s,%s,%s,%s)'
     MySQLconnection.execute_sql1(sql,args=(_ip,_cpu,_ram,_time),fetch=False)
コード例 #2
0
ファイル: views.py プロジェクト: jirh/actual-17-homework
def log_status():
    sql = 'select distinct status from accesslog'
    count, status_list = MySQLconnection.execute_sql1(sql)
    status_list = [i[0] for i in status_list]
    status_dict = {
        i: MySQLconnection.execute_sql1(
            'select count(*) from accesslog where status=%s', (i, ))[1][0][0]
        for i in status_list
    }
    total = reduce(lambda x, y: x + y, status_dict.values())
    data = [['%s' % k, round(v / total, 3) * 100]
            for k, v in status_dict.items()]
    return render_template('/public/index_body.html', data=data)
コード例 #3
0
def get_user():
    columns = ("id","username","password","job","age")
    sql = 'select * from user'
    user_list = []
    # count, rt_list = execute_sql(sql,fetch=True)
    count, rt_list = MySQLconnection.execute_sql(sql,fetch=True)
    for user in rt_list:
        user_list.append(dict(zip(columns,user)))
    return user_list
コード例 #4
0
 def get_list(cls,ip):
     _sql = 'select cpu,ram,time from performs where ip=%s and time >= %s order by time asc'
     _args = (ip,time.strftime( '%Y-%m-%d %H:%M:%S',time.localtime(time.time() - 3600)))
     _count, _rt_list = MySQLconnection.execute_sql1(_sql,args=_args,fetch=True)
     datetime_list = []
     cpu_list = []
     ram_list = []
     # return _rt_list
     for _cpu, _ram, _time in _rt_list:
         cpu_list.append(_cpu)
         ram_list.append(_ram)
         datetime_list.append(_time.strftime('%H:%M:%S'))
     return datetime_list,cpu_list,ram_list
コード例 #5
0
def has_alarm(ip):
    # CPU&RAM 大于80%
    _sql = 'select cpu,ram from performs where ip=%s order by time desc limit %s'
    _args = (ip, CNT)
    count, rt_list = MySQLconnection.execute_sql1(sql=_sql,
                                                  args=_args,
                                                  fetch=True)
    cpu = False
    ram = False
    for _cpu, _ram in rt_list:
        if _cpu > CPU_PERCENT:
            cpu = True
        if _ram > RAM_PERCENT:
            ram = True
    return cpu, ram
コード例 #6
0
def vilidate_find(username,passwd,age,job):
    if not username:
        return True, u'用户名不能为空'
    sql = "select username from user where username=%s"
    args = (username,)
    # count, rt_list = execute_sql(sql, args, fetch=True)
    count, rt_list = MySQLconnection.execute_sql1(sql, args, fetch=True)
    if count != 0:
        return True, u'用户名已存在'
    if not passwd:
        return True, u'密码不能为空'
    if not age:
        return True, u'年龄不能为空'
    if not job:
        return True, u'职务不能为空'
    return False, ''
コード例 #7
0
def add_user(username,passwd,age,job):
    sql = 'insert into user(username,password,job,age) values(%s,md5(%s),%s,%s)'
    args = (username,passwd,job,age)
    # count, rt_list = execute_sql(sql,args=args,fetch=False)
    count,rt_list = MySQLconnection.execute_sql(sql,args=args,fetch=False)
    return count != 0
コード例 #8
0
def vilidate_login(username,password):
    sql = 'select * from user where username=%s and password=md5(%s)'
    args = (username,password)
    # count, rt_list = execute_sql(sql,args,fetch=True)
    count, rt_list = MySQLconnection.execute_sql(sql,args,fetch=True)
    return count != 0