Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

disable logind on systemd 239 by default #1452

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions agent/confgroup/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"regexp"
"strings"

"github.com/netdata/go.d.plugin/agent/hostinfo"
"github.com/netdata/go.d.plugin/agent/module"

"github.com/ilyam8/hashstructure"
Expand Down Expand Up @@ -99,7 +100,7 @@ func firstPositive(value int, others ...int) int {
}

func urlResolveHostname(rawURL string) string {
if hostname == "" || !strings.Contains(rawURL, "hostname") {
if hostinfo.Hostname == "" || !strings.Contains(rawURL, "hostname") {
return rawURL
}

Expand All @@ -108,19 +109,19 @@ func urlResolveHostname(rawURL string) string {
return rawURL
}

u.Host = strings.Replace(u.Host, "hostname", hostname, 1)
u.Host = strings.Replace(u.Host, "hostname", hostinfo.Hostname, 1)

return u.String()
}

func jobNameResolveHostname(name string) string {
if hostname == "" || !strings.Contains(name, "hostname") {
if hostinfo.Hostname == "" || !strings.Contains(name, "hostname") {
return name
}

if name != "hostname" && !strings.HasPrefix(name, "hostname.") && !strings.HasPrefix(name, "hostname_") {
return name
}

return strings.Replace(name, "hostname", hostname, 1)
return strings.Replace(name, "hostname", hostinfo.Hostname, 1)
}
10 changes: 7 additions & 3 deletions agent/confgroup/hostname.go → agent/hostinfo/hostinfo.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package confgroup
// SPDX-License-Identifier: GPL-3.0-or-later

package hostinfo

import (
"bytes"
Expand All @@ -7,7 +9,9 @@ import (
"time"
)

var hostname = func() string {
var Hostname = getHostname()

func getHostname() string {
path, err := exec.LookPath("hostname")
if err != nil {
return ""
Expand All @@ -22,4 +26,4 @@ var hostname = func() string {
}

return string(bytes.TrimSpace(bs))
}()
}
7 changes: 7 additions & 0 deletions agent/hostinfo/hostinfo_common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later

//go:build !linux

package hostinfo

var SystemdVersion int
42 changes: 42 additions & 0 deletions agent/hostinfo/hostinfo_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// SPDX-License-Identifier: GPL-3.0-or-later

//go:build linux

package hostinfo

import (
"context"
"regexp"
"strconv"

"github.com/coreos/go-systemd/v22/dbus"
)

var SystemdVersion = getSystemdVersion()

func getSystemdVersion() int {
var reVersion = regexp.MustCompile(`[0-9][0-9][0-9]`)

conn, err := dbus.NewWithContext(context.Background())
if err != nil {
return 0
}
defer conn.Close()

version, err := conn.GetManagerProperty("Version")
if err != nil {
return 0
}

major := reVersion.FindString(version)
if major == "" {
return 0
}

ver, err := strconv.Atoi(major)
if err != nil {
return 0
}

return ver
}
20 changes: 13 additions & 7 deletions agent/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/netdata/go.d.plugin/agent/discovery"
"github.com/netdata/go.d.plugin/agent/discovery/dummy"
"github.com/netdata/go.d.plugin/agent/discovery/file"
"github.com/netdata/go.d.plugin/agent/hostinfo"
"github.com/netdata/go.d.plugin/agent/module"
"github.com/netdata/go.d.plugin/agent/vnodes"

Expand Down Expand Up @@ -54,17 +55,22 @@ func (a *Agent) loadEnabledModules(cfg config) module.Registry {
if !all && a.RunModule != name {
continue
}
if all && creator.Disabled && !cfg.isExplicitlyEnabled(name) {
a.Infof("'%s' module disabled by default, should be explicitly enabled in the config", name)
continue
}
if all && !cfg.isImplicitlyEnabled(name) {
a.Infof("'%s' module disabled in the config file", name)
continue
if all {
// Known issue: go.d/logind high CPU usage on Alma Linux8 (https://github.com/netdata/netdata/issues/15930)
if !cfg.isExplicitlyEnabled(name) && (creator.Disabled || name == "logind" && hostinfo.SystemdVersion == 239) {
a.Infof("'%s' module disabled by default, should be explicitly enabled in the config", name)
continue
}
if !cfg.isImplicitlyEnabled(name) {
a.Infof("'%s' module disabled in the config file", name)
continue
}
}
enabled[name] = creator
}

a.Infof("enabled/registered modules: %d/%d", len(enabled), len(a.ModuleRegistry))

return enabled
}

Expand Down
Loading