<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Suramya Shah</title>
    <description>The latest articles on Forem by Suramya Shah (@suramya).</description>
    <link>https://forem.com/suramya</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F8034%2F21042045.jpeg</url>
      <title>Forem: Suramya Shah</title>
      <link>https://forem.com/suramya</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/suramya"/>
    <language>en</language>
    <item>
      <title>How to Monitor Endpoints in Kubernetes using Blackbox Exporter</title>
      <dc:creator>Suramya Shah</dc:creator>
      <pubDate>Mon, 17 Jan 2022 04:20:33 +0000</pubDate>
      <link>https://forem.com/infracloud/how-to-monitor-endpoints-in-kubernetes-using-blackbox-exporter-3mlc</link>
      <guid>https://forem.com/infracloud/how-to-monitor-endpoints-in-kubernetes-using-blackbox-exporter-3mlc</guid>
      <description>&lt;p&gt;Monitoring endpoints is an important aspect of system observability for diagnosing performance and availability issues. In this article, we will cover in detail how to achieve endpoint monitoring in Kubernetes using Blackbox Exporter and Prometheus.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a Prometheus Exporter?
&lt;/h2&gt;

&lt;p&gt;Prometheus exporter is a translator that can fetch statistics from a non-prometheus system and can convert the statistics to Prometheus understandable metrics, i.e. the Prometheus &lt;a href="https://prometheus.io/docs/instrumenting/exposition_formats/" rel="noopener noreferrer"&gt;exposition format&lt;/a&gt;.&lt;br&gt;
There are a number of Prometheus exporters that are used to export existing metrics from third-party systems to Prometheus metrics, some of them are:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Exporter Name&lt;/th&gt;
&lt;th&gt;Function&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Blackbox Exporter&lt;/td&gt;
&lt;td&gt;Probe endpoints over HTTP/S, DNS, TCP, and ICMP&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Redis Exporter&lt;/td&gt;
&lt;td&gt;Connects to Redis instance and provides Redis metrics in Prometheus readable format&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Node Exporter&lt;/td&gt;
&lt;td&gt;Exposes hardware and OS metrics for *NIX kernels&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Elasticsearch Exporter&lt;/td&gt;
&lt;td&gt;Connects to Elasticsearch instance and provides various Elasticsearch metrics in Prometheus readable format&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Kube-state Metrics Exporter&lt;/td&gt;
&lt;td&gt;add-on agent which provides metrics about various Kubernetes objects, such as pods, nodes, and deployments&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Other exporters can be found in &lt;a href="https://prometheus.io/docs/instrumenting/exporters/" rel="noopener noreferrer"&gt;Exporters and integrations&lt;/a&gt; docs page.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Endpoint monitoring, why is it needed?
&lt;/h2&gt;

&lt;p&gt;In the current context, endpoint monitoring refers to monitoring internal and external endpoints (HTTP/S, DNS, TCP, and ICMP) for various parameters including HTTP latencies, DNS lookup latencies, SSL certificate expiry information, TLS version.&lt;/p&gt;

&lt;p&gt;In a Kubernetes system, not just the external endpoints that need to be monitored, internal endpoints are also required to be monitored for latency and other parameters. These metrics are an important piece of the infrastructure to ensure continuity of service and compliance with some security certifications.&lt;/p&gt;

&lt;h2&gt;
  
  
  WhiteBox vs BlackBox monitoring
&lt;/h2&gt;

&lt;p&gt;Whitebox monitoring refers to monitoring the internals of the system including application logs, metrics from handlers. Blackbox monitoring on the other hand includes monitoring the behavior from outside that affects users like server down, page not working, or degradation of site performance.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Blackbox Exporter?
&lt;/h2&gt;

&lt;p&gt;Blackbox Exporter is used to probe endpoints like HTTPS, HTTP, TCP, DNS, and ICMP. After you define the endpoint, Blackbox Exporter generates metrics that can be visualized using tools like Grafana. One of the most important feature of Blackbox Exporter is measuring the response time of endpoints.&lt;/p&gt;

&lt;p&gt;The following diagram shows the flow of Blackbox Exporter monitoring an endpoint.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft87bh0twcxfp7h52hoke.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft87bh0twcxfp7h52hoke.png" alt="blackbox exporter flow diagram"&gt;&lt;/a&gt;&lt;br&gt;
Here is a default module defined in the Blackbox Exporter config:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;

