This commit is contained in:
parent
79476151b5
commit
673e3ea0b2
1 changed files with 19 additions and 0 deletions
|
@ -20,6 +20,7 @@ const (
|
||||||
hosnameFile = "/etc/hostname"
|
hosnameFile = "/etc/hostname"
|
||||||
osRealeaseFile = "/etc/os-release"
|
osRealeaseFile = "/etc/os-release"
|
||||||
versionFile = "/proc/version"
|
versionFile = "/proc/version"
|
||||||
|
machineIDFile = "/etc/machine-id"
|
||||||
)
|
)
|
||||||
|
|
||||||
var labels = []string{
|
var labels = []string{
|
||||||
|
@ -28,6 +29,7 @@ var labels = []string{
|
||||||
"os",
|
"os",
|
||||||
"distro",
|
"distro",
|
||||||
"distro_version",
|
"distro_version",
|
||||||
|
"machine_id",
|
||||||
}
|
}
|
||||||
|
|
||||||
type SysinfoCollector struct {
|
type SysinfoCollector struct {
|
||||||
|
@ -36,10 +38,12 @@ type SysinfoCollector struct {
|
||||||
os string
|
os string
|
||||||
distro string
|
distro string
|
||||||
distroVersion string
|
distroVersion string
|
||||||
|
machineID string
|
||||||
|
|
||||||
hostnameFile string
|
hostnameFile string
|
||||||
osReleaseFile string
|
osReleaseFile string
|
||||||
versionFile string
|
versionFile string
|
||||||
|
machineIDFile string
|
||||||
|
|
||||||
promExporter *prometheus.GaugeVec
|
promExporter *prometheus.GaugeVec
|
||||||
updateFreq time.Duration
|
updateFreq time.Duration
|
||||||
|
@ -57,6 +61,7 @@ func (c *SysinfoCollector) labels() prometheus.Labels {
|
||||||
"os": c.os,
|
"os": c.os,
|
||||||
"distro": c.distro,
|
"distro": c.distro,
|
||||||
"distro_version": c.distroVersion,
|
"distro_version": c.distroVersion,
|
||||||
|
"machine_id": c.machineID,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,6 +116,16 @@ func (c *SysinfoCollector) updateDistro() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *SysinfoCollector) updateMachineID() error {
|
||||||
|
machineIDContent, err := os.ReadFile(c.machineIDFile)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
c.machineID = strings.TrimSpace(string(machineIDContent))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c *SysinfoCollector) update() error {
|
func (c *SysinfoCollector) update() error {
|
||||||
if err := c.updateKernelVersion(); err != nil {
|
if err := c.updateKernelVersion(); err != nil {
|
||||||
return fmt.Errorf("failed to get kernel version: %w", err)
|
return fmt.Errorf("failed to get kernel version: %w", err)
|
||||||
|
@ -121,6 +136,9 @@ func (c *SysinfoCollector) update() error {
|
||||||
if err := c.updateDistro(); err != nil {
|
if err := c.updateDistro(); err != nil {
|
||||||
return fmt.Errorf("failed to get distro info: %w", err)
|
return fmt.Errorf("failed to get distro info: %w", err)
|
||||||
}
|
}
|
||||||
|
if err := c.updateMachineID(); err != nil {
|
||||||
|
return fmt.Errorf("failed to get machine-id: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
c.promExporter.With(c.labels()).Set(1)
|
c.promExporter.With(c.labels()).Set(1)
|
||||||
return nil
|
return nil
|
||||||
|
@ -158,6 +176,7 @@ func New() *SysinfoCollector {
|
||||||
hostnameFile: hosnameFile,
|
hostnameFile: hosnameFile,
|
||||||
osReleaseFile: osRealeaseFile,
|
osReleaseFile: osRealeaseFile,
|
||||||
versionFile: versionFile,
|
versionFile: versionFile,
|
||||||
|
machineIDFile: machineIDFile,
|
||||||
promExporter: prometheus.NewGaugeVec(prometheus.GaugeOpts{Namespace: "system", Name: "info", Help: "System global information"}, labels),
|
promExporter: prometheus.NewGaugeVec(prometheus.GaugeOpts{Namespace: "system", Name: "info", Help: "System global information"}, labels),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue