代码拉取完成,页面将自动刷新
package pool
import (
"encoding/json"
"fmt"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/logp"
"github.com/elastic/beats/metricbeat/helper"
"github.com/elastic/beats/metricbeat/mb"
"github.com/elastic/beats/metricbeat/mb/parse"
)
// init registers the MetricSet with the central registry.
func init() {
if err := mb.Registry.AddMetricSet("php_fpm", "pool", New, HostParser); err != nil {
panic(err)
}
}
const (
defaultScheme = "http"
defaultPath = "/status"
)
// HostParser is used for parsing the configured php-fpm hosts.
var HostParser = parse.URLHostParserBuilder{
DefaultScheme: defaultScheme,
DefaultPath: defaultPath,
QueryParams: "json",
PathConfigKey: "status_path",
}.Build()
// MetricSet type defines all fields of the MetricSet
type MetricSet struct {
mb.BaseMetricSet
*helper.HTTP
}
// New create a new instance of the MetricSet
func New(base mb.BaseMetricSet) (mb.MetricSet, error) {
logp.Warn("BETA: The php-fpm pool metricset is beta")
return &MetricSet{
base,
helper.NewHTTP(base),
}, nil
}
// Fetch gathers data for the pool metricset
func (m *MetricSet) Fetch() (common.MapStr, error) {
content, err := m.HTTP.FetchContent()
if err != nil {
return nil, err
}
var stats map[string]interface{}
err = json.Unmarshal(content, &stats)
if err != nil {
return nil, fmt.Errorf("error parsing json: %v", err)
}
return schema.Apply(stats), nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。