Automating kubernetes domain registration expiration check using prometheus-stack

For everyone who hosts their sites, the problem of domain name renewal is urgent – if you miss the registration expiration date, you can get a bunch of problems out of the blue. For the timely renewal of registration, you need to track the expiration date.

For a small number of domains, it will be enough to create a reminder in the calendar, but if there are many domains, this process should be automated.

Prometheus-stack

Using prometheus to monitor your infrastructure, you need to do 3 steps:

  1. collect metrics about domain expiration time;

  2. create a visualization of the collected metrics in grafana;

  3. create alerts about the approaching domain expiration time.

In the case of using kubernetes and installed in it prometheus-stack the task is greatly simplified, since it provides the following features:

  • ServiceMonitor – a mechanism for dynamically describing goals for collecting metrics;

  • automatic addition of dashboards to grafana via ConigMap;

  • PrometheusRule – mechanism for dynamically adding alerts to prometheus;

Helm chart domain-exporter

helm is a package manager for kubernetes. The package is appropriately named chart.

You can use a ready-made helm chart domain-exporterwhich will provide everything you need out of the box.

This chart wraps the prometheus domain metrics export application domain_exporter, simple visualization and the necessary alerts in a single chart, which is easy to customize for your own needs.

Metrics

Prometheus will automatically collect data from the exporter through the ServiceMonitor mechanism. The following metrics are available:

  • domain_expiry_days – number of days before domain expiration;

  • domain_probe_success – successfully or not the domain data was collected;

# HELP domain_expiry_days time in days until the domain expires
# TYPE domain_expiry_days gauge
domain_expiry_days{domain="amazon.com"} 1144
domain_expiry_days{domain="amazon.de"} -1
domain_expiry_days{domain="amazon.pl"} 22
domain_expiry_days{domain="domain-failed.com"} -1
domain_expiry_days{domain="fabiensanglard.net"} 240
domain_expiry_days{domain="flibusta.site"} 50
domain_expiry_days{domain="github.com"} 391
domain_expiry_days{domain="google.com"} 2558
domain_expiry_days{domain="habr.ru"} 217
domain_expiry_days{domain="microsoft.com"} 232
domain_expiry_days{domain="ok.ru"} 79
domain_expiry_days{domain="ted.com"} 55
domain_expiry_days{domain="vaikutis.lt"} 63
domain_expiry_days{domain="viva64.com"} 57
# HELP domain_probe_success wether the probe was successful or not
# TYPE domain_probe_success gauge
domain_probe_success{domain="amazon.com"} 1
domain_probe_success{domain="amazon.de"} 0
domain_probe_success{domain="amazon.pl"} 1
domain_probe_success{domain="domain-failed.com"} 0
domain_probe_success{domain="fabiensanglard.net"} 1
domain_probe_success{domain="flibusta.site"} 1
domain_probe_success{domain="github.com"} 1
domain_probe_success{domain="google.com"} 1
domain_probe_success{domain="habr.ru"} 1
omain_probe_success{domain="microsoft.com"} 1
domain_probe_success{domain="ok.ru"} 1
domain_probe_success{domain="ted.com"} 1
domain_probe_success{domain="vaikutis.lt"} 1
domain_probe_success{domain="viva64.com"} 1

Dashboard

The upper left half displays domains that are about to expire.

In the upper right, there are domains for which we were unable to retrieve data.

Below – in general, all domains for which metrics are exported.

dashboard view in grafana
dashboard view in grafana

Alerts

The following alerts are available by default:

  • DomainExpiringWarning – less than 60 days left until the end of registration. The number of days can be changed;

  • DomainExpiringCritical – less than 5 days left. Has the highest severity. The number of days can be changed;

  • DomainProbeFailed – it was not possible to collect data about the domain;

  • DomainMetricsAbsent – there are no domain metrics. For some reason, metrics cannot be collected or are missing. This may indicate any problems in the application, helm chart configuration, prometheus or even kubernetes cluster.

displaying alerts in prometheus
displaying alerts in prometheus

Customization

Helm chart domain-exporterlike any other helm chart, it’s easy to customize through values. You can disable specific alerts and set other boundaries:

# Prometheus rules
rules:
  enabled: true
  # Alert with warning severity if metrics is absent
  absent:
    enabled: true
  # Alert with warning severity if expiration time is less then provided
  warning:
    enabled: true
    expiration: 60  # days
  # Alert with critical severity alert if expiration time is less then provided
  critical:
    enabled: true
    expiration: 5  # days
  # Alert on failure to detect expiration time
  failed:
    enabled: true

# Grafana dashboard with representation of monitoring domains
dashboards:
  enabled: true
  # Labels to add dashboard
  labels:
    # default grafana dashboard discovery label with stub value
    # Override this value if you use custom grafana label
    # https://github.com/grafana/helm-charts/blob/grafana-6.16.3/charts/grafana/values.yaml#L629
    grafana_dashboard: '1'
  # Folder to put dashboard in grafana
  # Will be used default if it's empty
  targetFolder: ""

# Prometheus service monitor
metrics:
  enabled: true
  # Interval between metrics scraping
  interval: 1m

# List of domains to monitor
domains:
  - example.com

Installation

First, you need to add a local helm repository:

helm repo add zifter https://zifter.github.io/helm-charts/

then install the chart with the required domains:

helm install domain-exporter zifter/domain-exporter --namespace monitoring --set "domains={aliexpress.ru,amazon.com,amazon.pl,censor.net,domain-is-not-found.net}"

or via customization file values.yaml:

helm install domain-exporter zifter/domain-exporter --namespace monitoring -f values.yaml

where values.yaml:

# Prometheus rules
rules:
  warning:
    expiration: 60  # days
  critical:
    expiration: 5  # days

# List of domains to monitor
domains:
- google.com
- habr.ru
- github.com
- vaikutis.lt
- amazon.pl
- amazon.com
- amazon.de
- ok.ru
- flibusta.site
- domain-failed.com
- viva64.com
- ted.com

What’s left outside the scope of the article

There are several things that will affect how the helm chart works:

  1. AlertManager must be configured to receive information about alerts to the desired communication channel;

  2. CRD ServiceMonitor is a relatively new mechanism. Make sure your version of prometheus-stack supports this and not the deprecated annotation-based mechanism. It is enough to check through the helm chart installation;

  3. Prometheus-stack looks into specific namespaces to track ServiceMonitor, dashboards and alerts. Make sure it is configured properly and you put the helm chart in the correct namespace;

  4. dashboard compatibility has not been tested with newer or older versions of grafana. Compatibility is likely but not guaranteed;

  5. the chart is guaranteed to work in kubernetes 1.19+ and helm 3. Compatibility has not been tested with other versions, but most likely everything works or needs to be finished a little with a file.

Conclusion

Keeping track of domain expiration times is critical.

With the prometheus stack in kubernetes, which provides convenient mechanisms to simplify monitoring operations, this is easy to do.

Using the prepared helm chart domain-exporterwhich will provide all the necessary metrics, dashboards and alerts out of the box, it becomes very easy to automate tracking domain expiration times.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *