1 Star 0 Fork 0

sqos/beats

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
.github
auditbeat
deploy/kubernetes
dev-tools
docs/devguide
filebeat
generator
heartbeat
libbeat
metricbeat
_meta
beater
cmd
docs
helper
include
mb
module
aerospike
apache
ceph
couchbase
docker
dropwizard
elasticsearch
etcd
golang
graphite
haproxy
http
jolokia
kafka
kibana
kubernetes
logstash
memcached
mongodb
mysql
nginx
php_fpm
postgresql
prometheus
rabbitmq
redis
system
_meta
core
cpu
diskio
filesystem
fsstat
load
memory
network
process
process_summary
_meta
doc.go
process_summary.go
process_summary_test.go
raid
socket
uptime
doc.go
hostnamechange_test.go
module.yml
system.go
system_linux.go
system_other.go
system_windows.go
uwsgi
vsphere
windows
zookeeper
doc.go
plugin.go
modules.d
processor/add_kubernetes_metadata
scripts
tests/system
vendor
.gitignore
Dockerfile
Makefile
README.md
docker-compose.yml
main.go
main_test.go
make.bat
metricbeat.reference.yml
metricbeat.yml
packetbeat
script
testing/environments
vendor
winlogbeat
.appveyor.yml
.editorconfig
.gitattributes
.gitignore
.go-version
.pylintrc
.travis.yml
CHANGELOG.asciidoc
CONTRIBUTING.md
LICENSE.txt
Makefile
NOTICE.txt
README.md
Vagrantfile
codecov.yml
reviewdog.yml
setup.yml
克隆/下载
process_summary.go 2.47 KB
一键复制 编辑 原始数据 按行查看 历史
// +build darwin freebsd linux windows
package process_summary
import (
"github.com/pkg/errors"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/logp"
"github.com/elastic/beats/libbeat/metric/system/process"
"github.com/elastic/beats/metricbeat/mb"
"github.com/elastic/beats/metricbeat/mb/parse"
sigar "github.com/elastic/gosigar"
)
// init registers the MetricSet with the central registry.
// The New method will be called after the setup of the module and before starting to fetch data
func init() {
if err := mb.Registry.AddMetricSet("system", "process_summary", New, parse.EmptyHostParser); err != nil {
panic(err)
}
}
// MetricSet type defines all fields of the MetricSet
// As a minimum it must inherit the mb.BaseMetricSet fields, but can be extended with
// additional entries. These variables can be used to persist data or configuration between
// multiple fetch calls.
type MetricSet struct {
mb.BaseMetricSet
}
// New create a new instance of the MetricSet
// Part of new is also setting up the configuration by processing additional
// configuration entries if needed.
func New(base mb.BaseMetricSet) (mb.MetricSet, error) {
return &MetricSet{
BaseMetricSet: base,
}, nil
}
// Fetch methods implements the data gathering and data conversion to the right format
// It returns the event which is then forward to the output. In case of an error, a
// descriptive error must be returned.
func (m *MetricSet) Fetch() (common.MapStr, error) {
pids, err := process.Pids()
if err != nil {
return nil, errors.Wrap(err, "failed to fetch the list of PIDs")
}
var summary struct {
sleeping int
running int
idle int
stopped int
zombie int
unknown int
}
for _, pid := range pids {
state := sigar.ProcState{}
err = state.Get(pid)
if err != nil {
summary.unknown += 1
continue
}
switch byte(state.State) {
case 'S':
summary.sleeping++
case 'R':
summary.running++
case 'D':
summary.idle++
case 'T':
summary.stopped++
case 'Z':
summary.zombie++
default:
logp.Err("Unknown state <%v> for process with pid %d", state.State, pid)
summary.unknown++
}
}
event := common.MapStr{
"total": len(pids),
"sleeping": summary.sleeping,
"running": summary.running,
"idle": summary.idle,
"stopped": summary.stopped,
"zombie": summary.zombie,
"unknown": summary.unknown,
}
// change the name space to use . instead of _
event[mb.NamespaceKey] = "process.summary"
return event, nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sqos/beats.git
git@gitee.com:sqos/beats.git
sqos
beats
beats
v6.2.1

搜索帮助