mirror of
https://github.com/bolucat/Archive.git
synced 2025-12-24 13:28:37 +08:00
Update On Mon Sep 9 20:33:15 CEST 2024
This commit is contained in:
@@ -27,7 +27,6 @@ require (
|
||||
golang.org/x/sync v0.8.0
|
||||
golang.org/x/time v0.6.0
|
||||
google.golang.org/grpc v1.65.0
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
modernc.org/sqlite v1.32.0
|
||||
)
|
||||
|
||||
@@ -130,6 +129,7 @@ require (
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 // indirect
|
||||
google.golang.org/protobuf v1.34.2 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
gvisor.dev/gvisor v0.0.0-20231202080848-1f7806d17489 // indirect
|
||||
howett.net/plist v1.0.1 // indirect
|
||||
lukechampine.com/blake3 v1.3.0 // indirect
|
||||
|
||||
@@ -61,21 +61,46 @@ WantedBy=multi-user.target
|
||||
EOF
|
||||
}
|
||||
|
||||
function _detect_package_manager() {
|
||||
if command -v apt-get &>/dev/null; then
|
||||
echo "apt-get"
|
||||
elif command -v yum &>/dev/null; then
|
||||
echo "yum"
|
||||
elif command -v dnf &>/dev/null; then
|
||||
echo "dnf"
|
||||
else
|
||||
echo "未知"
|
||||
fi
|
||||
}
|
||||
|
||||
function _install_dependencies() {
|
||||
local pkg_manager=$(_detect_package_manager)
|
||||
|
||||
case $pkg_manager in
|
||||
apt-get)
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y jq curl
|
||||
;;
|
||||
yum|dnf)
|
||||
sudo $pkg_manager install -y jq curl
|
||||
;;
|
||||
*)
|
||||
_print_error_msg "无法检测到支持的包管理器。请手动安装 jq 和 curl。"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
function _check_install_required() {
|
||||
if [[ -z "$API_OR_CONFIG_PATH" ]]; then
|
||||
_print_error_msg "Flag for config is required. please use --config to specify the configuration file path or api endpoint."
|
||||
_print_error_msg "需要配置标志。请使用 --config 指定配置文件路径或 API 端点。"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# check jq and curl
|
||||
if ! command -v jq &>/dev/null; then
|
||||
_print_error_msg "jq is required to parse JSON data. please use apt/yum to install jq."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! command -v curl &>/dev/null; then
|
||||
_print_error_msg "curl is required to download files. please use apt/yum to install curl."
|
||||
exit 1
|
||||
# 检查并安装 jq 和 curl
|
||||
if ! command -v jq &>/dev/null || ! command -v curl &>/dev/null; then
|
||||
_print_warning_msg "正在安装必要的依赖项 (jq 和 curl)..."
|
||||
_install_dependencies
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -248,7 +273,7 @@ function perform_install() {
|
||||
|
||||
_download_bin
|
||||
_install_systemd_service
|
||||
_print_warning_msg "Ehco has been installed."
|
||||
_print_warning_msg "Ehco 已安装完成。"
|
||||
}
|
||||
|
||||
function perform_remove() {
|
||||
|
||||
@@ -5,7 +5,7 @@ import "time"
|
||||
type RelayType string
|
||||
|
||||
var (
|
||||
Version = "1.1.5-dev"
|
||||
Version = "1.1.5"
|
||||
GitBranch string
|
||||
GitRevision string
|
||||
BuildTime string
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
</a>
|
||||
<a href="/rule_metrics/" class="navbar-item">
|
||||
<span class="icon"><i class="fas fa-chart-line"></i></span>
|
||||
<span>Metrics</span>
|
||||
<span>Monitor</span>
|
||||
</a>
|
||||
<a href="/logs/" class="navbar-item">
|
||||
<span class="icon"><i class="fas fa-file-alt"></i></span>
|
||||
|
||||
@@ -21,11 +21,19 @@
|
||||
<li>StartTime: {{.StartTime}}</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="mt-4">
|
||||
<p>Latest Version: <span id="latestVersion">Checking...</span></p>
|
||||
<p id="updateMessage" style="display: none;"></p>
|
||||
</div>
|
||||
</div>
|
||||
<footer class="card-footer">
|
||||
<button class="button is-danger is-outlined card-footer-item" id="reloadButton">
|
||||
<span class="icon"><i class="fas fa-sync-alt"></i></span>
|
||||
<span>Reload Config</span>
|
||||
<span>Reload Configuration</span>
|
||||
</button>
|
||||
<button class="button is-info is-outlined card-footer-item" id="checkUpdateButton">
|
||||
<span class="icon"><i class="fas fa-download"></i></span>
|
||||
<span>Check for Updates</span>
|
||||
</button>
|
||||
</footer>
|
||||
</div>
|
||||
@@ -46,7 +54,20 @@
|
||||
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
// Reload config button click event
|
||||
// Add this function to compare version strings
|
||||
function compareVersions(v1, v2) {
|
||||
const v1Parts = v1.replace('v', '').split('.');
|
||||
const v2Parts = v2.replace('v', '').split('.');
|
||||
for (let i = 0; i < Math.max(v1Parts.length, v2Parts.length); i++) {
|
||||
const v1Part = parseInt(v1Parts[i] || 0);
|
||||
const v2Part = parseInt(v2Parts[i] || 0);
|
||||
if (v1Part > v2Part) return 1;
|
||||
if (v1Part < v2Part) return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Reload configuration button click event
|
||||
$('#reloadButton').click(function () {
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
@@ -59,6 +80,33 @@
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
// Check for updates button click event
|
||||
$('#checkUpdateButton').click(function () {
|
||||
$.ajax({
|
||||
url: 'https://api.github.com/repos/Ehco1996/ehco/releases/latest',
|
||||
type: 'GET',
|
||||
dataType: 'json',
|
||||
success: function (data) {
|
||||
var latestVersion = data.tag_name;
|
||||
$('#latestVersion').text(latestVersion);
|
||||
var currentVersion = '{{.Version}}';
|
||||
if (compareVersions(latestVersion, currentVersion) > 0) {
|
||||
var releaseUrl = data.html_url;
|
||||
var updateMessage = 'New version available: ' + latestVersion +
|
||||
'. Please update manually from: <a href="' + releaseUrl + '" target="_blank">' + releaseUrl + '</a>';
|
||||
$('#updateMessage').html(updateMessage).show();
|
||||
alert('New version available: ' + latestVersion + '. Please check the update message for details.');
|
||||
} else {
|
||||
$('#updateMessage').hide();
|
||||
alert('You have the latest version');
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
alert('Failed to check for updates. Please try again later.');
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
@@ -66,7 +66,6 @@ func (b *readerImpl) ParseNodeMetrics(metricMap map[string]*dto.MetricFamily, nm
|
||||
b.processLoadMetrics(metricMap, nm)
|
||||
|
||||
b.calculateFinalMetrics(nm, cpu)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -95,9 +94,24 @@ func (b *readerImpl) processMemoryMetrics(metricMap map[string]*dto.MetricFamily
|
||||
}
|
||||
|
||||
func (b *readerImpl) processDiskMetrics(metricMap map[string]*dto.MetricFamily, nm *NodeMetrics) {
|
||||
nm.DiskTotalBytes = sumInt64Metric(metricMap, metricFilesystemSizeBytes)
|
||||
availableDisk := sumInt64Metric(metricMap, metricFilesystemAvailBytes)
|
||||
nm.DiskUsageBytes = nm.DiskTotalBytes - availableDisk
|
||||
if metric, ok := metricMap[metricFilesystemSizeBytes]; ok {
|
||||
for _, m := range metric.Metric {
|
||||
if getLabel(m, "mountpoint") == "/" {
|
||||
nm.DiskTotalBytes = int64(getMetricValue(m, metric.GetType()))
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if metric, ok := metricMap[metricFilesystemAvailBytes]; ok {
|
||||
for _, m := range metric.Metric {
|
||||
if getLabel(m, "mountpoint") == "/" {
|
||||
availableDisk := int64(getMetricValue(m, metric.GetType()))
|
||||
nm.DiskUsageBytes = nm.DiskTotalBytes - availableDisk
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (b *readerImpl) processNetworkMetrics(metricMap map[string]*dto.MetricFamily, nm *NodeMetrics) {
|
||||
|
||||
Reference in New Issue
Block a user