&lt;span class="na"&gt;modules&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;http_2xx&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;http&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;fail_if_not_ssl&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
      &lt;span class="na"&gt;ip_protocol_fallback&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
      &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;GET&lt;/span&gt;
      &lt;span class="na"&gt;no_follow_redirects&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
      &lt;span class="na"&gt;preferred_ip_protocol&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ip4&lt;/span&gt;
      &lt;span class="na"&gt;valid_http_versions&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;HTTP/1.1&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;HTTP/2.0&lt;/span&gt;
      &lt;span class="na"&gt;valid_status_codes&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="m"&gt;200&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="m"&gt;204&lt;/span&gt;
    &lt;span class="na"&gt;prober&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;http&lt;/span&gt;
    &lt;span class="na"&gt;timeout&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;15s&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The above module is http_2xx. It works on HTTP Probe offered by Blackbox Exporter. Here we have also added valid_status_codes for the probe to return success for the endpoints returning various status codes. You can accordingly configure your blackbox.yml to make the probe return success/failure based on your configurations. Other configuration parameters can be found below:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Parameter&lt;/th&gt;
&lt;th&gt;Function&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;valid_status_codes:&lt;/td&gt;
&lt;td&gt;List of status codes for the probe to return success for your applications&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;method: GET&lt;/td&gt;
&lt;td&gt;Use of HTTP GET to access the endpoint&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;no_follow_redirects: false&lt;/td&gt;
&lt;td&gt;Do not follow HTTP redirects&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;preferred_ip_protocol: ip4&lt;/td&gt;
&lt;td&gt;Use IPv4 protocol&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;valid_http_versions&lt;/td&gt;
&lt;td&gt;Both HTTP/1.1 and HTTP/2.0 are valid&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;timeout: 15s&lt;/td&gt;
&lt;td&gt;Timeout after 15s if no response received&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;fail_if_not_ssl: true&lt;/td&gt;
&lt;td&gt;The probe will fail if the endpoint is not SSL secured&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;You can have a look at the detailed example for more scenarios in this &lt;a href="https://github.com/prometheus/blackbox_exporter/blob/master/example.yml" rel="noopener noreferrer"&gt;example.yml&lt;/a&gt;. With some config changes on the Prometheus side, the Blackbox Exporter then sends metrics relevant to the configs applied, we will see this in more detail in the coming sections.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why do we need Blackbox Exporter?
&lt;/h2&gt;

&lt;p&gt;There are various tools available for monitoring endpoints like Datadog, Freshping, Uptime.com, etc.&lt;br&gt;
In a production infrastructure with multiple services and endpoints, the regular endpoint monitoring solutions monetarily cost us hefty amounts even for small probe checks, Blackbox Exporter in this case is an open-source alternative to available solutions and is maintained by the Prometheus community.&lt;/p&gt;

&lt;p&gt;One point to be noted is that most exporters accept static configurations and expose metrics, Blackbox Exporter works a little differently. Inside the config, you define modules, then Prometheus can query each of the modules for a set of targets. As a response to that query, Blackbox Exporter generates metrics for the queried endpoint. This means we do not have to manually change the endpoints, Prometheus and Blackbox Exporter takes care of generating the endpoints dynamically with the help of Prometheus’ kubernetes_sd_configs functionality.&lt;/p&gt;

&lt;p&gt;In small deployments and infrastructure, a static list is easy to maintain, it is very easy to forget about updating that list once you have multiple clusters and environments, maintenance of such monitoring solutions becomes very cumbersome.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing and Configuring Blackbox Exporter in Kubernetes
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Installing Blackbox Exporter
&lt;/h3&gt;

&lt;p&gt;We will be using the prometheus-community/prometheus-blackbox-exporter Helm chart to install Blackbox Exporter, it can be found in &lt;a href="https://github.com/prometheus-community/helm-charts/tree/main/charts/prometheus-blackbox-exporter" rel="noopener noreferrer"&gt;prometheus-blackbox-exporter&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can add the modules for blackbox.yml in the values.yml config section:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;

