mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-12-11 12:56:10 +08:00
feat: Add PrettyDistro field to dashboard information and update related services and frontend components
This commit is contained in:
parent
fef13211a0
commit
0bedd2b48a
5 changed files with 99 additions and 3 deletions
|
|
@ -13,6 +13,7 @@ type DashboardBase struct {
|
|||
Platform string `json:"platform"`
|
||||
PlatformFamily string `json:"platformFamily"`
|
||||
PlatformVersion string `json:"platformVersion"`
|
||||
PrettyDistro string `json:"prettyDistro"`
|
||||
KernelArch string `json:"kernelArch"`
|
||||
KernelVersion string `json:"kernelVersion"`
|
||||
VirtualizationSystem string `json:"virtualizationSystem"`
|
||||
|
|
@ -49,6 +50,7 @@ type OsInfo struct {
|
|||
PlatformFamily string `json:"platformFamily"`
|
||||
KernelArch string `json:"kernelArch"`
|
||||
KernelVersion string `json:"kernelVersion"`
|
||||
PrettyDistro string `json:"prettyDistro"`
|
||||
|
||||
DiskSize int64 `json:"diskSize"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -88,6 +88,7 @@ func (u *DashboardService) LoadOsInfo() (*dto.OsInfo, error) {
|
|||
baseInfo.PlatformFamily = hostInfo.PlatformFamily
|
||||
baseInfo.KernelArch = hostInfo.KernelArch
|
||||
baseInfo.KernelVersion = hostInfo.KernelVersion
|
||||
baseInfo.PrettyDistro = psutil.HOST.GetDistro()
|
||||
|
||||
diskInfo, err := psutil.DISK.GetUsage(global.Dir.BaseDir, false)
|
||||
if err == nil {
|
||||
|
|
@ -152,6 +153,7 @@ func (u *DashboardService) LoadBaseInfo(ioOption string, netOption string) (*dto
|
|||
Platform: hostInfo.Platform,
|
||||
PlatformFamily: hostInfo.PlatformFamily,
|
||||
PlatformVersion: hostInfo.PlatformVersion,
|
||||
PrettyDistro: psutil.HOST.GetDistro(),
|
||||
KernelArch: hostInfo.KernelArch,
|
||||
KernelVersion: hostInfo.KernelVersion,
|
||||
VirtualizationSystem: string(ss),
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package psutil
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
|
|
@ -13,7 +15,8 @@ type HostInfoState struct {
|
|||
mu sync.RWMutex
|
||||
lastSampleTime time.Time
|
||||
|
||||
cachedInfo *host.InfoStat
|
||||
cachedInfo *host.InfoStat
|
||||
cachedDistro string
|
||||
}
|
||||
|
||||
func (h *HostInfoState) GetHostInfo(forceRefresh bool) (*host.InfoStat, error) {
|
||||
|
|
@ -36,3 +39,86 @@ func (h *HostInfoState) GetHostInfo(forceRefresh bool) (*host.InfoStat, error) {
|
|||
|
||||
return hostInfo, nil
|
||||
}
|
||||
|
||||
func (h *HostInfoState) GetDistro() string {
|
||||
if h.cachedDistro == "" {
|
||||
h.cachedDistro = detectLinuxDistro()
|
||||
}
|
||||
return h.cachedDistro
|
||||
}
|
||||
|
||||
func detectLinuxDistro() string {
|
||||
distroFiles := []string{
|
||||
"/etc/os-release",
|
||||
"/usr/lib/os-release",
|
||||
"/etc/lsb-release",
|
||||
"/etc/redhat-release",
|
||||
"/etc/debian_version",
|
||||
"/etc/issue",
|
||||
}
|
||||
|
||||
var targetFile string
|
||||
for _, f := range distroFiles {
|
||||
if _, err := os.Stat(f); err == nil {
|
||||
targetFile = f
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if targetFile != "" {
|
||||
data, err := os.ReadFile(targetFile)
|
||||
if err == nil {
|
||||
content := string(data)
|
||||
switch targetFile {
|
||||
case "/etc/os-release", "/usr/lib/os-release":
|
||||
if v := findKeyValues(content, "PRETTY_NAME"); v["PRETTY_NAME"] != "" {
|
||||
return v["PRETTY_NAME"]
|
||||
}
|
||||
if v := findKeyValues(content, "NAME", "VERSION_ID"); v["NAME"] != "" && v["VERSION_ID"] != "" {
|
||||
return v["NAME"] + " " + v["VERSION_ID"]
|
||||
}
|
||||
case "/etc/lsb-release":
|
||||
if v := findKeyValues(content, "DISTRIB_DESCRIPTION"); v["DISTRIB_DESCRIPTION"] != "" {
|
||||
return v["DISTRIB_DESCRIPTION"]
|
||||
}
|
||||
if v := findKeyValues(content, "DISTRIB_ID", "DISTRIB_RELEASE"); v["DISTRIB_ID"] != "" && v["DISTRIB_RELEASE"] != "" {
|
||||
return v["DISTRIB_ID"] + " " + v["DISTRIB_RELEASE"]
|
||||
}
|
||||
case "/etc/redhat-release", "/etc/issue":
|
||||
return strings.TrimSpace(content)
|
||||
case "/etc/debian_version":
|
||||
return "Debian " + strings.TrimSpace(content)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// gopsutil fallback
|
||||
if osInfo, err := host.Info(); err == nil {
|
||||
return osInfo.OS
|
||||
}
|
||||
|
||||
return "Unknown Linux"
|
||||
}
|
||||
|
||||
func findKeyValues(data string, keys ...string) map[string]string {
|
||||
result := make(map[string]string, len(keys))
|
||||
found := 0
|
||||
for _, line := range strings.Split(data, "\n") {
|
||||
idx := strings.Index(line, "=")
|
||||
if idx == -1 {
|
||||
continue
|
||||
}
|
||||
key := line[:idx]
|
||||
for _, k := range keys {
|
||||
if key == k {
|
||||
result[k] = strings.Trim(line[idx+1:], "\"")
|
||||
found++
|
||||
if found == len(keys) {
|
||||
return result
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ export namespace Dashboard {
|
|||
platform: string;
|
||||
platformFamily: string;
|
||||
platformVersion: string;
|
||||
prettyDistro: string;
|
||||
kernelArch: string;
|
||||
kernelVersion: string;
|
||||
virtualizationSystem: string;
|
||||
|
|
|
|||
|
|
@ -203,7 +203,9 @@
|
|||
<span class="system-label">{{ $t('home.platformVersion') }}</span>
|
||||
</template>
|
||||
{{
|
||||
baseInfo.platformVersion
|
||||
baseInfo.prettyDistro
|
||||
? baseInfo.prettyDistro
|
||||
: baseInfo.platformVersion
|
||||
? baseInfo.platform + '-' + baseInfo.platformVersion
|
||||
: baseInfo.platform
|
||||
}}
|
||||
|
|
@ -393,6 +395,7 @@ const baseInfo = ref<Dashboard.BaseInfo>({
|
|||
platform: '',
|
||||
platformFamily: '',
|
||||
platformVersion: '',
|
||||
prettyDistro: '',
|
||||
kernelArch: '',
|
||||
kernelVersion: '',
|
||||
virtualizationSystem: '',
|
||||
|
|
@ -660,7 +663,9 @@ const handleCopy = () => {
|
|||
'\n' +
|
||||
i18n.global.t('home.platformVersion') +
|
||||
': ' +
|
||||
(baseInfo.value.platformVersion
|
||||
(baseInfo.value.prettyDistro
|
||||
? baseInfo.value.prettyDistro
|
||||
: baseInfo.value.platformVersion
|
||||
? baseInfo.value.platform + '-' + baseInfo.value.platformVersion
|
||||
: baseInfo.value.platform) +
|
||||
'\n' +
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue