1 Star 0 Fork 0

chenhuxy / logstash_exporter

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
nodeinfo_collector.go 2.11 KB
一键复制 编辑 原始数据 按行查看 历史
package collector
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/log"
"strconv"
)
// NodeInfoCollector type
type NodeInfoCollector struct {
endpoint string
NodeInfos *prometheus.Desc
OsInfos *prometheus.Desc
JvmInfos *prometheus.Desc
}
// NewNodeInfoCollector function
func NewNodeInfoCollector(logstashEndpoint string) (Collector, error) {
const subsystem = "info"
return &NodeInfoCollector{
endpoint: logstashEndpoint,
NodeInfos: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "node"),
"A metric with a constant '1' value labeled by Logstash version.",
[]string{"version"},
nil,
),
OsInfos: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "os"),
"A metric with a constant '1' value labeled by name, arch, version and available_processors to the OS running Logstash.",
[]string{"name", "arch", "version", "available_processors"},
nil,
),
JvmInfos: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "jvm"),
"A metric with a constant '1' value labeled by name, version and vendor of the JVM running Logstash.",
[]string{"name", "version", "vendor"},
nil,
),
}, nil
}
// Collect function implements nodestats_collector collector
func (c *NodeInfoCollector) Collect(ch chan<- prometheus.Metric) error {
if desc, err := c.collect(ch); err != nil {
log.Error("Failed collecting info metrics", desc, err)
return err
}
return nil
}
func (c *NodeInfoCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
stats, err := NodeInfo(c.endpoint)
if err != nil {
return nil, err
}
ch <- prometheus.MustNewConstMetric(
c.NodeInfos,
prometheus.CounterValue,
float64(1),
stats.Version,
)
ch <- prometheus.MustNewConstMetric(
c.OsInfos,
prometheus.CounterValue,
float64(1),
stats.Os.Name,
stats.Os.Arch,
stats.Os.Version,
strconv.Itoa(stats.Os.AvailableProcessors),
)
ch <- prometheus.MustNewConstMetric(
c.JvmInfos,
prometheus.CounterValue,
float64(1),
stats.Jvm.VMName,
stats.Jvm.VMVersion,
stats.Jvm.VMVendor,
)
return nil, nil
}
1
https://gitee.com/chenhuxy/logstash_exporter.git
git@gitee.com:chenhuxy/logstash_exporter.git
chenhuxy
logstash_exporter
logstash_exporter
v0.1.2

搜索帮助