&lt;span class="na"&gt;config&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;modules&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;http_2xx&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;prober&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;http&lt;/span&gt;
      &lt;span class="na"&gt;timeout&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;5s&lt;/span&gt;
      &lt;span class="na"&gt;http&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;valid_http_versions&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;HTTP/1.1"&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;HTTP/2.0"&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
        &lt;span class="na"&gt;follow_redirects&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
        &lt;span class="na"&gt;preferred_ip_protocol&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;ip4"&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="nv"&gt;$ &lt;/span&gt;helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
&lt;span class="nv"&gt;$ &lt;/span&gt;helm repo update
&lt;span class="nv"&gt;$ &lt;/span&gt;helm &lt;span class="nb"&gt;install &lt;/span&gt;prometheus-blackbox prometheus-community/prometheus-blackbox-exporter &lt;span class="nt"&gt;-f&lt;/span&gt; values.yaml


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Configuring Prometheus for Blackbox Exporter
&lt;/h3&gt;

&lt;p&gt;Prometheus is a prerequisite for Blackbox Exporter, we will be using Prometheus Operator to install Prometheus. You can install/know more about Prometheus Operator from &lt;a href="https://www.infracloud.io/blogs/prometheus-operator-helm-guide/" rel="noopener noreferrer"&gt;InfraCloud’s prometheus-operator-helm-guide&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;We will be editing the prometheus.yml by adding the configurations. If you have installed the Prometheus Operator using &lt;a href="https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack" rel="noopener noreferrer"&gt;kube-prometheus-stack&lt;/a&gt; chart, then you can add the configuration under &lt;code&gt;additionalScrapeConfigs[]&lt;/code&gt; in values.yml.&lt;/p&gt;

&lt;p&gt;Note: Prometheus Operator also has a &lt;a href="https://prometheus-operator.dev/docs/operator/api/#probespec" rel="noopener noreferrer"&gt;Probe Custom Resource&lt;/a&gt;, which can be used to configure Prometheus with Blackbox Exporter. At the time of writing this article, it only supports dynamic discovery for Ingress resource.&lt;/p&gt;

&lt;p&gt;We will majorly be adding configs for the following in Prometheus for our endpoint monitoring.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Probing external targets&lt;/li&gt;
&lt;li&gt;Probing services via the Blackbox Exporter&lt;/li&gt;
&lt;li&gt;Probing ingresses via the Blackbox Exporter&lt;/li&gt;
&lt;li&gt;Probing pods via Blackbox Exporter&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the kube-prometheus-stack’s values.yaml, add the following blocks under &lt;code&gt;additionalScrapeConfigs[]&lt;/code&gt; section:&lt;/p&gt;
&lt;h4&gt;
  
  
  1. Add Prometheus config to probe external targets
&lt;/h4&gt;

&lt;p&gt;We can probe certain static targets from Prometheus with the help of Blackbox Exporter using static_configs.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;

&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;job_name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;blackbox-external-targets'&lt;/span&gt;
  &lt;span class="na"&gt;metrics_path&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;/probe&lt;/span&gt;
  &lt;span class="na"&gt;params&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;module&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;http_2xx&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
  &lt;span class="na"&gt;static_configs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;targets&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;https://www.google.com&lt;/span&gt;
  &lt;span class="na"&gt;relabel_configs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;source_labels&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;__address__&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
      &lt;span class="na"&gt;target_label&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;__param_target&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;source_labels&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;__param_target&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
      &lt;span class="na"&gt;target_label&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;instance&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;target_label&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;__address__&lt;/span&gt;
      &lt;span class="na"&gt;replacement&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;prometheus-blackbox-prometheus-blackbox-exporter:9115&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The &lt;code&gt;__param_target&lt;/code&gt; label tells Prometheus to set the &lt;code&gt;target&lt;/code&gt; query param to the given value, which is the target's address, in this case, i.e. google.com. &lt;/p&gt;

&lt;p&gt;In Kubernetes, external targets can be used in some scenarios to test the third-party service's performance, in checking some performance tools latency issues.&lt;/p&gt;

&lt;p&gt;But in a Kubernetes system where resources and endpoints come and go over time, the probing which can be highly useful is the dynamic probing of resources including pods, services, and ingress.&lt;/p&gt;

