Skip to content
This repository was archived by the owner on Oct 23, 2024. It is now read-only.

Commit 25ddf91

Browse files
Ben Keithkeitwb
authored andcommitted
Add collectd/chrony monitor
1 parent a2e03fa commit 25ddf91

File tree

6 files changed

+130
-0
lines changed

6 files changed

+130
-0
lines changed

docs/monitor-config.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ along with their possible configuration options:
1111
- [collectd/activemq](./monitors/collectd-activemq.md)
1212
- [collectd/apache](./monitors/collectd-apache.md)
1313
- [collectd/cassandra](./monitors/collectd-cassandra.md)
14+
- [collectd/chrony](./monitors/collectd-chrony.md)
1415
- [collectd/consul](./monitors/collectd-consul.md)
1516
- [collectd/couchbase](./monitors/collectd-couchbase.md)
1617
- [collectd/cpu](./monitors/collectd-cpu.md)

docs/monitors/collectd-chrony.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!--- GENERATED BY gomplate from scripts/docs/monitor-page.md.tmpl --->
2+
3+
# collectd/chrony
4+
5+
Collectd NTP data from a chronyd instance
6+
7+
See https://collectd.org/documentation/manpages/collectd.conf.5.shtml#plugin_chrony
8+
9+
10+
Monitor Type: `collectd/chrony`
11+
12+
[Monitor Source Code](https://github.com/signalfx/signalfx-agent/tree/master/internal/monitors/collectd/chrony)
13+
14+
**Accepts Endpoints**: No
15+
16+
**Multiple Instances Allowed**: **No**
17+
18+
## Configuration
19+
20+
| Config option | Required | Type | Description |
21+
| --- | --- | --- | --- |
22+
| `host` | **yes** | `string` | The hostname of the chronyd instance |
23+
| `port` | no | `integer` | The UDP port number of the chronyd instance. Defaults to 323 in collectd if unspecified. |
24+
| `timeout` | no | `unsigned integer` | How long to wait for a response from chronyd before considering it down. Defaults to 2 seconds in the collectd plugin if not specified |
25+
26+
27+
28+
29+
30+

internal/core/modules_collectd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
_ "github.com/signalfx/signalfx-agent/internal/monitors/collectd/activemq"
1111
_ "github.com/signalfx/signalfx-agent/internal/monitors/collectd/apache"
1212
_ "github.com/signalfx/signalfx-agent/internal/monitors/collectd/cassandra"
13+
_ "github.com/signalfx/signalfx-agent/internal/monitors/collectd/chrony"
1314
_ "github.com/signalfx/signalfx-agent/internal/monitors/collectd/consul"
1415
_ "github.com/signalfx/signalfx-agent/internal/monitors/collectd/couchbase"
1516
_ "github.com/signalfx/signalfx-agent/internal/monitors/collectd/cpu"
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// +build !windows
2+
3+
package chrony
4+
5+
//go:generate collectd-template-to-go chrony.tmpl
6+
7+
import (
8+
"github.com/signalfx/signalfx-agent/internal/core/config"
9+
"github.com/signalfx/signalfx-agent/internal/monitors"
10+
"github.com/signalfx/signalfx-agent/internal/monitors/collectd"
11+
)
12+
13+
const monitorType = "collectd/chrony"
14+
15+
// MONITOR(collectd/chrony): Collectd NTP data from a chronyd instance
16+
//
17+
// See https://collectd.org/documentation/manpages/collectd.conf.5.shtml#plugin_chrony
18+
19+
func init() {
20+
monitors.Register(monitorType, func() interface{} {
21+
return &Monitor{
22+
MonitorCore: *collectd.NewMonitorCore(CollectdTemplate),
23+
}
24+
}, &Config{})
25+
}
26+
27+
// Config is the monitor-specific config with the generic config embedded
28+
type Config struct {
29+
// This cannot be multi instance until there is a way to differentiate them
30+
// in collectd
31+
config.MonitorConfig `singleInstance:"true"`
32+
33+
// The hostname of the chronyd instance
34+
Host string `yaml:"host" validate:"required" default:"localhost"`
35+
// The UDP port number of the chronyd instance. Defaults to 323 in
36+
// collectd if unspecified.
37+
Port *uint16 `yaml:"port"`
38+
// How long to wait for a response from chronyd before considering it down.
39+
// Defaults to 2 seconds in the collectd plugin if not specified
40+
Timeout *uint `yaml:"timeout"`
41+
}
42+
43+
// Monitor is the main type that represents the monitor
44+
type Monitor struct {
45+
collectd.MonitorCore
46+
}
47+
48+
// Configure configures and runs the plugin in collectd
49+
func (m *Monitor) Configure(conf *Config) error {
50+
return m.SetConfigurationAndRun(conf)
51+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
LoadPlugin chrony
2+
<Plugin chrony>
3+
Host "{{.Host}}"
4+
{{with .Port}}
5+
Port "{{.}}"
6+
{{end}}
7+
{{with .Timeout}}
8+
Timeout "{{.}}"
9+
{{end}}
10+
</Plugin>
11+
12+
<Chain "PostCache">
13+
<Rule "set_chrony_monitor_id">
14+
<Match "regex">
15+
Plugin "^chrony$"
16+
</Match>
17+
<Target "set">
18+
MetaData "monitorID" "{{.MonitorID}}"
19+
</Target>
20+
</Rule>
21+
</Chain>

tests/monitors/chrony_test.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
Integration tests for chrony monitor.
3+
"""
4+
from tests.helpers.util import wait_for, run_agent
5+
from tests.helpers.assertions import has_log_message
6+
7+
chrony_config = """
8+
monitors:
9+
- type: collectd/chrony
10+
host: localhost
11+
port: 23874
12+
"""
13+
14+
def test_chrony():
15+
"""
16+
Unfortunately, chronyd is very hard to run in a test environment without
17+
giving it the ability to change the time which we don't want, so just check
18+
for an error message ensuring that the monitor actually did configure it,
19+
even if it doesn't emit any metrics.
20+
"""
21+
with run_agent(chrony_config) as [_, get_output, _]:
22+
def has_error():
23+
return has_log_message(get_output(), level="error",
24+
message="chrony plugin: chrony_query (REQ_TRACKING) failed")
25+
26+
assert wait_for(has_error), "Didn't get chrony error message"

0 commit comments

Comments
 (0)