代码拉取完成,页面将自动刷新
/*
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
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。