From 87d772a7d708fec12f48cd8adc0dedff6e1025da Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 26 Aug 2024 10:15:20 +0200 Subject: Adding upstream version 1.47.0. Signed-off-by: Daniel Baumann --- src/go/plugin/go.d/modules/uwsgi/client.go | 64 ++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/go/plugin/go.d/modules/uwsgi/client.go (limited to 'src/go/plugin/go.d/modules/uwsgi/client.go') diff --git a/src/go/plugin/go.d/modules/uwsgi/client.go b/src/go/plugin/go.d/modules/uwsgi/client.go new file mode 100644 index 000000000..403680743 --- /dev/null +++ b/src/go/plugin/go.d/modules/uwsgi/client.go @@ -0,0 +1,64 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +package uwsgi + +import ( + "bytes" + "fmt" + + "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/socket" +) + +type uwsgiConn interface { + connect() error + disconnect() + queryStats() ([]byte, error) +} + +func newUwsgiConn(conf Config) uwsgiConn { + return &uwsgiClient{conn: socket.New(socket.Config{ + Address: conf.Address, + ConnectTimeout: conf.Timeout.Duration(), + ReadTimeout: conf.Timeout.Duration(), + WriteTimeout: conf.Timeout.Duration(), + })} +} + +type uwsgiClient struct { + conn socket.Client +} + +func (c *uwsgiClient) connect() error { + return c.conn.Connect() +} + +func (c *uwsgiClient) disconnect() { + _ = c.conn.Disconnect() +} + +func (c *uwsgiClient) queryStats() ([]byte, error) { + var b bytes.Buffer + var n int64 + var err error + const readLineLimit = 1000 * 10 + + clientErr := c.conn.Command("", func(bs []byte) bool { + b.Write(bs) + b.WriteByte('\n') + + if n++; n >= readLineLimit { + err = fmt.Errorf("read line limit exceeded %d", readLineLimit) + return false + } + // The server will close the connection when it has finished sending data. + return true + }) + if clientErr != nil { + return nil, clientErr + } + if err != nil { + return nil, err + } + + return b.Bytes(), nil +} -- cgit v1.2.3