&lt;p&gt;Using Kubernetes service discovery configs in Prometheus, we can achieve the dynamic probing of endpoints. Kubernetes service discovery configurations allow fetching scrape targets from Kubernetes' API and always stays synchronized with the cluster state.&lt;br&gt;
You can find the list of available roles that can be configured to discover targets in the &lt;a href="https://prometheus.io/docs/prometheus/latest/configuration/configuration/#kubernetes_sd_config" rel="noopener noreferrer"&gt;kubernetes_sd_config&lt;/a&gt; section of the documentation.&lt;/p&gt;

&lt;h4&gt;
  
  
  2. Add Prometheus config to probe services
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;

    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;job_name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;blackbox-kubernetes-services"&lt;/span&gt;
      &lt;span class="na"&gt;metrics_path&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;/probe&lt;/span&gt;
      &lt;span class="na"&gt;params&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;module&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;http_2xx&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
      &lt;span class="na"&gt;kubernetes_sd_configs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;role&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;service&lt;/span&gt;
      &lt;span class="na"&gt;relabel_configs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="c1"&gt;# Example relabel to probe only some services that have "example.io/should_be_probed = true" annotation&lt;/span&gt;
      &lt;span class="c1"&gt;#  - source_labels: [__meta_kubernetes_service_annotation_example_io_should_be_probed]&lt;/span&gt;
      &lt;span class="c1"&gt;#    action: keep&lt;/span&gt;
      &lt;span class="c1"&gt;#    regex: true      &lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;source_labels&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;__address__&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
          &lt;span class="na"&gt;target_label&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;__param_target&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;target_label&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;__address__&lt;/span&gt;
          &lt;span class="na"&gt;replacement&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;  &lt;span class="s"&gt;prometheus-blackbox-prometheus-blackbox-exporter:9115&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;source_labels&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;__param_target&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
          &lt;span class="na"&gt;target_label&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;instance&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;action&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;labelmap&lt;/span&gt;
          &lt;span class="na"&gt;regex&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;__meta_kubernetes_service_label_(.+)&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;source_labels&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;__meta_kubernetes_namespace&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
          &lt;span class="na"&gt;target_label&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;kubernetes_namespace&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;source_labels&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;__meta_kubernetes_service_name&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
          &lt;span class="na"&gt;target_label&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;kubernetes_service_name&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Here we can use &lt;code&gt;[__meta_kubernetes_service_annotation_example_io_should_be_probed]&lt;/code&gt; to only check those services that have the annotation &lt;code&gt;example.io/should_be_probed = true&lt;/code&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  3. Add Prometheus config to probe ingress
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;

    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;job_name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;blackbox-kubernetes-ingresses"&lt;/span&gt;
      &lt;span class="na"&gt;metrics_path&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;/probe&lt;/span&gt;
      &lt;span class="na"&gt;params&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;module&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;http_2xx&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
      &lt;span class="na"&gt;kubernetes_sd_configs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;role&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ingress&lt;/span&gt;
      &lt;span class="na"&gt;relabel_configs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="c1"&gt;# Example relabel to probe only some ingresses that have "example.io/should_be_probed = true" annotation&lt;/span&gt;
      &lt;span class="c1"&gt;#  - source_labels: [__meta_kubernetes_ingress_annotation_example_io_should_be_probed]&lt;/span&gt;
      &lt;span class="c1"&gt;#    action: keep&lt;/span&gt;
      &lt;span class="c1"&gt;#    regex: true&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;source_labels&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="pi"&gt;[&lt;/span&gt;
              &lt;span class="nv"&gt;__meta_kubernetes_ingress_scheme&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt;
              &lt;span class="nv"&gt;__address__&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt;
              &lt;span class="nv"&gt;__meta_kubernetes_ingress_path&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt;
            &lt;span class="pi"&gt;]&lt;/span&gt;
          &lt;span class="na"&gt;regex&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;(.+);(.+);(.+)&lt;/span&gt;
          &lt;span class="na"&gt;replacement&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${1}://${2}${3}&lt;/span&gt;
          &lt;span class="na"&gt;target_label&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;__param_target&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;target_label&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;__address__&lt;/span&gt;
          &lt;span class="na"&gt;replacement&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;prometheus-blackbox-prometheus-blackbox-exporter:9115&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;source_labels&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;__param_target&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
          &lt;span class="na"&gt;target_label&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;instance&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;action&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;labelmap&lt;/span&gt;
          &lt;span class="na"&gt;regex&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;__meta_kubernetes_ingress_label_(.+)&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;source_labels&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;__meta_kubernetes_namespace&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
          &lt;span class="na"&gt;target_label&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;kubernetes_namespace&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;source_labels&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;__meta_kubernetes_ingress_name&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
          &lt;span class="na"&gt;target_label&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ingress_name&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  4. Add Prometheus config to probe pods
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;

    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;job_name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;blackbox-kubernetes-pods"&lt;/span&gt;
      &lt;span class="na"&gt;metrics_path&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;/probe&lt;/span&gt;    
      &lt;span class="na"&gt;params&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;module&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;http_2xx&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
      &lt;span class="na"&gt;kubernetes_sd_configs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;role&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;pod&lt;/span&gt;        
      &lt;span class="na"&gt;relabel_configs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="c1"&gt;# Example relabel to scrape only pods that have&lt;/span&gt;
      &lt;span class="c1"&gt;# "example.io/should_be_scraped = true" annotation.&lt;/span&gt;
      &lt;span class="c1"&gt;#  - source_labels: [__meta_kubernetes_pod_annotation_example_io_should_be_scraped]&lt;/span&gt;
      &lt;span class="c1"&gt;#    action: keep&lt;/span&gt;
      &lt;span class="c1"&gt;#    regex: true&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;source_labels&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;__address__&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
          &lt;span class="na"&gt;target_label&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;__param_target&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;target_label&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;__address__&lt;/span&gt;
          &lt;span class="na"&gt;replacement&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;  &lt;span class="s"&gt;prometheus-blackbox-prometheus-blackbox-exporter:9115&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;source_labels&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;__param_target&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
          &lt;span class="na"&gt;replacement&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${1}/health&lt;/span&gt;
          &lt;span class="na"&gt;target_label&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;instance&lt;/span&gt;          
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;action&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;labelmap&lt;/span&gt;
          &lt;span class="na"&gt;regex&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;__meta_kubernetes_pod_label_(.+)&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;source_labels&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;__meta_kubernetes_namespace&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
          &lt;span class="na"&gt;target_label&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;kubernetes_namespace&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;source_labels&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;__meta_kubernetes_pod_name&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
          &lt;span class="na"&gt;target_label&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;kubernetes_pod_name&lt;/span&gt;     


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Considering our application which exposes health of the application at &lt;code&gt;/health&lt;/code&gt; endpoint, we have used replacement directive for source_label.&lt;/p&gt;

