django实现Linux运维管理平台
老早之前就想做一个运维管理平台的项目了,一直没沉下来去做,上半年的时候毕设选择了这个课题,想着逼自己一把,不管做出来的怎么样,先把它搞起来.....
django的工作原理
KioL1mFg1XgRVIFAAEB4OzOk8A451.png-h_50
文字说明
(1)Web服务器收到用户的http请求。
(2) Django通过URL控制器来判断对应的视图(Vie)函数从而对http请求做处理。
(3)视图函数调用相应的模型来存取数据、调用相应的模板把数据展示出来。
(4)视图函数最终返回一个http的响应给Web服务器。
(5)Web服务器把接收到的响应数据发给浏览器,浏览器把响应渲染展示出来。
我个人独自开发项目的功能模块图
Kiom1mFhALQHkYMAAA61YqJWfU698.png-h_50
我在django项目下面创建了多个app,分别负责独立的功能。
一、用户注册登录
视图
# coding:utf-8
from django.shortcuts import render,render_to_response
import os
import mands
from django.http import HttpResponse,HttpResponseRedirect
from .models import monitors,User,question,Experience
from django import forms
from django.template import RequestContext
from django.contrib import auth
from cmdb.models import Information
from ebssh.forms import ebsshform
#用户注册
def register(request):
if request.method == 'POST':
username = request.POST['username']
passord = request.POST['passord']
try:
registusername = User.objects.filter(username=username).get().username
registered="已经注册了"
return render(request,'register.html',{'registusername':registusername,'registered':registered})
except:
registAdd = User.objects.create(username=username,passord=passord)
Registered="注册成功!!!"
return render(request,'register.html',{'registAdd':registAdd,'Registered':Registered})
else:
return render(request,'register.html')
return render(request,'register.html')
#用户登录
def login(request):
if request.method == 'POST':
username = request.POST.get("username","")
passord = request.POST.get("passord","")
user = User.objects.filter(username__exact = username,passord__exact = passord)
if user: #如果用户匹配成功
response = HttpResponseRedirect('/index/') #重定向到index
response.set_cookie('cookie_username',username,36) #设置cookie
return response #把index页面输出
else:
nopass="用户名或者密码输入错误" #没有匹配成功
return render(request,'login.html',{'nopass':nopass})
return HttpResponse('yes')
return render(request,'login.html')
#用户注销登录
def logout(request):
return render(request,'login.html')
response.delete_cookie('cookie_username') #删除cookie_username对应的用户的cookie
return response
模板templates
登录页面
{% load staticfiles %}
Linux运维管理平台登录页面
{{ nopass }}{{ deltxt }}
Copyright © 付炜超Linux运维管理系统登录界面
注册页面
KioL1mFhy3xMH8AAAV4TBGhInY454.png-h_50
登录页面代码
Linux运维管理平台注册页面
Copyright © 付炜超运维管理系统的注册页
注册页面
KioL1mFiJnBzxtyAAW3OIedjgM006.png-h_50
二、 首页
视图(vies)
def index(request):
date=mands.getoutput('date')
area=mands.getoutput('sh /home/zqxt_form2/monitor/ip.sh 2>/dev/null ')
eather=mands.getoutput('python /home/zqxt_form2/monitor/eather.py ')
username = request.cookieS.get('cookie_username','')
if username:
return render_to_response('index.html',{'date': date,'area': area,'eather':eather,'username':username})
else:
return render(request,'login.html')
模板(templates)
{% load staticfiles %}
付炜超的运维管理平台
linux运维管理平台
45%
新订单数
1019
今天的访问数
1012
新增用户
$450
一天的收入
July 2015 SMTWTFS282930123456789101112131415161718192021222324252627282930311
Lorem Ipsum liked random
Lorem Ipsum is simply dummy
8:03
simply random liked passages
Lorem Ipsum is simply dummy
8:03
standard chunk liked model
Lorem Ipsum is simply dummy
8:03
perspiciatis liked donating
Lorem Ipsum is simply dummy
8:03
Broser Stats
- Google Chrome12%
- Firefox15%
- Inter Explorer18%
- Safari17%
- Opera10%
- Mobile & tablet14%
- Others5%
服务器资源信息 资源 Total free
cpu(%)
100%
70%
内存
10M
10%
磁盘
30G
5%
Sap
1000M
3%
service
install
status
httpd
已安装
未启动
mysql
已安装
启动成功
tomcat
未安装
未启动
sendmail
已安装
已启动
网络
1M
磁盘
20GB
cpu
1核
内存
1GB
{{ area }}
°F °C
`eather`°
{{ date}}
Copyright 付炜超的运维管理平台
首页效果图
Kiom1mFioyzxFP5AAFJ7Imtbgc799.png-h_50
Kiom1mFisuB9337AACKRaDOjpk725.png-h_50
三 、服务器资产信息存入和前端展示
模型(models)
from django.db import models
class Information(models.Model):
name = models.CharField(max_length=30)
privateip = models.GenericIPAddressField()
publicip = models.GenericIPAddressField()
use = models.TextField()
zoneid = models.CharField(max_length=30)
cpu = models.CharField(max_length=50)
memory = models.CharField(max_length=50)
datadisk = models.CharField(max_length=30)
time = models.DateTimeField()
def __unicode__(self):
return self.name
admin
from django.contrib import admin
from .models import Information
class InformationAdmin(admin.ModelAdmin):
list_display = ('name','privateip','publicip','use','zoneid','cpu','memory','datadisk')
admin.site.register(Information,InformationAdmin)
视图(vies)
from django.contrib import admin
from .models import Information
class InformationAdmin(admin.ModelAdmin):
list_display = ('name','privateip','publicip','use','zoneid','cpu','memory','datadisk')
admin.site.register(Information,InformationAdmin)
模板(templates)
#header {
background-color:#484891;
color:hite;
text-align:center;
padding:5px;
}
#nav {
line-height:30px;
background-color:#E0E0E0;
height:calc(100vh - 111px);
idth:200px;
float:left;
padding:5px;
}
#section {
idth:350px;
float:left;
padding:10px;
}
#footer {
background-color:#484891;
color:hite;
clear:both;
text-align:center;
padding:6px;
position:fixed;
left:0;
bottom:0;
idth: 100%;
height:20px;
}
服务器信息展示
CMDB
This is use django to create cmdb
User:fueichao
Email:961769710@qq.
Tel:15517707935
{% block content %}
{% for infor in infor_list %}
{{ infor.name }}
{{ infor.privateip}}
{{ infor.publicip}}
{{ infor.zoneid}}
{{ infor.cpu}}
{{ infor.memory}}
{{ infor.datadisk}}
{{ infor.time}}
{{ infor.use}}
{% endfor %}
{% endblock %}
Copyright fueichao ebssh page
后台数据录入,我用的django自身的admin
Kiom1mFjI2T_tvJAABDENPg1GM935.png-h_50
Kiom1mFjLyCYmcsAAB-Smx4VnY704.png-h_50
前端服务器信息展示
KioL1mFjb7Stcd6AACpMTm6FGI866.png-h_50
四、服务器性能监控
视图(vies)
def cpu(request):
os.system('sh /home/zqxt_form2/monitor/image.sh')
return render_to_response('cpu.html')
def memory(request):
os.system('sh /home/zqxt_form2/monitor/image.sh')
return render_to_response('memory.html')
def disk(request):
os.system('sh /home/zqxt_form2/monitor/image.sh')
return render_to_response('disk.html')
image.sh 脚本
#!/bin/bash
minute1="`date --date '1 minute ago ' +%s`"
minute3="`date --date '3 minute ago ' +%s`"
minute5="`date --date '5 minute ago ' +%s`"
dir="/home/zqxt_form2/monitor/rrdtool/"
rrdtool graph ${dir}/cpu1.jpg --step 5 -s ${minute1} -t "cpu free monitor (1 minute)" -v cpu DEF:cpu=${dir}/cpu.rrd:cpuds:AVERAGE LINE1:cpu#FF0000:'cpu free'
rrdtool graph ${dir}/cpu3.jpg --step 5 -s ${minute3} -t "cpu free monitor (3 minute" -v cpu DEF:cpu=${dir}/cpu.rrd:cpuds:AVERAGE LINE1:cpu#FF0000:'cpu free'
rrdtool graph ${dir}/cpu5.jpg --step 5 -s ${minute5} -t "cpu free monitor (5 minute)" -v cpu DEF:cpu=${dir}/cpu.rrd:cpuds:AVERAGE LINE1:cpu#FF0000:'cpu free'
rrdtool graph ${dir}/memory1.jpg --step 5 -s ${minute1} -t " memory free monitor (1 minute) " -v cpu DEF:cpu=${dir}/memory.rrd:memoryds:AVERAGE LINE1:cpu#FF0000:'memory free(MB)'
rrdtool graph ${dir}/memory3.jpg --step 5 -s ${minute3} -t " memory free monitor (3 minute)" -v cpu DEF:cpu=${dir}/memory.rrd:memoryds:AVERAGE LINE1:cpu#FF0000:'memory free(MB)'
rrdtool graph ${dir}/memory5.jpg --step 5 -s ${minute5} -t " memory free monitor (5 minute)" -v cpu DEF:cpu=${dir}/memory.rrd:memoryds:AVERAGE LINE1:cpu#FF0000:'memory free(MB)'
rrdtool graph ${dir}/disk1.jpg --step 5 -s ${minute1} -t "disk used / monitor (1 minute)" -v cpu DEF:cpu=${dir}/disk.rrd:diskds:AVERAGE LINE1:cpu#FF0000:'disk free %'
rrdtool graph ${dir}/disk3.jpg --step 5 -s ${minute3} -t "disk used / monitor (3 minute)" -v cpu DEF:cpu=${dir}/disk.rrd:diskds:AVERAGE LINE1:cpu#FF0000:'disk free %'
rrdtool graph ${dir}/disk5.jpg --step 5 -s ${minute5} -t "disk used / monitor (5 minute)" -v cpu DEF:cpu=${dir}/disk.rrd:diskds:AVERAGE LINE1:cpu#FF0000:'disk free %'
dir2="/home/zqxt_form2/monitor/static/jpg/monitor/"
cp -rf ${dir}/cpu1.jpg ${dir2}
cp -rf ${dir}/cpu3.jpg ${dir2}
cp -rf ${dir}/cpu5.jpg ${dir2}
cp -rf ${dir}/memory1.jpg ${dir2}
cp -rf ${dir}/memory3.jpg ${dir2}
cp -rf ${dir}/memory5.jpg ${dir2}
cp -rf ${dir}/disk1.jpg ${dir2}
cp -rf ${dir}/disk3.jpg ${dir2}
cp -rf ${dir}/disk5.jpg ${dir2}
模板(templates)
{% load staticfiles %}
#header {
background-color:#484891;
color:hite;
text-align:center;
padding:5px;
}
#nav {
line-height:30px;
background-color:#eeeeee;
height:calc(100vh - 111px);
idth:200px;
float:left;
padding:5px;
}
#section {
idth:350px;
float:left;
padding:10px;
}
#footer {
background-color:#484891;
color:hite;
clear:both;
text-align:center;
padding:6px;
position:fixed;
left:0;
bottom:0;
idth: 100%;
height:20px;
}
服务器性能指标监控
磁盘监控
cpu监控
memory监控
Copyright fueichao monitor page
前端效果图
KioL1mFj6yKG0uAAEDz1TeXvA675.png-h_50
五 、服务器批量管理
视图(vies)
def servers(request):
if request.method == 'POST':
hostgroup = request.POST.get("hostgroup","")
model = request.POST.get("model","")
user = request.POST.get("user","")
mand = request.POST.get("mand","")
os.environ['hostgroup']=str(hostgroup)
os.environ['model']=str(model)
os.environ['user']=str(user)
os.environ['mand']=str(mand)
output = mands.getoutput("sh /home/zqxt_form2/monitor/ansible.sh $hostgroup $model $user $mand")
return render(request,'servers.html',{'output':output})
return render(request,'servers.html')
ansible脚本
#!/bin/bash
ansible $1 -m $2 -a "sudo su - '$3' -c '$4'"
模板(templates)
{% load staticfiles %}
批量管理页面
Copyright © 付炜超的linux运维管理平台
前端效果图
Kiom1mFkWjhLHO2AABPV0YVmsU102.png-h_50
这个项目由我自己独立完成,算是给自己的大学一个交代了吧。
如需看详情版,请到 spacer.gifhttp://.demodashi./demo/11242.html 下载
©著作权归作者所有来自51CTO博客作者付炜超的原创作品,如需转载,请注明出处,否则将追究法律责任
空调维修
- 海信电视维修站 海信电视维修站点
- 格兰仕空调售后电话 格兰仕空调维修售后服务电
- 家电售后服务 家电售后服务流程
- 华扬太阳能维修 华扬太阳能维修收费标准表
- 三菱电机空调维修 三菱电机空调维修费用高吗
- 美的燃气灶维修 美的燃气灶维修收费标准明细
- 科龙空调售后服务 科龙空调售后服务网点
- 华帝热水器维修 华帝热水器维修常见故障
- 康泉热水器维修 康泉热水器维修故障
- 华凌冰箱维修电话 华凌冰箱维修点电话
- 海尔维修站 海尔维修站点地址在哪里
- 北京海信空调维修 北京海信空调售后服务
- 科龙空调维修 科龙空调维修故障
- 皇明太阳能售后 皇明太阳能售后维修点
- 海信冰箱售后服务 海信冰箱售后服务热线电话
- 海尔热水器服务热线