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

     1  // SPDX-License-Identifier: GPL-3.0-or-later
     2  
     3  package phpfpm
     4  
     5  import (
     6  	_ "embed"
     7  	"time"
     8  
     9  	"github.com/netdata/go.d.plugin/pkg/web"
    10  
    11  	"github.com/netdata/go.d.plugin/agent/module"
    12  )
    13  
    14  //go:embed "config_schema.json"
    15  var configSchema string
    16  
    17  func init() {
    18  	module.Register("phpfpm", module.Creator{
    19  		JobConfigSchema: configSchema,
    20  		Create:          func() module.Module { return New() },
    21  	})
    22  }
    23  
    24  func New() *Phpfpm {
    25  	return &Phpfpm{
    26  		Config: Config{
    27  			HTTP: web.HTTP{
    28  				Request: web.Request{
    29  					URL: "http://127.0.0.1/status?full&json",
    30  				},
    31  				Client: web.Client{
    32  					Timeout: web.Duration{Duration: time.Second},
    33  				},
    34  			},
    35  			FcgiPath: "/status",
    36  		},
    37  	}
    38  }
    39  
    40  type (
    41  	Config struct {
    42  		web.HTTP `yaml:",inline"`
    43  		Socket   string `yaml:"socket"`
    44  		Address  string `yaml:"address"`
    45  		FcgiPath string `yaml:"fcgi_path"`
    46  	}
    47  	Phpfpm struct {
    48  		module.Base
    49  		Config `yaml:",inline"`
    50  
    51  		client client
    52  	}
    53  )
    54  
    55  func (p *Phpfpm) Init() bool {
    56  	c, err := p.initClient()
    57  	if err != nil {
    58  		p.Errorf("init client: %v", err)
    59  		return false
    60  	}
    61  	p.client = c
    62  	return true
    63  }
    64  
    65  func (p *Phpfpm) Check() bool {
    66  	return len(p.Collect()) > 0
    67  }
    68  
    69  func (Phpfpm) Charts() *Charts {
    70  	return charts.Copy()
    71  }
    72  
    73  func (p *Phpfpm) Collect() map[string]int64 {
    74  	mx, err := p.collect()
    75  	if err != nil {
    76  		p.Error(err)
    77  	}
    78  
    79  	if len(mx) == 0 {
    80  		return nil
    81  	}
    82  	return mx
    83  }
    84  
    85  func (Phpfpm) Cleanup() {}