&lt;h4&gt;
  
  
  Verify the generated metrics in Prometheus
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsw1xbfcv6g476gtxnex0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsw1xbfcv6g476gtxnex0.png" alt="verify targets in Prometheus"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once the changes are applied and the resources for the Blackbox Exporter are deployed, we can verify the status of targets in Prometheus. We can check whether the Blackbox Exporter is up with the registered targets by navigating to the Status tab and then selecting Targets in the Prometheus UI.&lt;/p&gt;

&lt;p&gt;Here you can see we are using &lt;code&gt;https://www.google.com&lt;/code&gt; as an external target for reference with its state UP.&lt;br&gt;
We can also check if metrics are getting populated by looking for metrics starting with &lt;code&gt;probe_&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr0v9fc4xxu0ebbvqj1zh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr0v9fc4xxu0ebbvqj1zh.png" alt="Prometheus probe metrics"&gt;&lt;/a&gt;&lt;br&gt;
Here you can see the list of some of the generated probe_ metrics:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Metric name&lt;/th&gt;
&lt;th&gt;Function&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;probe_duration_seconds&lt;/td&gt;
&lt;td&gt;Returns how long the probe took to complete in seconds&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;probe_http_status_code&lt;/td&gt;
&lt;td&gt;Response HTTP status code&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;probe_http_version&lt;/td&gt;
&lt;td&gt;Returns the version of HTTP of the probe response&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;probe_success&lt;/td&gt;
&lt;td&gt;Displays whether or not the probe was a success&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;probe_dns_lookup_time_seconds&lt;/td&gt;
&lt;td&gt;Returns the time taken for probe DNS lookup in seconds&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;probe_ip_protocol&lt;/td&gt;
&lt;td&gt;Specifies whether probe ip protocol is IP4 or IP6&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;probe_ssl_earliest_cert_expiry metric&lt;/td&gt;
&lt;td&gt;Returns earliest SSL cert expiry in unixtime&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;probe_tls_version_info&lt;/td&gt;
&lt;td&gt;Contains the TLS version used&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;probe_failed_due_to_regex&lt;/td&gt;
&lt;td&gt;Indicates if probe failed due to regex&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;probe_http_content_length&lt;/td&gt;
&lt;td&gt;Length of HTTP content response&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;probe_http_version&lt;/td&gt;
&lt;td&gt;Returns the version of HTTP of the probe response&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Monitoring configured endpoints using Grafana
&lt;/h2&gt;

