github.com/netdata/go.d.plugin@v0.58.1/modules/phpfpm/init.go (about)

     1  // SPDX-License-Identifier: GPL-3.0-or-later
     2  
     3  package phpfpm
     4  
     5  import (
     6  	"errors"
     7  	"fmt"
     8  	"os"
     9  
    10  	"github.com/netdata/go.d.plugin/pkg/web"
    11  )
    12  
    13  func (p Phpfpm) initClient() (client, error) {
    14  	if p.Socket != "" {
    15  		return p.initSocketClient()
    16  	}
    17  	if p.Address != "" {
    18  		return p.initTcpClient()
    19  	}
    20  	if p.URL != "" {
    21  		return p.initHTTPClient()
    22  	}
    23  	return nil, errors.New("neither 'socket' nor 'url' set")
    24  }
    25  
    26  func (p Phpfpm) initHTTPClient() (*httpClient, error) {
    27  	c, err := web.NewHTTPClient(p.Client)
    28  	if err != nil {
    29  		return nil, fmt.Errorf("create HTTP client: %v", err)
    30  	}
    31  	p.Debugf("using HTTP client, URL: %s", p.URL)
    32  	p.Debugf("using timeout: %s", p.Timeout.Duration)
    33  	return newHTTPClient(c, p.Request)
    34  }
    35  
    36  func (p Phpfpm) initSocketClient() (*socketClient, error) {
    37  	if _, err := os.Stat(p.Socket); err != nil {
    38  		return nil, fmt.Errorf("the socket '%s' does not exist: %v", p.Socket, err)
    39  	}
    40  	p.Debugf("using socket client: %s", p.Socket)
    41  	p.Debugf("using timeout: %s", p.Timeout.Duration)
    42  	p.Debugf("using fcgi path: %s", p.FcgiPath)
    43  	return newSocketClient(p.Socket, p.Timeout.Duration, p.FcgiPath), nil
    44  }
    45  
    46  func (p Phpfpm) initTcpClient() (*tcpClient, error) {
    47  	p.Debugf("using tcp client: %s", p.Address)
    48  	p.Debugf("using timeout: %s", p.Timeout.Duration)
    49  	p.Debugf("using fcgi path: %s", p.FcgiPath)
    50  	return newTcpClient(p.Address, p.Timeout.Duration, p.FcgiPath), nil
    51  }