代码拉取完成,页面将自动刷新
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
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。