diff --git a/errors.go b/errors.go new file mode 100644 index 0000000..d2db349 --- /dev/null +++ b/errors.go @@ -0,0 +1,17 @@ +package main + +import ( + "errors" +) + +type timeout interface { + Timeout() bool +} + +func IsTimeout(err error) bool { + var t timeout + if errors.As(err, &t) && t.Timeout() { + return true + } + return false +} diff --git a/main.go b/main.go index 3c2bbd8..f89df5d 100644 --- a/main.go +++ b/main.go @@ -259,7 +259,7 @@ func discoverNetwork(network string, queue chan func(context.Context), exporter if port == ExporterExporterPort { exporters, err = checkExporterExporter(ctx, ip, port) if err != nil { - if !errors.Is(err, context.DeadlineExceeded) && !os.IsTimeout(err) { + if !errors.Is(err, context.DeadlineExceeded) && !IsTimeout(err) { logrus.Errorf("error fetching from exporter_exporter: %s", err) } logrus.Debugf("%s:%s was not open", ip, port) @@ -328,8 +328,8 @@ func getOldGroups(path string) ([]Group, error) { return oldGroups, err } -func writeFileSDConfig(config *Config, path string, addresses []Address) error { - path = filepath.Join(config.FileSdPath, path+".json") +func writeFileSDConfig(config *Config, exporterName string, addresses []Address) error { + path := filepath.Join(config.FileSdPath, exporterName+".json") previous, err := getOldGroups(path) if err != nil { @@ -346,6 +346,10 @@ func writeFileSDConfig(config *Config, path string, addresses []Address) error { "host": v.Hostname, }, } + if v.Port == ExporterExporterPort { + group.Labels["__metrics_path__"] = "/proxy" + group.Labels["__param_module"] = exporterName + } groups = append(groups, group) }