Merge pull request #470 from sll552/add_hostname

Add collector for hostname information
This commit is contained in:
Calle Pettersson
2020-03-02 07:40:11 +01:00
committed by GitHub
2 changed files with 30 additions and 0 deletions

View File

@@ -18,6 +18,7 @@ func init() {
type CSCollector struct { type CSCollector struct {
PhysicalMemoryBytes *prometheus.Desc PhysicalMemoryBytes *prometheus.Desc
LogicalProcessors *prometheus.Desc LogicalProcessors *prometheus.Desc
Hostname *prometheus.Desc
} }
// NewCSCollector ... // NewCSCollector ...
@@ -37,6 +38,15 @@ func NewCSCollector() (Collector, error) {
nil, nil,
nil, nil,
), ),
Hostname: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "hostname"),
"Labeled system hostname information as provided by ComputerSystem.DNSHostName and ComputerSystem.Domain",
[]string{
"hostname",
"domain",
"fqdn"},
nil,
),
}, nil }, nil
} }
@@ -55,6 +65,9 @@ func (c *CSCollector) Collect(ctx *ScrapeContext, ch chan<- prometheus.Metric) e
type Win32_ComputerSystem struct { type Win32_ComputerSystem struct {
NumberOfLogicalProcessors uint32 NumberOfLogicalProcessors uint32
TotalPhysicalMemory uint64 TotalPhysicalMemory uint64
DNSHostname string
Domain string
Workgroup string
} }
func (c *CSCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) { func (c *CSCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
@@ -79,5 +92,21 @@ func (c *CSCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, er
float64(dst[0].TotalPhysicalMemory), float64(dst[0].TotalPhysicalMemory),
) )
var fqdn string
if dst[0].Domain != dst[0].Workgroup {
fqdn = dst[0].DNSHostname + "." + dst[0].Domain
} else {
fqdn = dst[0].DNSHostname
}
ch <- prometheus.MustNewConstMetric(
c.Hostname,
prometheus.GaugeValue,
1.0,
dst[0].DNSHostname,
dst[0].Domain,
fqdn,
)
return nil, nil return nil, nil
} }

View File

@@ -18,6 +18,7 @@ Name | Description | Type | Labels
-----|-------------|------|------- -----|-------------|------|-------
`wmi_cs_logical_processors` | Number of installed logical processors | gauge | None `wmi_cs_logical_processors` | Number of installed logical processors | gauge | None
`wmi_cs_physical_memory_bytes` | Total installed physical memory | gauge | None `wmi_cs_physical_memory_bytes` | Total installed physical memory | gauge | None
`wmi_cs_hostname` | Labeled system hostname information | gauge | `hostname`, `domain`, `fqdn`
### Example metric ### Example metric
_This collector does not yet have explained examples, we would appreciate your help adding them!_ _This collector does not yet have explained examples, we would appreciate your help adding them!_