Skip to content

Commit

Permalink
chore: fix some issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Ehco1996 committed Sep 9, 2024
1 parent 6851d83 commit 1f511c0
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 17 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down Expand Up @@ -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
Expand Down
47 changes: 36 additions & 11 deletions hack/get-ehco.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,46 @@ WantedBy=multi-user.target
EOF
}

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."
exit 1
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
}

# 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."
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 "需要配置标志。请使用 --config 指定配置文件路径或 API 端点。"
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
}

Expand Down Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion internal/web/templates/_navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ <h1 class="title is-4">Ehco Relay</h1>
</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>
Expand Down
22 changes: 18 additions & 4 deletions pkg/metric_reader/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ func (b *readerImpl) ParseNodeMetrics(metricMap map[string]*dto.MetricFamily, nm
b.processLoadMetrics(metricMap, nm)

b.calculateFinalMetrics(nm, cpu)

return nil
}

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 1f511c0

Please sign in to comment.