3

???? Pinger: 一个轻巧的 `ping` 探针,支持 ICMP/TCP/HTTP 协议

 1 year ago
source link: https://studygolang.com/articles/28546?fr=sidebar
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

???? Pinger: 一个轻巧的 `ping` 探针,支持 ICMP/TCP/HTTP 协议

chenjiandongx · 2020-05-09 20:44:13 · 1136 次点击 · 预计阅读时间 1 分钟 · 大约8小时之前 开始浏览    
这是一个创建于 2020-05-09 20:44:13 的文章,其中的信息可能已经有所发展或是发生改变。

Pinger

Pinger is a library used to evaluate the quality of services in ICMP/TCP/HTTP protocol.

???? Installation

$ go get -u github.com/chenjiangdongx/pinger

???? Usage

Here is an example. For more information, please refer to godoc.

package main

import (
    "fmt"

    "github.com/chenjiandongx/pinger"
)

func main() {
    // ICMP
    stats, err := pinger.ICMPPing(nil, "qq.com", "baidu.com", "114.114.114.114")

    // TCP
    // stats, err := pinger.TCPPing(nil, "baidu.com:80", "qq.com:80", "qq.com:443", "baidu.com:443")

    // HTTP/HTTPS
    // stats, err := pinger.HTTPPing(nil, "http://baidu.com", "https://baidu.com", "http://39.156.69.79")
    if err != nil {
        panic(err)
    }

    for _, s := range stats {
        fmt.Printf("%+v\n", s)
    }
}

// output
{Host:qq.com PktSent:10 PktLossRate:0 Mean:42.858058ms Last:39.66054ms Best:38.031497ms Worst:71.050511ms}
{Host:baidu.com PktSent:10 PktLossRate:0 Mean:45.834938ms Last:44.408987ms Best:40.155878ms Worst:75.480914ms}
{Host:114.114.114.114 PktSent:10 PktLossRate:0 Mean:10.953486ms Last:6.618554ms Best:5.407619ms Worst:38.53662ms}

项目地址:https://github.com/chenjiandongx/pinger


有疑问加站长微信联系(非本文作者))

280

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK