mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-02-04 12:40:07 +00:00
⚡️ improve: 服务监控相关优化
This commit is contained in:
@@ -15,6 +15,35 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
icmp()
|
||||
// tcpping()
|
||||
// httpWithSSLInfo()
|
||||
// diskinfo()
|
||||
}
|
||||
|
||||
func tcpping() {
|
||||
start := time.Now()
|
||||
conn, err := net.DialTimeout("tcp", "example.com:80", time.Second*10)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
conn.Write([]byte("ping\n"))
|
||||
conn.Close()
|
||||
fmt.Println(time.Now().Sub(start).Microseconds(), float32(time.Now().Sub(start).Microseconds())/1000.0)
|
||||
}
|
||||
|
||||
func diskinfo() {
|
||||
// 硬盘信息
|
||||
dparts, _ := disk.Partitions(false)
|
||||
for _, part := range dparts {
|
||||
u, _ := disk.Usage(part.Mountpoint)
|
||||
if u != nil {
|
||||
log.Printf("%s %d %d", part.Device, u.Total, u.Used)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func httpWithSSLInfo() {
|
||||
// 跳过 SSL 检查
|
||||
transCfg := &http.Transport{
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
@@ -25,31 +54,19 @@ func main() {
|
||||
// SSL 证书信息获取
|
||||
c := cert.NewCert("expired-ecc-dv.ssl.com")
|
||||
fmt.Println(c.Error)
|
||||
// TCP
|
||||
conn, err := net.DialTimeout("tcp", "example.com:80", time.Second*10)
|
||||
}
|
||||
|
||||
func icmp() {
|
||||
pinger, err := ping.NewPinger("10.10.10.2")
|
||||
if err != nil {
|
||||
panic(err) // Blocks until finished.
|
||||
}
|
||||
pinger.Count = 3000
|
||||
pinger.Timeout = 10 * time.Second
|
||||
if err = pinger.Run(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
println(conn)
|
||||
// ICMP Ping
|
||||
pinger, err := ping.NewPinger("example.com")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
pinger.Count = 3
|
||||
err = pinger.Run() // Blocks until finished.
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Printf("%+v", pinger.Statistics())
|
||||
// 硬盘信息
|
||||
dparts, _ := disk.Partitions(false)
|
||||
for _, part := range dparts {
|
||||
u, _ := disk.Usage(part.Mountpoint)
|
||||
if u != nil {
|
||||
log.Printf("%s %d %d", part.Device, u.Total, u.Used)
|
||||
}
|
||||
}
|
||||
fmt.Println(pinger.PacketsRecv, float32(pinger.Statistics().AvgRtt.Microseconds())/1000.0)
|
||||
}
|
||||
|
||||
func cmdExec() {
|
||||
|
||||
Reference in New Issue
Block a user