make x509_read_timestamp an optional metric

To preserve storage efficiency in TSDB systems that don't need the
metric for alerting.

Argument --timestamp-metric is to be used when x509_read_timestamp
should be emitted.

Signed-off-by: Thibault VINCENT <root@paraneko.org>
This commit is contained in:
Thibault VINCENT
2021-03-12 12:30:23 +01:00
parent 32acde5c04
commit 809b324bae
4 changed files with 11 additions and 5 deletions
+1
View File
@@ -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
+2
View File
@@ -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 <n> 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,
+7 -5
View File
@@ -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 {
+1
View File
@@ -22,6 +22,7 @@ type Exporter struct {
YAMLs []string
YAMLPaths []YAMLCertRef
TrimPathComponents int
EmitTimestampMetric bool
KubeSecretTypes []string
KubeIncludeNamespaces []string
KubeExcludeNamespaces []string