1 Star 0 Fork 0

sqos/beats

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
zookeeper.go 1.08 KB
一键复制 编辑 原始数据 按行查看 历史
/*
Package zookeeper is a Metricbeat module for ZooKeeper servers.
*/
package zookeeper
import (
"bytes"
"io"
"io/ioutil"
"net"
"time"
"github.com/pkg/errors"
)
// RunCommand establishes a TCP connection the ZooKeeper command port that
// accepts the four-letter ZooKeeper commands and sends the given command. It
// reads all response data received on the socket and returns an io.Reader
// containing that data.
func RunCommand(command, address string, timeout time.Duration) (io.Reader, error) {
conn, err := net.DialTimeout("tcp", address, timeout)
if err != nil {
return nil, errors.Wrapf(err, "connection to host '%s' failed", address)
}
defer conn.Close()
// Set read and write timeout.
err = conn.SetDeadline(time.Now().Add(timeout))
if err != nil {
return nil, err
}
// Write four-letter command.
_, err = conn.Write([]byte(command))
if err != nil {
return nil, errors.Wrapf(err, "writing command '%s' failed", command)
}
result, err := ioutil.ReadAll(conn)
if err != nil {
return nil, errors.Wrap(err, "read failed")
}
return bytes.NewReader(result), nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sqos/beats.git
git@gitee.com:sqos/beats.git
sqos
beats
beats
v5.5.2

搜索帮助