mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-02-12 07:56:38 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d9404c6cc2 | ||
|
|
af250824f7 | ||
|
|
7f57491fac | ||
|
|
890fdc2996 | ||
|
|
d1a807840c |
10
.promu.yml
10
.promu.yml
@@ -4,11 +4,11 @@ build:
|
|||||||
binaries:
|
binaries:
|
||||||
- name: wmi_exporter
|
- name: wmi_exporter
|
||||||
ldflags: |
|
ldflags: |
|
||||||
-X {{repoPath}}/vendor/github.com/prometheus/common/version.Version={{.Version}}
|
-X github.com/prometheus/common/version.Version={{.Version}}
|
||||||
-X {{repoPath}}/vendor/github.com/prometheus/common/version.Revision={{.Revision}}
|
-X github.com/prometheus/common/version.Revision={{.Revision}}
|
||||||
-X {{repoPath}}/vendor/github.com/prometheus/common/version.Branch={{.Branch}}
|
-X github.com/prometheus/common/version.Branch={{.Branch}}
|
||||||
-X {{repoPath}}/vendor/github.com/prometheus/common/version.BuildUser={{user}}@{{host}}
|
-X github.com/prometheus/common/version.BuildUser={{user}}@{{host}}
|
||||||
-X {{repoPath}}/vendor/github.com/prometheus/common/version.BuildDate={{date "20060102-15:04:05"}}
|
-X github.com/prometheus/common/version.BuildDate={{date "20060102-15:04:05"}}
|
||||||
tarball:
|
tarball:
|
||||||
files:
|
files:
|
||||||
- LICENSE
|
- LICENSE
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ type Win32_ComputerSystem struct {
|
|||||||
TotalPhysicalMemory uint64
|
TotalPhysicalMemory uint64
|
||||||
DNSHostname string
|
DNSHostname string
|
||||||
Domain string
|
Domain string
|
||||||
Workgroup 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) {
|
||||||
@@ -93,7 +93,7 @@ func (c *CSCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, er
|
|||||||
)
|
)
|
||||||
|
|
||||||
var fqdn string
|
var fqdn string
|
||||||
if dst[0].Domain != dst[0].Workgroup {
|
if dst[0].Workgroup == nil || dst[0].Domain != *dst[0].Workgroup {
|
||||||
fqdn = dst[0].DNSHostname + "." + dst[0].Domain
|
fqdn = dst[0].DNSHostname + "." + dst[0].Domain
|
||||||
} else {
|
} else {
|
||||||
fqdn = dst[0].DNSHostname
|
fqdn = dst[0].DNSHostname
|
||||||
|
|||||||
84
collector/terminal_services.go
Normal file
84
collector/terminal_services.go
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
// +build windows
|
||||||
|
|
||||||
|
package collector
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"github.com/StackExchange/wmi"
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/prometheus/common/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
registerCollector("terminal_services", NewTerminalServicesCollector)
|
||||||
|
}
|
||||||
|
|
||||||
|
// A TerminalServicesCollector is a Prometheus collector for WMI
|
||||||
|
// Win32_PerfRawData_LocalSessionManager_TerminalServices & Win32_PerfRawData_TermService_TerminalServicesSession metrics
|
||||||
|
type TerminalServicesCollector struct {
|
||||||
|
Local_session_count *prometheus.Desc
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewTerminalServicesCollector ...
|
||||||
|
func NewTerminalServicesCollector() (Collector, error) {
|
||||||
|
const subsystem = "terminal_services"
|
||||||
|
return &TerminalServicesCollector{
|
||||||
|
Local_session_count: prometheus.NewDesc(
|
||||||
|
prometheus.BuildFQName(Namespace, subsystem, "local_session_count"),
|
||||||
|
"Number of Terminal Services sessions",
|
||||||
|
[]string{"session"},
|
||||||
|
nil,
|
||||||
|
),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Collect sends the metric values for each metric
|
||||||
|
// to the provided prometheus Metric channel.
|
||||||
|
func (c *TerminalServicesCollector) Collect(ctx *ScrapeContext, ch chan<- prometheus.Metric) error {
|
||||||
|
if desc, err := c.collectTSSessionCount(ch); err != nil {
|
||||||
|
log.Error("failed collecting terminal services session count metrics:", desc, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type Win32_PerfRawData_LocalSessionManager_TerminalServices struct {
|
||||||
|
ActiveSessions uint32
|
||||||
|
InactiveSessions uint32
|
||||||
|
TotalSessions uint32
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *TerminalServicesCollector) collectTSSessionCount(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||||
|
var dst []Win32_PerfRawData_LocalSessionManager_TerminalServices
|
||||||
|
q := queryAll(&dst)
|
||||||
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(dst) == 0 {
|
||||||
|
return nil, errors.New("WMI query returned empty result set")
|
||||||
|
}
|
||||||
|
|
||||||
|
ch <- prometheus.MustNewConstMetric(
|
||||||
|
c.Local_session_count,
|
||||||
|
prometheus.GaugeValue,
|
||||||
|
float64(dst[0].ActiveSessions),
|
||||||
|
"active",
|
||||||
|
)
|
||||||
|
|
||||||
|
ch <- prometheus.MustNewConstMetric(
|
||||||
|
c.Local_session_count,
|
||||||
|
prometheus.GaugeValue,
|
||||||
|
float64(dst[0].InactiveSessions),
|
||||||
|
"inactive",
|
||||||
|
)
|
||||||
|
|
||||||
|
ch <- prometheus.MustNewConstMetric(
|
||||||
|
c.Local_session_count,
|
||||||
|
prometheus.GaugeValue,
|
||||||
|
float64(dst[0].TotalSessions),
|
||||||
|
"total",
|
||||||
|
)
|
||||||
|
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user