-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve systemd configuration and metric names (#3974)
upgrade: - Update to the configuration of the systemd check: ``unit_names`` is now required and only matching units will be monitored, ``unit_regexes`` configuration has been removed. - Several metrics sent by the systemd check have been renamed. The integration is now stable. enhancements: - Add `private_socket` configuration to the systemd check. Defaults to `/run/systemd/private` (or `/host/run/systemd/private` when using Docker Agent).
- Loading branch information
1 parent
3ab2c2b
commit dad4b81
Showing
6 changed files
with
386 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed | ||
// under the Apache License Version 2.0. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// This file includes software developed at CoreOS, Inc (http://www.coreos.com/). | ||
|
||
// Copyright 2016-2019 Datadog, Inc. | ||
// Copyright 2015 CoreOS, Inc. | ||
// | ||
// Use of this source code is governed by Apache License 2.0 | ||
// license that can be found here: https://github.com/coreos/go-systemd/blob/master/LICENSE | ||
|
||
// +build systemd | ||
|
||
package systemd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strconv" | ||
|
||
"github.com/coreos/go-systemd/dbus" | ||
godbus "github.com/godbus/dbus" | ||
) | ||
|
||
// NewSystemdConnection establishes a private, direct connection to systemd. | ||
// This can be used for communicating with systemd without a dbus daemon. | ||
// Callers should call Close() when done with the connection. | ||
// Note: method borrowed from `go-systemd/dbus` to provide custom path for systemd private socket | ||
// Source: https://github.com/coreos/go-systemd/blob/master/dbus/dbus.go | ||
func NewSystemdConnection(privateSocket string) (*dbus.Conn, error) { | ||
return dbus.NewConnection(func() (*godbus.Conn, error) { | ||
// We skip Hello when talking directly to systemd. | ||
return dbusAuthConnection(func() (*godbus.Conn, error) { | ||
return godbus.Dial(fmt.Sprintf("unix:path=%s", privateSocket)) | ||
}) | ||
}) | ||
} | ||
|
||
// Note: method borrowed from `go-systemd/dbus` to provide custom path for systemd private socket | ||
// Source: https://github.com/coreos/go-systemd/blob/master/dbus/dbus.go | ||
func dbusAuthConnection(createBus func() (*godbus.Conn, error)) (*godbus.Conn, error) { | ||
conn, err := createBus() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// Only use EXTERNAL method, and hardcode the uid (not username) | ||
// to avoid a username lookup (which requires a dynamically linked | ||
// libc) | ||
methods := []godbus.Auth{godbus.AuthExternal(strconv.Itoa(os.Getuid()))} | ||
|
||
err = conn.Auth(methods) | ||
if err != nil { | ||
conn.Close() | ||
return nil, err | ||
} | ||
|
||
return conn, nil | ||
} |
Oops, something went wrong.