@Override
    public void bindTo(MeterRegistry registry) {
        final List<Gauge> meters = new ArrayList<>(certificates.size() * 2);
        for (X509Certificate certificate : certificates) {
            final String commonName = firstNonNull(CertificateUtil.getCommonName(certificate), "");

            final Gauge validityMeter =
                    Gauge.builder(meterIdPrefix.name("tls.certificate.validity"), certificate, x509Cert -> {
                             try {
                                 x509Cert.checkValidity();
                             } catch (CertificateExpiredException | CertificateNotYetValidException e) {
                                 return 0;
                             }
                             return 1;
                         })
                         .description(
                                 "1 if TLS certificate is in validity period, 0 if certificate is not in " +
                                 "validity period")
                         .tags("common.name", commonName)
                         .tags(meterIdPrefix.tags())
                         .register(registry);
            meters.add(validityMeter);

            final Gauge validityDaysMeter =
                    Gauge.builder(meterIdPrefix.name("tls.certificate.validity.days"), certificate,
                                  x509Cert -> {
                                      final Instant notAfter = x509Cert.getNotAfter().toInstant();
                                      final Duration diff =
                                              Duration.between(Instant.now(), notAfter);
                                      return diff.toDays();
                                  })
                         .description("Duration in days before TLS certificate expires, which becomes -1 " +
                                      "if certificate is expired")
                         .tags("common.name", commonName)
                         .tags(meterIdPrefix.tags())
                         .register(registry);
            meters.add(validityDaysMeter);
        }

        addClosingTask(() -> {
            for (Gauge meter : meters) {
                registry.remove(meter);
            }
        });
    }
A {@link MeterBinder} that provides metrics for TLS certificates.
The following stats are currently exported per registered {@link MeterIdPrefix}.

<ul>
  <li>"tls.certificate.validity" (gauge) - 1 if TLS certificate is in validity period, 0 if certificate
      is not in validity period</li>
  <li>"tls.certificate.validity.days" (gauge) - Duration in days before TLS certificate expires, which
      becomes -1 if certificate is expired</li>
</ul>
core/src/main/java/com/linecorp/armeria/common/metric/CertificateMetrics.java