diff --git a/README.md b/README.md index 0816589..01eae34 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,7 @@ x509_cert_not_after - time() ``` When collecting these metrics from tools like Datadog that does not have timestamp functions, the `x509_read_timestamp` allow to know read timestamp. +Run the exporter with `--timestamp-metric` to get that optionnal metric. ``` x509_cert_not_after - x509_read_timestamp > delay_in_seconds diff --git a/cmd/x509-certificate-exporter/main.go b/cmd/x509-certificate-exporter/main.go index 8614447..8487487 100644 --- a/cmd/x509-certificate-exporter/main.go +++ b/cmd/x509-certificate-exporter/main.go @@ -27,6 +27,7 @@ func main() { port := getopt.IntLong("port", 'p', 9793, "prometheus exporter listening port") debug := getopt.BoolLong("debug", 0, "enable debug mode") trimPathComponents := getopt.IntLong("trim-path-components", 0, 0, "remove leading component(s) from path(s) in label(s)") + emitTimestampMetric := getopt.BoolLong("timestamp-metric", 0, "provide an additionnal metric with current timestamp") files := stringArrayFlag{} getopt.FlagLong(&files, "watch-file", 'f', "watch one or more x509 certificate file") @@ -77,6 +78,7 @@ func main() { YAMLs: yamls, YAMLPaths: internal.DefaultYamlPaths, TrimPathComponents: *trimPathComponents, + EmitTimestampMetric: *emitTimestampMetric, KubeSecretTypes: kubeSecretTypes, KubeIncludeNamespaces: kubeIncludeNamespaces, KubeExcludeNamespaces: kubeExcludeNamespaces, diff --git a/internal/collector.go b/internal/collector.go index bbf188d..bd8daa9 100644 --- a/internal/collector.go +++ b/internal/collector.go @@ -72,11 +72,13 @@ func (collector *collector) Collect(ch chan<- prometheus.Metric) { float64(len(certErrors)), ) - ch <- prometheus.MustNewConstMetric( - certTimestampDesc, - prometheus.GaugeValue, - float64(time.Now().Unix()), - ) + if collector.exporter.EmitTimestampMetric { + ch <- prometheus.MustNewConstMetric( + certTimestampDesc, + prometheus.GaugeValue, + float64(time.Now().Unix()), + ) + } } func (collector *collector) getMetricsForCertificate(certData *parsedCertificate, ref *certificateRef) []prometheus.Metric { diff --git a/internal/exporter.go b/internal/exporter.go index b5f20b1..04d8649 100644 --- a/internal/exporter.go +++ b/internal/exporter.go @@ -22,6 +22,7 @@ type Exporter struct { YAMLs []string YAMLPaths []YAMLCertRef TrimPathComponents int + EmitTimestampMetric bool KubeSecretTypes []string KubeIncludeNamespaces []string KubeExcludeNamespaces []string