Skip to content

Commit 63424d6

Browse files
author
xinglu_zhang
committed
readme
1 parent 8186abd commit 63424d6

File tree

7 files changed

+140
-3
lines changed

7 files changed

+140
-3
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,4 @@ cython_debug/
159159
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
160160
# and can be added to the global gitignore or merged into this file. For a more nuclear
161161
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
162-
#.idea/
162+
.idea/

Dockerfile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# 使用官方Python基础镜像
2+
FROM python:3.8-slim
3+
4+
# 设置工作目录
5+
WORKDIR /app
6+
7+
# 复制当前目录的内容到容器中
8+
COPY ../../PyProject/monitor /app
9+
10+
# 安装依赖
11+
RUN pip install --index-url=https://mirrors.aliyun.com/pypi/simple/ --no-cache-dir -r requirements.txt
12+
13+
# 安装supervisor
14+
RUN pip install --index-url=https://mirrors.aliyun.com/pypi/simple/ supervisor==4.2.5
15+
16+
# 复制supervisor配置文件
17+
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
18+
19+
# 设置环境变量
20+
ENV FLASK_APP=app.py
21+
ENV FLASK_RUN_HOST=0.0.0.0
22+
23+
# 暴露端口
24+
EXPOSE 5000
25+
26+
# 运行Flask应用
27+
#CMD ["flask", "run"]
28+
29+
# 运行supervisord
30+
CMD ["/usr/local/bin/supervisord", "-n", "-c", "/etc/supervisor/conf.d/supervisord.conf"]

README.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,26 @@
1-
# monitor
2-
cpu and memory monitor, can use docker
1+
# monitor监控
2+
3+
可以监控linux服务器的CPU和内存占用情况,支持历史监控查询(个人自用,功能比较简陋)。
4+
使用docker部署,使用supervisord进行进程管理。
5+
6+
### 本地启动
7+
```
8+
# 环境配置
9+
pip install --index-url=https://mirrors.aliyun.com/pypi/simple/ --no-cache-dir -r requirements.txt
10+
```
11+
12+
### 打包部署(docker)
13+
```
14+
#打包镜像
15+
docker build -t monitor:0.0.3 . --progress=plain
16+
# 另存镜像
17+
docker save -o monitor003.tar monitor:0.0.3
18+
# 加载镜像
19+
docker load -i monitor-0.0.3.tar
20+
# 启动镜像
21+
docker run -d -p 5000:5000 --name monitor003 --mount type=bind,src=/proc,dst=/host/proc -dit --restart=always monitor:0.0.3
22+
```
23+
24+
访问地址:http://localhost:5000/
25+
26+
![img.png](img.png)

img.png

135 KB
Loading

monitor.db

192 KB
Binary file not shown.

templates/__init__.py

Whitespace-only changes.

templates/index.html

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Server Monitor</title>
6+
<script src="https://fastly.jsdelivr.net/npm/chart.js"></script>
7+
</head>
8+
<body>
9+
<div>
10+
<label for="start_time">Start Time:</label>
11+
<input type="datetime-local" id="start_time">
12+
<label for="end_time">End Time:</label>
13+
<input type="datetime-local" id="end_time">
14+
<button onclick="update()">Fetch Data</button>
15+
</div>
16+
<div>
17+
<canvas id="cpuChart" width="400" height="90"></canvas>
18+
<canvas id="memoryChart" width="400" height="90"></canvas>
19+
</div>
20+
21+
<script>
22+
23+
let cpuChart; // Global variable to store the CPU chart instance
24+
let memoryChart; // Global variable to store the Memory chart instance
25+
26+
async function fetchData(url) {
27+
const response = await fetch(url + '?start_time=' + document.getElementById('start_time').value + '&end_time=' + document.getElementById('end_time').value);
28+
return await response.json();
29+
}
30+
31+
async function updateChart(chartId, label, url) {
32+
// Destroy existing chart if it exists
33+
if (chartId === 'cpuChart' && cpuChart) {
34+
cpuChart.destroy();
35+
} else if (chartId === 'memoryChart' && memoryChart) {
36+
memoryChart.destroy();
37+
}
38+
39+
const data = await fetchData(url);
40+
const labels = data.map(item => item.timestamp);
41+
const values = data.map(item => item[label]);
42+
43+
const ctx = document.getElementById(chartId).getContext('2d');
44+
const chart = new Chart(ctx, {
45+
type: 'line',
46+
data: {
47+
labels: labels,
48+
datasets: [
49+
{
50+
label: label + ' Usage',
51+
data: values,
52+
backgroundColor: 'rgba(246,173,188,0.2)',
53+
borderColor: 'rgb(30,66,219)',
54+
borderWidth: 1
55+
}
56+
]
57+
},
58+
options: {
59+
scales: {
60+
y: {
61+
beginAtZero: true
62+
}
63+
}
64+
}
65+
});
66+
67+
if (chartId === 'cpuChart') {
68+
cpuChart = chart;
69+
} else if (chartId === 'memoryChart') {
70+
memoryChart = chart;
71+
}
72+
}
73+
74+
async function update() {
75+
await updateChart('cpuChart', 'cpu', '/data/cpu');
76+
await updateChart('memoryChart', 'memory', '/data/memory');
77+
}
78+
79+
update();
80+
81+
</script>
82+
</body>
83+
</html>

0 commit comments

Comments
 (0)