&lt;p&gt;We can now use the generated metrics with Grafana to create our custom dashboards. However, there are some already available dashboards that can be &lt;a href="https://grafana.com/docs/grafana/v7.5/dashboards/export-import/" rel="noopener noreferrer"&gt;imported&lt;/a&gt; to visualize data from the generated metrics, some of them are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://grafana.com/grafana/dashboards/7587" rel="noopener noreferrer"&gt;Prometheus Blackbox Exporter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://grafana.com/grafana/dashboards/13659" rel="noopener noreferrer"&gt;Blackbox Exporter (HTTP prober)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://grafana.com/grafana/dashboards/13587" rel="noopener noreferrer"&gt;9115 - Blackbox&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://grafana.com/grafana/dashboards/4859" rel="noopener noreferrer"&gt;HTTP Services Status&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How did Blackbox Exporter reveal our infrastructure discrepancies?
&lt;/h2&gt;

&lt;p&gt;In this section we will see how we used Blackbox Exporter to probe external targets and some other scenarios where it can be used to probe ingress,pods and services:&lt;/p&gt;

&lt;h3&gt;
  
  
  External target
&lt;/h3&gt;

&lt;p&gt;We were facing increased latencies in our application performance, and we were not sure which endpoint is causing the problem. We monitored the response time of all endpoints which were being used in the application flow, and with the help of BlackBox Exporter we found our latency causing endpoints.&lt;/p&gt;

&lt;p&gt;Let us assume a scenario where we have two Kubernetes services A and B. Service A calls another service B, service B then calls some external endpoints for response, processes it, and sends it back to service A. The external endpoints can be user facing endpoints, third party services, or database endpoints. For reference, we are monitoring &lt;code&gt;google.com&lt;/code&gt; as an external endpoint here.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fie54gg4tzdz2qdq995z0.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fie54gg4tzdz2qdq995z0.jpg" alt="External target example in Grafana for Blackbox Exporter"&gt;&lt;/a&gt;&lt;br&gt;
In the above dashboard example, we can see that we can now monitor the website performance by measuring its response time using &lt;code&gt;probe_http_duration_seconds&lt;/code&gt; metrics generated by the Blackbox Exporter, and look for the spike in the external targets that caused the latency in services A and B.&lt;/p&gt;

&lt;h3&gt;
  
  
  Ingress
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzn0qn5m7efwxso3jl12w.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzn0qn5m7efwxso3jl12w.jpg" alt="Ingress example in Grafana for Blackbox Exporter"&gt;&lt;/a&gt;&lt;br&gt;
In this scenario we will be focusing on the problem regarding certificate expiry, if we want to monitor when our domain certificate is going to expire, we can achieve this by using &lt;code&gt;probe_ssl_earliest_cert_expiry&lt;/code&gt; metric generated by Blackbox Exporter for our ingress resources. We can also use it to monitor if DNS resolution is working, or if there is any latency/issues from the loadbalancer side.&lt;/p&gt;

&lt;h3&gt;
  
  
  Pods
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn276u04sqmy3ny1vi87m.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn276u04sqmy3ny1vi87m.jpg" alt="Pods example in Grafana for Blackbox Exporter"&gt;&lt;/a&gt;&lt;br&gt;
We can probe pods and create health dashboard for our applications, in the above example we can see we are probing the pod on /health endpoint by using &lt;code&gt;probe_http_status_code&lt;/code&gt; metrics generated by Blackbox Exporter.&lt;/p&gt;

