master
go 47 lines 862 Bytes
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 package uwsgi
4
5 import (
6 "bytes"
7 "time"
8
9 "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/socket"
10 )
11
12 type uwsgiConn interface {
13 queryStats() ([]byte, error)
14 }
15
16 func newUwsgiConn(conf Config) uwsgiConn {
17 return &uwsgiClient{
18 address: conf.Address,
19 timeout: conf.Timeout.Duration(),
20 }
21 }
22
23 type uwsgiClient struct {
24 address string
25 timeout time.Duration
26 }
27
28 func (c *uwsgiClient) queryStats() ([]byte, error) {
29 var b bytes.Buffer
30
31 cfg := socket.Config{
32 Address: c.address,
33 Timeout: c.timeout,
34 MaxReadLines: 1000 * 10,
35 }
36
37 if err := socket.ConnectAndRead(cfg, func(bs []byte) (bool, error) {
38 b.Write(bs)
39 b.WriteByte('\n')
40 // The server will close the connection when it has finished sending data.
41 return true, nil
42 }); err != nil {
43 return nil, err
44 }
45
46 return b.Bytes(), nil
47 }