mirror of
https://github.com/enix/x509-certificate-exporter.git
synced 2026-08-23 22:16:39 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -22,6 +22,7 @@ type Exporter struct {
|
||||
YAMLs []string
|
||||
YAMLPaths []YAMLCertRef
|
||||
TrimPathComponents int
|
||||
EmitTimestampMetric bool
|
||||
KubeSecretTypes []string
|
||||
KubeIncludeNamespaces []string
|
||||
KubeExcludeNamespaces []string
|
||||
|
||||
Reference in New Issue
Block a user