1 Star 0 Fork 0

sqos/beats

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
pool.go 1.41 KB
一键复制 编辑 原始数据 按行查看 历史
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
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sqos/beats.git
git@gitee.com:sqos/beats.git
sqos
beats
beats
v5.5.3

搜索帮助

0d507c66 1850385 C8b1a773 1850385