Skip to content

Commit

Permalink
1.修改原有dashboard接口,更新dashboard-web界面
Browse files Browse the repository at this point in the history
2.修复分页bug
3.补全readme文档
4.分离安装需要的包
  • Loading branch information
cplinux98 committed Jan 7, 2023
1 parent b268a97 commit aa4315f
Show file tree
Hide file tree
Showing 18 changed files with 237 additions and 86 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,7 @@ dmypy.json
# Cython debug symbols
cython_debug/

# django
migrations/

t*.py
22 changes: 20 additions & 2 deletions .idea/SmartPXE.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 75 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,78 @@ https://wiki.syslinux.org/wiki/index.php?title=PXELINUX
Redhat
https://access.redhat.com/documentation/zh-cn/red_hat_enterprise_linux/6/html/installation_guide/sn-booting-from-pxe-x86
```


## 开发项目

### 配置pip

```bash
mkdir ~/.pip
vim ~/.pip/pip.conf

# 输入下面的内容
[global]
index-url = https://mirrors.aliyun.com/pypi/simple/

[install]
trusted-host=mirrors.aliyun.com


```

### 安装依赖包
```commandline
sudo apt install libmysqlclient-dev python3-dev gcc
pip3 install -r requirements
```

### 创建数据库

```sql
CREATE DATABASE `smartpxe` CHARACTER SET 'utf8mb4'
```

### 迁移数据库

```bash
python3 manage.py makemigrations
python3 manage.py migrate
```

### 创建超级用户

```bash
python3 manage.py createsuperuser
```

### 启动项目

```bash
# open dev
smartpxe.settings.py -> CONF_STATUS = 0
python3 manage.py runserver 0.0.0.0:8000
```

### build

```bash
python setup.py sdist --formats=gztar
# dist/SmartPXE-version.tar.gz
```


### install

```bash
1.从百度网盘下载 smartpxe_install_require.zip依赖文件
2.修改install.sh里面的版本号
3.将软件包放置在install.sh同级目录下
4.执行安装(root权限)
```

```angular2html
链接:https://pan.baidu.com/s/1jJJ0ZMigI7bN_8bnkz1Q-Q?pwd=m3qj
提取码:m3qj
```

6 changes: 3 additions & 3 deletions dashboard/urls.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from django.contrib import admin
from django.urls import path
from .views import get_sys_info, get_status_info
from .views import get_sys_info, get_status_info, get_history_info
from rest_framework.routers import SimpleRouter

router = SimpleRouter()


urlpatterns = [
path('sysinfo/', get_sys_info),
path('status/', get_status_info)
path('status/', get_status_info),
path('history/', get_history_info)
] + router.urls


Expand Down
130 changes: 64 additions & 66 deletions dashboard/views.py
Original file line number Diff line number Diff line change
@@ -1,77 +1,20 @@
import datetime

import psutil
from rest_framework.decorators import api_view, permission_classes
from rest_framework.permissions import IsAuthenticated, IsAdminUser
from django.db.models import Count
from rest_framework.decorators import api_view
from rest_framework.request import Request
from rest_framework.response import Response
from pyecharts import options as opts
from pyecharts.charts import Gauge
from install.models import Discover, InstallResult, InstallProgress

options_temp = """
{
tooltip: {
formatter: '{a} <br/>{b} : {c}%'
},
series: [
{
name: 'show_name',
type: 'gauge',
detail: {
formatter: '{value}'
},
data: [
{
value: data_value,
name: 'data_name'
}
]
}
]
}
"""

def temp(title_name, data_value):
c = (
Gauge(init_opts=opts.InitOpts(width="800px", height="800px"))
.add(
series_name=title_name,
data_pair=[("已使用", data_value)],
radius="50%",
axisline_opts=opts.AxisLineOpts(
linestyle_opts=opts.LineStyleOpts(
color=[(0.3, "#67e0e3"), (0.7, "#37a2da"), (1, "#fd666d")], width=15
)
),
detail_label_opts=opts.GaugeDetailOpts(offset_center=[0, "30%"]),
title_label_opts=opts.GaugeTitleOpts())
.set_global_opts(
title_opts=opts.TitleOpts(title=title_name),
legend_opts=opts.LegendOpts(is_show=False),
tooltip_opts=opts.TooltipOpts(is_show=True, formatter="{a} <br/>{b} : {c}%"), )
)
return c.dump_options_with_quotes()


def status_temp(title, value, img, link):
ret = {
"title": title,
"value": value,
"img": img,
"date": datetime.datetime.now(),
"link": link
}
return ret

# get sys info
# @permission_classes([IsAuthenticated])
@api_view(['GET'])
def get_sys_info(request: Request):
options = {
"cpu": temp('CPU使用率', psutil.cpu_percent(interval=1)),
"disk": temp('硬盘使用率', psutil.virtual_memory().percent),
"mem": temp('内存使用率', psutil.disk_usage('/').percent)
"cpu": psutil.cpu_percent(),
"disk": psutil.virtual_memory().percent,
"mem": psutil.disk_usage('/').percent
}
return Response(options)

Expand All @@ -84,11 +27,66 @@ def get_status_info(request: Request):
install_num = InstallProgress.objects.all().count()
success = InstallResult.objects.filter(status=1).count()
failed = InstallResult.objects.filter(status=0).count()

status = {
"client": status_temp('客户端在线数量', client_num, 'https://image.lichunpeng.cn/py_test/ts_client.png', '/discovered'),
"install": status_temp('正在安装的数量', install_num, 'https://image.lichunpeng.cn/py_test/install.png', '/installing'),
"success": status_temp('安装成功的数量', success, 'https://image.lichunpeng.cn/py_test/success.png', '/installed'),
"failed": status_temp('安装失败的数量', failed, 'https://image.lichunpeng.cn/py_test/failed.png', '/installed')
"success": success,
"failed": failed,
"online": client_num,
"running": install_num
}

return Response(status)


@api_view(['GET'])
def get_history_info(request: Request):
"""
获取完成的,失败和成功的历史数据
:param request:
:return:
"""
end_time = datetime.datetime.now()
start_time = end_time - datetime.timedelta(days=30)

select = {'day': 'date(date)'}

success_module = InstallResult.objects.filter(status=1, date__range=(start_time, end_time)).extra(select)
success = success_module.values('day').distinct().order_by('day').annotate(number=Count('date'))

failed_module = InstallResult.objects.filter(status=0, date__range=(start_time, end_time)).extra(select)
failed = failed_module.values('day').distinct().order_by('day').annotate(number=Count('date'))

# 循环成功和失败的结果,按照对应的key放在_date_value里面
_date_value_s = {}
_date_value_f = {}
days = []

for d in range(30):
day = (end_time + datetime.timedelta(days=(d - 30))).strftime("%Y-%m-%d")
days.append(day)
# 初始化
_date_value_s[day] = 0
_date_value_f[day] = 0
# print(days)

for i in success:
day = i.get("day").strftime("%Y-%m-%d")
# print(day)
value = i.get("number")
_date_value_s[day] = value

# print(_date_value_s)
for i in failed:
day = i.get("day").strftime("%Y-%m-%d")
value = i.get("number")
_date_value_f[day] = value

# a1 = sorted(_date_value_s.items(), key=lambda x: x[0])

status = {
"success": [i for i in _date_value_s.values()],
"failed": [i for i in _date_value_f.values()],
"days": days
}

return Response(status)
1 change: 0 additions & 1 deletion frontends/css/app.377f3dee.css

This file was deleted.

1 change: 1 addition & 0 deletions frontends/css/app.c916690f.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontends/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!DOCTYPE html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/favicon.ico"><title>SmartPXE智能部署平台</title><link href="/css/app.377f3dee.css" rel="preload" as="style"><link href="/css/chunk-vendors.6b196170.css" rel="preload" as="style"><link href="/js/app.817de867.js" rel="preload" as="script"><link href="/js/chunk-vendors.6254ffd1.js" rel="preload" as="script"><link href="/css/chunk-vendors.6b196170.css" rel="stylesheet"><link href="/css/app.377f3dee.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but SmartPXE智能部署平台 doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script src="/js/chunk-vendors.6254ffd1.js"></script><script src="/js/app.817de867.js"></script></body></html>
<!DOCTYPE html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/favicon.ico"><title>SmartPXE智能部署平台</title><link href="/css/app.c916690f.css" rel="preload" as="style"><link href="/css/chunk-vendors.6b196170.css" rel="preload" as="style"><link href="/js/app.fae1315c.js" rel="preload" as="script"><link href="/js/chunk-vendors.badef4b9.js" rel="preload" as="script"><link href="/css/chunk-vendors.6b196170.css" rel="stylesheet"><link href="/css/app.c916690f.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but SmartPXE智能部署平台 doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script src="/js/chunk-vendors.badef4b9.js"></script><script src="/js/app.fae1315c.js"></script></body></html>
2 changes: 0 additions & 2 deletions frontends/js/app.817de867.js

This file was deleted.

1 change: 0 additions & 1 deletion frontends/js/app.817de867.js.map

This file was deleted.

2 changes: 2 additions & 0 deletions frontends/js/app.fae1315c.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions frontends/js/app.fae1315c.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit aa4315f

Please sign in to comment.