Skip to content

Commit 4e3abb3

Browse files
authored
Minor cleanup (#56)
* Rename config struct params to be more descriptive. * Document new config struct. * Update upstream project URLs to new homepage. Signed-off-by: SuperQ <[email protected]>
1 parent 201ce78 commit 4e3abb3

File tree

5 files changed

+30
-21
lines changed

5 files changed

+30
-21
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
[![Build Status](https://circleci.com/gh/SuperQ/chrony_exporter/tree/main.svg?style=svg)](https://circleci.com/gh/SuperQ/chrony_exporter/tree/main)
44
[![Docker Repository on Quay](https://quay.io/repository/superq/chrony-exporter/status "Docker Repository on Quay")](https://quay.io/repository/superq/chrony-exporter)
5+
[![Go Reference](https://pkg.go.dev/badge/github.com/superq/chrony_exporter.svg)](https://pkg.go.dev/github.com/superq/chrony_exporter)
56

6-
This is a [Prometheus Exporter](https://prometheus.io) for [Chrony NTP](https://chrony.tuxfamily.org/).
7+
This is a [Prometheus Exporter](https://prometheus.io) for [Chrony NTP](https://chrony-project.org/).
78

89
## Installation
910

@@ -67,7 +68,7 @@ When the exporter is run as root the flag `collector.chmod-socket` is needed as
6768

6869
You can use [Prometheus rules](https://prometheus.io/docs/prometheus/latest/configuration/recording_rules/) to pre-compute some values.
6970

70-
For example, the maximum clock error can be computed from several metrics as [documented in the Chrony man pages](https://chrony.tuxfamily.org/doc/4.3/chronyc.html).
71+
For example, the maximum clock error can be computed from several metrics as [documented in the Chrony man pages](https://chrony-project.org/doc/4.4/chrony.conf.html).
7172

7273
```yaml
7374
groups:

collector/collector.go

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ type Exporter struct {
4949
address string
5050
timeout time.Duration
5151

52-
collectSources bool
53-
collectTracking bool
54-
collectChmodSocket bool
55-
collectDNSLookups bool
52+
collectSources bool
53+
collectTracking bool
54+
chmodSocket bool
55+
dnsLookups bool
5656

5757
logger log.Logger
5858
}
@@ -66,25 +66,33 @@ func (d *typedDesc) mustNewConstMetric(value float64, labels ...string) promethe
6666
return prometheus.MustNewConstMetric(d.desc, d.valueType, value, labels...)
6767
}
6868

69+
// ChronyCollectorConfig configures the exporter parameters.
6970
type ChronyCollectorConfig struct {
71+
// Address is the Chrony server UDP command port.
7072
Address string
73+
// Timeout configures the socket timeout to the Chrony server.
7174
Timeout time.Duration
7275

73-
CollectSource bool
74-
CollectTracking bool
75-
CollectChmodSocket bool
76-
CollectDNSLookups bool
76+
// ChmodSocket will set the unix datagram socket to mode `0666` when true.
77+
ChmodSocket bool
78+
// DNSLookups will reverse resolve IP addresses to names when true.
79+
DNSLookups bool
80+
81+
// CollectSources will configure the exporter to collect `chronyc sources`.
82+
CollectSources bool
83+
// CollectTracking will configure the exporter to collect `chronyc tracking`.
84+
CollectTracking bool
7785
}
7886

7987
func NewExporter(conf ChronyCollectorConfig, logger log.Logger) Exporter {
8088
return Exporter{
8189
address: conf.Address,
8290
timeout: conf.Timeout,
8391

84-
collectSources: conf.CollectSource,
85-
collectTracking: conf.CollectTracking,
86-
collectChmodSocket: conf.CollectChmodSocket,
87-
collectDNSLookups: conf.CollectDNSLookups,
92+
collectSources: conf.CollectSources,
93+
collectTracking: conf.CollectTracking,
94+
chmodSocket: conf.ChmodSocket,
95+
dnsLookups: conf.DNSLookups,
8896

8997
logger: logger,
9098
}
@@ -106,7 +114,7 @@ func (e Exporter) dial() (net.Conn, error, func()) {
106114
if err != nil {
107115
return nil, err, func() { os.Remove(local) }
108116
}
109-
if e.collectChmodSocket {
117+
if e.chmodSocket {
110118
if err := os.Chmod(local, 0666); err != nil {
111119
return nil, err, func() { conn.Close(); os.Remove(local) }
112120
}

collector/sources.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func (e Exporter) getSourcesMetrics(ch chan<- prometheus.Metric, client chrony.C
122122
for _, r := range results {
123123
sourceAddress := r.IPAddr.String()
124124
sourceName := sourceAddress
125-
if e.collectDNSLookups {
125+
if e.dnsLookups {
126126
// Ignore reverse lookup errors.
127127
sourceNames, _ := net.LookupAddr(sourceAddress)
128128
sort.Strings(sourceNames)

collector/tracking.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func (e Exporter) chronyFormatName(tracking chrony.Tracking) string {
166166
if tracking.IPAddr.IsUnspecified() {
167167
return chrony.RefidToString(tracking.RefID)
168168
}
169-
if !e.collectDNSLookups {
169+
if !e.dnsLookups {
170170
return tracking.IPAddr.String()
171171
}
172172

main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,16 @@ func main() {
5555
kingpin.Flag(
5656
"collector.sources",
5757
"Collect sources metrics",
58-
).Default("false").BoolVar(&conf.CollectSource)
58+
).Default("false").BoolVar(&conf.CollectSources)
5959

6060
kingpin.Flag(
6161
"collector.chmod-socket",
6262
"Chmod 0666 the receiving unix datagram socket",
63-
).Default("false").BoolVar(&conf.CollectChmodSocket)
63+
).Default("false").BoolVar(&conf.ChmodSocket)
6464

6565
kingpin.Flag(
6666
"collector.dns-lookups", "do reverse DNS lookups",
67-
).Default("true").BoolVar(&conf.CollectDNSLookups)
67+
).Default("true").BoolVar(&conf.DNSLookups)
6868

6969
metricsPath := kingpin.Flag(
7070
"web.telemetry-path",
@@ -99,7 +99,7 @@ func main() {
9999
Text: "Metrics",
100100
},
101101
{
102-
Address: "https://chrony.tuxfamily.org/",
102+
Address: "https://chrony-project.org/",
103103
Text: "Chrony NTP",
104104
},
105105
},

0 commit comments

Comments
 (0)