mirror of
https://github.com/nezhahq/nezha.git
synced 2025-02-02 09:38:13 -05:00
Merge remote-tracking branch 'github/master'
This commit is contained in:
commit
7c115d0f9a
@ -1,6 +1,6 @@
|
|||||||
# 哪吒监控
|
# 哪吒监控
|
||||||
|
|
||||||
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/naiba/nezha/Dashboard%20image?label=管理面板%20v0.4.9&logo=github&style=for-the-badge) ![Agent release](https://img.shields.io/github/v/release/naiba/nezha?color=brightgreen&label=Agent&style=for-the-badge&logo=github) ![GitHub Workflow Status](https://img.shields.io/github/workflow/status/naiba/nezha/Agent%20release?label=Agent%20CI&logo=github&style=for-the-badge) ![shell](https://img.shields.io/badge/安装脚本-v0.4.6-brightgreen?style=for-the-badge&logo=linux)
|
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/naiba/nezha/Dashboard%20image?label=管理面板%20v0.4.11&logo=github&style=for-the-badge) ![Agent release](https://img.shields.io/github/v/release/naiba/nezha?color=brightgreen&label=Agent&style=for-the-badge&logo=github) ![GitHub Workflow Status](https://img.shields.io/github/workflow/status/naiba/nezha/Agent%20release?label=Agent%20CI&logo=github&style=for-the-badge) ![shell](https://img.shields.io/badge/安装脚本-v0.4.7-brightgreen?style=for-the-badge&logo=linux)
|
||||||
|
|
||||||
:trollface: 哪吒监控 一站式轻监控轻运维系统。支持系统状态、HTTP(SSL 证书变更、即将到期、到期)、TCP、Ping 监控报警,命令批量执行和计划任务。
|
:trollface: 哪吒监控 一站式轻监控轻运维系统。支持系统状态、HTTP(SSL 证书变更、即将到期、到期)、TCP、Ping 监控报警,命令批量执行和计划任务。
|
||||||
|
|
||||||
|
@ -12,15 +12,17 @@ import (
|
|||||||
|
|
||||||
"github.com/go-ping/ping"
|
"github.com/go-ping/ping"
|
||||||
"github.com/naiba/nezha/pkg/utils"
|
"github.com/naiba/nezha/pkg/utils"
|
||||||
|
"github.com/shirou/gopsutil/v3/cpu"
|
||||||
"github.com/shirou/gopsutil/v3/disk"
|
"github.com/shirou/gopsutil/v3/disk"
|
||||||
|
"github.com/shirou/gopsutil/v3/host"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// icmp()
|
// icmp()
|
||||||
// tcpping()
|
// tcpping()
|
||||||
// httpWithSSLInfo()
|
// httpWithSSLInfo()
|
||||||
// diskinfo()
|
sysinfo()
|
||||||
cmdExec()
|
// cmdExec()
|
||||||
}
|
}
|
||||||
|
|
||||||
func tcpping() {
|
func tcpping() {
|
||||||
@ -34,8 +36,26 @@ func tcpping() {
|
|||||||
fmt.Println(time.Now().Sub(start).Microseconds(), float32(time.Now().Sub(start).Microseconds())/1000.0)
|
fmt.Println(time.Now().Sub(start).Microseconds(), float32(time.Now().Sub(start).Microseconds())/1000.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func diskinfo() {
|
func sysinfo() {
|
||||||
// 硬盘信息
|
hi, _ := host.Info()
|
||||||
|
var cpuType string
|
||||||
|
if hi.VirtualizationSystem != "" {
|
||||||
|
cpuType = "Virtual"
|
||||||
|
} else {
|
||||||
|
cpuType = "Physical"
|
||||||
|
}
|
||||||
|
cpuModelCount := make(map[string]int)
|
||||||
|
ci, _ := cpu.Info()
|
||||||
|
for i := 0; i < len(ci); i++ {
|
||||||
|
cpuModelCount[ci[i].ModelName]++
|
||||||
|
}
|
||||||
|
var cpus []string
|
||||||
|
for model, count := range cpuModelCount {
|
||||||
|
cpus = append(cpus, fmt.Sprintf("%s %d %s Core", model, count, cpuType))
|
||||||
|
}
|
||||||
|
log.Println(cpus)
|
||||||
|
os.Exit(0)
|
||||||
|
// 硬盘信息,不使用的原因是会重复统计 Linux、Mac
|
||||||
dparts, _ := disk.Partitions(false)
|
dparts, _ := disk.Partitions(false)
|
||||||
for _, part := range dparts {
|
for _, part := range dparts {
|
||||||
u, _ := disk.Usage(part.Mountpoint)
|
u, _ := disk.Usage(part.Mountpoint)
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
pb "github.com/naiba/nezha/proto"
|
pb "github.com/naiba/nezha/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -85,22 +83,10 @@ func (h *Host) PB() *pb.Host {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func PB2Host(h *pb.Host) Host {
|
func PB2Host(h *pb.Host) Host {
|
||||||
|
|
||||||
cpuCount := make(map[string]int, 0)
|
|
||||||
cpus := h.GetCpu()
|
|
||||||
for _, u := range cpus {
|
|
||||||
cpuCount[u]++
|
|
||||||
}
|
|
||||||
|
|
||||||
var distCpu []string
|
|
||||||
for u, num := range cpuCount {
|
|
||||||
distCpu = append(distCpu, fmt.Sprintf("%sx%d", u, num))
|
|
||||||
}
|
|
||||||
|
|
||||||
return Host{
|
return Host{
|
||||||
Platform: h.GetPlatform(),
|
Platform: h.GetPlatform(),
|
||||||
PlatformVersion: h.GetPlatformVersion(),
|
PlatformVersion: h.GetPlatformVersion(),
|
||||||
CPU: distCpu,
|
CPU: h.GetCpu(),
|
||||||
MemTotal: h.GetMemTotal(),
|
MemTotal: h.GetMemTotal(),
|
||||||
DiskTotal: h.GetDiskTotal(),
|
DiskTotal: h.GetDiskTotal(),
|
||||||
SwapTotal: h.GetSwapTotal(),
|
SwapTotal: h.GetSwapTotal(),
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"time"
|
"time"
|
||||||
@ -25,5 +26,10 @@ type Server struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s Server) Marshal() template.JS {
|
func (s Server) Marshal() template.JS {
|
||||||
return template.JS(fmt.Sprintf(`{"ID":%d,"Name":"%s","Secret":"%s","DisplayIndex":%d,"Tag":"%s","Note":"%s"}`, s.ID, s.Name, s.Secret, s.DisplayIndex, s.Tag, s.Note))
|
name, _ := json.Marshal(s.Name)
|
||||||
|
tag, _ := json.Marshal(s.Tag)
|
||||||
|
note, _ := json.Marshal(s.Note)
|
||||||
|
secret, _ := json.Marshal(s.Secret)
|
||||||
|
return template.JS(fmt.Sprintf(`{"ID":%d,"Name":%s,"Secret":%s,"DisplayIndex":%d,"Tag":%s,"Note":%s}`,
|
||||||
|
s.ID, name, secret, s.DisplayIndex, tag, note))
|
||||||
}
|
}
|
||||||
|
27
model/server_test.go
Normal file
27
model/server_test.go
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestServerMarshal(t *testing.T) {
|
||||||
|
patterns := []string{
|
||||||
|
"asd > asd",
|
||||||
|
"asd \" asd",
|
||||||
|
"asd } asd",
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < len(patterns); i++ {
|
||||||
|
server := Server{
|
||||||
|
Name: patterns[i],
|
||||||
|
Tag: patterns[i],
|
||||||
|
}
|
||||||
|
serverStr := string(server.Marshal())
|
||||||
|
var serverRestore Server
|
||||||
|
assert.Nil(t, json.Unmarshal([]byte(serverStr), &serverRestore))
|
||||||
|
assert.Equal(t, server, serverRestore)
|
||||||
|
}
|
||||||
|
}
|
2
resource/template/common/menu.html
vendored
2
resource/template/common/menu.html
vendored
@ -40,7 +40,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{else}}
|
{{else}}
|
||||||
<a href="/login" class="ui large teal button">登录</a>
|
<a href="/login" class="ui large teal button"><i class="sign-in icon"></i>登录</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -10,7 +10,7 @@ NZ_BASE_PATH="/opt/nezha"
|
|||||||
NZ_DASHBOARD_PATH="${NZ_BASE_PATH}/dashboard"
|
NZ_DASHBOARD_PATH="${NZ_BASE_PATH}/dashboard"
|
||||||
NZ_AGENT_PATH="${NZ_BASE_PATH}/agent"
|
NZ_AGENT_PATH="${NZ_BASE_PATH}/agent"
|
||||||
NZ_AGENT_SERVICE="/etc/systemd/system/nezha-agent.service"
|
NZ_AGENT_SERVICE="/etc/systemd/system/nezha-agent.service"
|
||||||
NZ_VERSION="v0.4.6"
|
NZ_VERSION="v0.4.7"
|
||||||
|
|
||||||
red='\033[0;31m'
|
red='\033[0;31m'
|
||||||
green='\033[0;32m'
|
green='\033[0;32m'
|
||||||
@ -149,12 +149,12 @@ install_dashboard() {
|
|||||||
command -v docker-compose >/dev/null 2>&1
|
command -v docker-compose >/dev/null 2>&1
|
||||||
if [[ $? != 0 ]]; then
|
if [[ $? != 0 ]]; then
|
||||||
echo -e "正在安装 Docker Compose"
|
echo -e "正在安装 Docker Compose"
|
||||||
wget -O /usr/local/bin/docker-compose "https://${GITHUB_URL}/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" >/dev/null 2>&1 &&
|
wget -O /usr/local/bin/docker-compose "https://${GITHUB_URL}/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" >/dev/null 2>&1
|
||||||
chmod +x /usr/local/bin/docker-compose
|
|
||||||
if [[ $? != 0 ]]; then
|
if [[ $? != 0 ]]; then
|
||||||
echo -e "${red}下载脚本失败,请检查本机能否连接 ${GITHUB_URL}${plain}"
|
echo -e "${red}下载脚本失败,请检查本机能否连接 ${GITHUB_URL}${plain}"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
chmod +x /usr/local/bin/docker-compose
|
||||||
echo -e "${green}Docker Compose${plain} 安装成功"
|
echo -e "${green}Docker Compose${plain} 安装成功"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
pb "github.com/naiba/nezha/proto"
|
pb "github.com/naiba/nezha/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Version = "v0.4.9" // !!记得修改 README 重的 badge 版本!!
|
var Version = "v0.4.11" // !!记得修改 README 重的 badge 版本!!
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SnapshotDelay = 3
|
SnapshotDelay = 3
|
||||||
|
@ -28,10 +28,20 @@ var netInSpeed, netOutSpeed, netInTransfer, netOutTransfer, lastUpdate uint64
|
|||||||
|
|
||||||
func GetHost() *model.Host {
|
func GetHost() *model.Host {
|
||||||
hi, _ := host.Info()
|
hi, _ := host.Info()
|
||||||
var cpus []string
|
var cpuType string
|
||||||
|
if hi.VirtualizationSystem != "" {
|
||||||
|
cpuType = "Virtual"
|
||||||
|
} else {
|
||||||
|
cpuType = "Physical"
|
||||||
|
}
|
||||||
|
cpuModelCount := make(map[string]int)
|
||||||
ci, _ := cpu.Info()
|
ci, _ := cpu.Info()
|
||||||
for i := 0; i < len(ci); i++ {
|
for i := 0; i < len(ci); i++ {
|
||||||
cpus = append(cpus, fmt.Sprintf("%v-%vC%vT", ci[i].ModelName, ci[i].Cores, ci[i].Stepping))
|
cpuModelCount[ci[i].ModelName]++
|
||||||
|
}
|
||||||
|
var cpus []string
|
||||||
|
for model, count := range cpuModelCount {
|
||||||
|
cpus = append(cpus, fmt.Sprintf("%s %d %s Core", model, count, cpuType))
|
||||||
}
|
}
|
||||||
mv, _ := mem.VirtualMemory()
|
mv, _ := mem.VirtualMemory()
|
||||||
ms, _ := mem.SwapMemory()
|
ms, _ := mem.SwapMemory()
|
||||||
@ -47,8 +57,12 @@ func GetHost() *model.Host {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
body, _ := ioutil.ReadAll(resp.Body)
|
body, _ := ioutil.ReadAll(resp.Body)
|
||||||
|
if ip.IP == "" {
|
||||||
|
ip.IP = string(body)
|
||||||
|
} else {
|
||||||
ip.IP = fmt.Sprintf("ip(v4: %s, v6: %s)", ip.IP, body)
|
ip.IP = fmt.Sprintf("ip(v4: %s, v6: %s)", ip.IP, body)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return &model.Host{
|
return &model.Host{
|
||||||
Platform: hi.OS,
|
Platform: hi.OS,
|
||||||
PlatformVersion: hi.PlatformVersion,
|
PlatformVersion: hi.PlatformVersion,
|
||||||
|
@ -26,7 +26,7 @@ func (s *NezhaHandler) ReportTask(c context.Context, r *pb.TaskResult) (*pb.Rece
|
|||||||
var errMsg string
|
var errMsg string
|
||||||
if strings.HasPrefix(r.GetData(), "SSL证书错误:") {
|
if strings.HasPrefix(r.GetData(), "SSL证书错误:") {
|
||||||
// 排除超时错误
|
// 排除超时错误
|
||||||
if !strings.HasSuffix(r.GetData(), "i/o timeout") {
|
if !strings.HasSuffix(r.GetData(), "timeout") {
|
||||||
errMsg = r.GetData()
|
errMsg = r.GetData()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user