&lt;h3&gt;
  
  
  Service
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqfdoi52gvsqp4zq3esjb.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqfdoi52gvsqp4zq3esjb.jpg" alt="Service example in Grafana for Blackbox Exporter"&gt;&lt;/a&gt;&lt;br&gt;
We can also monitor if services are properly configured and are responding to probe checks.&lt;/p&gt;

&lt;h2&gt;
  
  
  Benefits of Blackbox Exporter
&lt;/h2&gt;

&lt;p&gt;In the above examples, we can see how we can use Blackbox Exporter for some common scenarios in a Kubernetes cluster. Overall, we can say Blackbox Exporter can be used in the following scenarios: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Measuring response time is the most important feature of the Blackbox Exporter, in such cases, it can be considered as an excellent tool for analyzing the latency/reachability of endpoints including our user-facing endpoints and third-party services.&lt;/li&gt;
&lt;li&gt;Provides dynamic endpoint monitoring from within the Kubernetes cluster. Most exporters accept static configurations and expose metrics, Blackbox Exporter works differently, and along with the support of static configs/endpoints it can produce metrics dynamically by using Prometheus’ &lt;a href="https://prometheus.io/docs/prometheus/latest/configuration/configuration/#kubernetes_sd_config" rel="noopener noreferrer"&gt;kubernetes_sd_config&lt;/a&gt; functionality and can be used in dynamic endpoint monitoring.&lt;/li&gt;
&lt;li&gt;Blackbox Exporter can be used to detect endpoint failures and health checks, it can be integrated with Alertmanager (We can add alert rules to the Prometheus to receive alerts about Blackbox Exporter).&lt;/li&gt;
&lt;li&gt;We can always stay updated by monitoring the certificate expiry date of endpoints using Blackbox Exporter.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this article, we covered the following points:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What is Blackbox Exporter, why it is needed.&lt;/li&gt;
&lt;li&gt;How to install and use Blackbox Exporter with a Kubernetes cluster and monitor it using Grafana.&lt;/li&gt;
&lt;li&gt;What are some important use cases/benefits of Blackbox Exporter.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This post introduced you to Blackbox Exporter for endpoint monitoring of a Kubernetes cluster for infrastructure reliability. I hope you found this post informative and engaging. &lt;/p&gt;

&lt;h3&gt;
  
  
  References and further reading
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dzone.com/articles/prometheus-blackbox-what-why-how" rel="noopener noreferrer"&gt;Blackbox Exporter What Why How&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/prometheus/blackbox_exporter" rel="noopener noreferrer"&gt;Prometheus Blackbox Exporter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=2TpQ3ETmhsw&amp;amp;t=484s" rel="noopener noreferrer"&gt;Kubernetes with Blackbox&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://lumaks.medium.com/monitoring-kubernetes-ingress-with-blackboxexporter-25e178ea9898" rel="noopener noreferrer"&gt;Monitoring kubernetes ingress with blackbox exporter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.opsramp.com/prometheus-monitoring/prometheus-blackbox-exporter/" rel="noopener noreferrer"&gt;Blackbox Exporter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://lapee79.github.io/en/article/monitoring-http-using-blackbox-exporter/" rel="noopener noreferrer"&gt;Monitoring http using Blackbox Exporter&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>kubernetes</category>
      <category>grafana</category>
      <category>prometheus</category>
    </item>
    <item>
      <title>Hi, I'm ss22ever</title>
      <dc:creator>Suramya Shah</dc:creator>
      <pubDate>Sun, 26 Feb 2017 08:41:43 +0000</pubDate>
      <link>https://forem.com/suramya/hi-im-ss22ever</link>
      <guid>https://forem.com/suramya/hi-im-ss22ever</guid>
      <description>&lt;p&gt;I have been coding for [number] years.&lt;/p&gt;

&lt;p&gt;You can find me on GitHub as &lt;a href="https://github.com/ss22ever" rel="noopener noreferrer"&gt;ss22ever&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I live in [city].&lt;/p&gt;

&lt;p&gt;I work for [company]&lt;/p&gt;

&lt;p&gt;I mostly program in these languages: [languages].&lt;/p&gt;

&lt;p&gt;I am currently learning more about [topic].&lt;/p&gt;

&lt;p&gt;Nice to meet you.&lt;/p&gt;

</description>
      <category>introduction</category>
    </item>
  </channel>
</rss>
