1 Star 0 Fork 0

zhangjungang/beats

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
info.go 1.61 KB
一键复制 编辑 原始数据 按行查看 历史
package info
import (
"time"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/logp"
"github.com/elastic/beats/metricbeat/mb"
"github.com/elastic/beats/metricbeat/mb/parse"
"github.com/elastic/beats/metricbeat/module/redis"
rd "github.com/garyburd/redigo/redis"
)
var (
debugf = logp.MakeDebug("redis-info")
)
func init() {
if err := mb.Registry.AddMetricSet("redis", "info", New, parse.PassThruHostParser); err != nil {
panic(err)
}
}
// MetricSet for fetching Redis server information and statistics.
type MetricSet struct {
mb.BaseMetricSet
pool *rd.Pool
}
// New creates new instance of MetricSet
func New(base mb.BaseMetricSet) (mb.MetricSet, error) {
// Unpack additional configuration options.
config := struct {
IdleTimeout time.Duration `config:"idle_timeout"`
Network string `config:"network"`
MaxConn int `config:"maxconn" validate:"min=1"`
Password string `config:"password"`
}{
Network: "tcp",
MaxConn: 10,
Password: "",
}
err := base.Module().UnpackConfig(&config)
if err != nil {
return nil, err
}
return &MetricSet{
BaseMetricSet: base,
pool: redis.CreatePool(base.Host(), config.Password, config.Network,
config.MaxConn, config.IdleTimeout, base.Module().Config().Timeout),
}, nil
}
// Fetch fetches metrics from Redis by issuing the INFO command.
func (m *MetricSet) Fetch() (common.MapStr, error) {
// Fetch default INFO.
info, err := redis.FetchRedisInfo("default", m.pool.Get())
if err != nil {
return nil, err
}
debugf("Redis INFO from %s: %+v", m.Host(), info)
return eventMapping(info), nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhangjungang/beats.git
git@gitee.com:zhangjungang/beats.git
zhangjungang
beats
beats
v6.1.2

搜索帮助

0d507c66 1850385 C8b1a773 1850385