Files
aler_dashboard_git/node_exporter_web/static/index.html
T

178 lines
6.9 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>Node Exporter 可视化管理面板</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="container mt-4">
<h2 class="text-center mb-4">Node Exporter 批量管理面板</h2>
<!-- 单台主机操作区域 -->
<div class="card mb-4">
<div class="card-header">单台主机安装/卸载</div>
<div class="card-body row g-3">
<div class="col-auto">
<label>主机IP</label>
<input type="text" id="host" class="form-control" placeholder="10.150.10.83">
</div>
<div class="col-auto">
<label>SSH端口</label>
<input type="text" id="ssh_port" class="form-control" value="22">
</div>
<div class="col-auto">
<label>用户名</label>
<input type="text" id="user" class="form-control" value="root">
</div>
<div class="col-auto">
<label>密码</label>
<input type="password" id="pwd" class="form-control" placeholder="留空使用密钥">
</div>
<div class="col-auto align-self-end">
<button class="btn btn-success" onclick="singleInstall()">单台安装</button>
<button class="btn btn-danger" onclick="singleUninstall()">单台卸载</button>
<button class="btn btn-info" onclick="sshDiag()">SSH连通诊断</button>
</div>
</div>
</div>
<!-- 批量操作区域 -->
<div class="card mb-4">
<div class="card-header">批量操作(读取node_exporter_hosts.txt</div>
<div class="card-body">
<button class="btn btn-primary me-2" onclick="batchInstall()">批量安装</button>
<button class="btn btn-warning me-2" onclick="batchUninstall()">批量卸载</button>
<button class="btn btn-secondary me-2" onclick="getHosts()">刷新主机列表</button>
<button class="btn btn-dark" onclick="restartProm()">重启Prometheus</button>
<hr>
<h5>主机清单预览</h5>
<pre id="hosts_text" class="bg-light p-2"></pre>
</div>
</div>
<!-- 执行日志输出 -->
<div class="card">
<div class="card-header">执行实时日志</div>
<div class="card-body">
<textarea id="log_box" class="form-control bg-black text-white" rows="15" readonly></textarea>
</div>
</div>
<script>
function log(msg) {
const box = document.getElementById('log_box');
const time = new Date().toLocaleString();
if (msg === null || msg === undefined || msg === "") {
msg = "命令无输出或执行返回空";
}
box.value += `[${time}] ${msg}\n`;
box.scrollTop = box.scrollHeight;
}
// 统一处理接口返回
async function fetchApi(url) {
try {
const res = await fetch(url);
if (!res.ok) {
log("接口请求失败,HTTP状态码:" + res.status);
return null;
}
const data = await res.json();
return data;
} catch (e) {
log("网络/解析异常:" + e.message);
return null;
}
}
// 单台安装
async function singleInstall() {
const host = document.getElementById('host').value.trim();
const sp = document.getElementById('ssh_port').value.trim();
const user = document.getElementById('user').value.trim();
const pwd = document.getElementById('pwd').value;
if (!host) {
log("错误:请填写主机IP");
return;
}
log("开始执行单台安装:" + host);
const data = await fetchApi(`/api/single/install?host=${host}&ssh_port=${sp}&user=${user}&pwd=${pwd}`);
if (!data) return;
log(data.Msg);
if(data.Code === 1) log("执行错误:" + data.Err);
}
// 单台卸载
async function singleUninstall() {
const host = document.getElementById('host').value.trim();
const sp = document.getElementById('ssh_port').value.trim();
const user = document.getElementById('user').value.trim();
const pwd = document.getElementById('pwd').value;
if (!host) {
log("错误:请填写主机IP");
return;
}
log("开始执行单台卸载:" + host);
const data = await fetchApi(`/api/single/uninstall?host=${host}&ssh_port=${sp}&user=${user}&pwd=${pwd}`);
if (!data) return;
log(data.Msg);
if(data.Code === 1) log("执行错误:" + data.Err);
}
// 批量安装
async function batchInstall() {
log("开始批量安装所有清单主机");
const data = await fetchApi("/api/batch/install");
if (!data) return;
log(data.Msg);
if(data.Code === 1) log("执行错误:" + data.Err);
}
// 批量卸载
async function batchUninstall() {
log("开始批量卸载所有清单主机");
const data = await fetchApi("/api/batch/uninstall");
if (!data) return;
log(data.Msg);
if(data.Code === 1) log("执行错误:" + data.Err);
}
// 刷新主机列表
async function getHosts() {
const data = await fetchApi("/api/hosts/list");
if (!data) return;
document.getElementById('hosts_text').innerText = data.Msg;
}
// 重启Prometheus
async function restartProm() {
log("执行Prometheus重启");
const data = await fetchApi("/api/prom/restart");
if (!data) return;
log(data.Msg);
if(data.Code === 1) log("执行错误:" + data.Err);
}
// SSH诊断
async function sshDiag() {
const host = document.getElementById('host').value.trim();
const sp = document.getElementById('ssh_port').value.trim();
const user = document.getElementById('user').value.trim();
const pwd = document.getElementById('pwd').value;
if (!host) {
log("错误:请填写主机IP");
return;
}
log("开始SSH连通诊断:" + host);
const data = await fetchApi(`/api/ssh/diag?host=${host}&ssh_port=${sp}&user=${user}&pwd=${pwd}`);
if (!data) return;
log(data.Msg);
if(data.Code === 1) log("执行错误:" + data.Err);
}
// 页面加载自动刷新主机列表
window.onload = getHosts;
</script>
</body>
</html>