Skip to content

Add option to disable Reverse DNS Lookups #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 30, 2023
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Supported parameters include:
- `--chrony.address`: the address/port (UDP) or path to Unix socket used to connect to chrony (default: `"[::1]:323"`)
- `--collector.sources`: Enable/disable the collection of `chronyc sources` metrics. (Default: Disabled)
- `--collector.tracking`: Enable/disable the collection of `chronyc tracking` metrics. (Default: Enabled)
- `--collector.dns-lookups`: Enable/disable reverse DNS Lookups. (Default: Enabled)

To disable a collector, use `--no-`. (i.e. `--no-collector.tracking`)

Expand Down
3 changes: 3 additions & 0 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var (
collectTracking = kingpin.Flag("collector.tracking", "Collect tracking metrics").Default("true").Bool()
collectSources = kingpin.Flag("collector.sources", "Collect sources metrics").Default("false").Bool()
collectChmodSocket = kingpin.Flag("collector.chmod-socket", "Chmod 0666 the receiving unix datagram socket").Default("false").Bool()
collectDNSLookups = kingpin.Flag("collector.dns-lookups", "do reverse DNS lookups").Default("true").Bool()

upMetric = typedDesc{
prometheus.NewDesc(
Expand All @@ -57,6 +58,7 @@ type Exporter struct {
collectSources bool
collectTracking bool
collectChmodSocket bool
collectDNSLookups bool

logger log.Logger
}
Expand All @@ -79,6 +81,7 @@ func NewExporter(address string, logger log.Logger) Exporter {
collectSources: *collectSources,
collectTracking: *collectTracking,
collectChmodSocket: *collectChmodSocket,
collectDNSLookups: *collectDNSLookups,

logger: logger,
}
Expand Down
11 changes: 7 additions & 4 deletions collector/sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,13 @@ func (e Exporter) getSourcesMetrics(ch chan<- prometheus.Metric, client chrony.C

for _, r := range results {
sourceAddress := r.IPAddr.String()
// Ignore reverse lookup errors.
sourceNames, _ := net.LookupAddr(sourceAddress)
sort.Strings(sourceNames)
sourceName := strings.Join(sourceNames, ",")
sourceName := sourceAddress
if e.collectDNSLookups {
// Ignore reverse lookup errors.
sourceNames, _ := net.LookupAddr(sourceAddress)
sort.Strings(sourceNames)
sourceName = strings.Join(sourceNames, ",")
}

if r.Mode == chrony.SourceModeRef && r.IPAddr.To4() != nil {
sourceName = chrony.RefidToString(binary.BigEndian.Uint32(r.IPAddr))
Expand Down
8 changes: 6 additions & 2 deletions collector/tracking.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,14 @@ var (
}
)

func chronyFormatName(tracking chrony.Tracking) string {
func (e Exporter) chronyFormatName(tracking chrony.Tracking) string {
if tracking.IPAddr.IsUnspecified() {
return chrony.RefidToString(tracking.RefID)
}
if !e.collectDNSLookups {
return tracking.IPAddr.String()
}

names, err := net.LookupAddr(tracking.IPAddr.String())
if err != nil || len(names) < 1 {
return tracking.IPAddr.String()
Expand All @@ -145,7 +149,7 @@ func (e Exporter) getTrackingMetrics(ch chan<- prometheus.Metric, client chrony.
return fmt.Errorf("Got wrong 'tracking' response: %q", packet)
}

ch <- trackingInfo.mustNewConstMetric(1.0, tracking.IPAddr.String(), chronyFormatName(tracking.Tracking), chrony.RefidAsHEX(tracking.RefID))
ch <- trackingInfo.mustNewConstMetric(1.0, tracking.IPAddr.String(), e.chronyFormatName(tracking.Tracking), chrony.RefidAsHEX(tracking.RefID))

ch <- trackingLastOffset.mustNewConstMetric(tracking.LastOffset)
level.Debug(e.logger).Log("msg", "Tracking Last Offset", "offset", tracking.LastOffset)
Expand Down