{"id":753,"date":"2024-04-04T15:28:56","date_gmt":"2024-04-04T15:28:56","guid":{"rendered":"https:\/\/blog.ngocha.biz\/?p=753"},"modified":"2024-04-04T15:28:56","modified_gmt":"2024-04-04T15:28:56","slug":"set-up-blackbox-exporter-on-vm","status":"publish","type":"post","link":"https:\/\/blog.ngocha.biz\/?p=753","title":{"rendered":"How To Set Up Blackbox Exporter On VM &#8211; Ultimate Guide"},"content":{"rendered":"<p>In this blog, let&#8217;s explore how to set up Black Box Exporter on VM(virtual machine). By the end, you&#8217;ll have a clear understanding of the process.<\/p>\n<p>The working nature of the <a href=\"https:\/\/devopscube.com\/blackbox-exporter-on-kubernetes\/\">Black Box exporter<\/a> is a little different than other exporters, if you require to monitor the endpoint of a server then the Blackbox exporter is useful.<\/p>\n<p>This exporter will probe the metrics based on monitoring the health of the server and whether the endpoint is available or not, using protocols such as HTTP, HTTPS, ICMP, TCP, gRPC, and DNS.<\/p>\n<h2 id=\"blackbox-exporter-workflow\"><strong>Blackbox Exporter Workflow<\/strong><\/h2>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/blackbox.png\" class=\"kg-image\" alt=\"set up Black box Exporter: This is the Workflow of Blackbox Exporter \" loading=\"lazy\" width=\"1920\" height=\"1080\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/blackbox.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/blackbox.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1600\/2025\/03\/blackbox.png 1600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/blackbox.png 1920w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>In this setup, we use two separate servers for <a href=\"https:\/\/devopscube.com\/prometheus-architecture\/\">Prometheus<\/a> and Blackbox Exporter, but if you want, you can install both utilities on the same server.<\/p>\n<p>After installing the Blackbox Exporter, we have to configure it for probing the metrics from the target, the configuration is a YAML formatted file, which contains modules, and modules are responsible for choosing the endpoint type.<\/p>\n<p>Blackbox itself doesn&#8217;t collect the information from the target, so for that we need <a href=\"https:\/\/devopscube.com\/prometheus-alert-manager\/\">Prometheus.<\/a><\/p>\n<p>We have to modify the configuration in Prometheus about the scraping interval, and target information. Also, we have to link the Blackbox Exporter to the Prometheus.<\/p>\n<p>Based on the scrape interval, Prometheus tries to scrape the metrics from the Blackbox Exporter, once that response reaches the Blackbox, Blackbox will be triggered to collect the information from the target.<\/p>\n<p>Blackbox Exporter collects the information and stores it in <strong>\/probes<\/strong> the directory, from there. Prometheus pulls them and stores them in the <strong>Time Series Data Base (TSDB).<\/strong><\/p>\n<h2 id=\"setting-up-prometheus-blackbox-exporter-on-virtual-machinevm\"><strong>Setting Up Prometheus Blackbox Exporter on Virtual Machine(VM)<\/strong><\/h2>\n<p>I am using two servers in <a href=\"https:\/\/devopscube.com\/terraform-aws-vpc\/\">AWS<\/a> for this tutorial.<\/p>\n<p><strong>Server 1<\/strong>: The instance type is <strong>t2.medium<\/strong> and the utilities in this server are <strong>Prometheus<\/strong> and <strong>Grafana<\/strong><code>.<\/code><\/p>\n<p><strong>Server 2<\/strong>: This instance type is <strong>t2.micro<\/strong> and the utilities are <strong>Prometheus Blackbox Exporter<\/strong>.<\/p>\n<p>I assume you have the server 1 setup already, so I am skipping that installation part, and let&#8217;s begin to install Blackbox Exporter on the server.<\/p>\n<p>Download Blackbox Exporter binaries from the <a href=\"https:\/\/github.com\/prometheus\/blackbox_exporter\/releases?ref=devopscube.com\">official repository<\/a>. I am using the latest version <strong>v0.24.0<\/strong> for this setup.<\/p>\n<pre><code>https:\/\/github.com\/prometheus\/blackbox_exporter\/releases\/download\/v0.24.0\/blackbox_exporter-0.24.0.linux-amd64.tar.gz<\/code><\/pre>\n<p>Unzip the files.<\/p>\n<pre><code>tar -xvf blackbox_exporter-0.24.0.linux-amd64.tar.gz<\/code><\/pre>\n<p>This will contain the Blackbox executable file and the configuration file.<\/p>\n<p>Open the directory<\/p>\n<pre><code>cd blackbox_exporter-0.24.0.linux-amd64<\/code><\/pre>\n<p>Create a user for Blackbox with no shell access.<\/p>\n<pre><code>sudo useradd -rs \/bin\/false blackbox<\/code><\/pre>\n<p>Create a directory in the <strong>\/etc<\/strong> directory to store the configuration file.<\/p>\n<pre><code>sudo mkdir -p \/etc\/blackbox<\/code><\/pre>\n<p>Move the configuration <code>blackbox.yml<\/code> file to the directory<\/p>\n<pre><code>sudo mv blackbox.yml \/etc\/blackbox<\/code><\/pre>\n<p>Move the executable file <strong>blackbox_exporter<\/strong> to the <strong>\/usr\/local\/bin<\/strong> directory<\/p>\n<pre><code>sudo mv blackbox_exporter \/usr\/local\/bin<\/code><\/pre>\n<p>Change the ownership to the executable file and configuration file to the <strong>Blackbox<\/strong> user.<\/p>\n<pre><code>sudo chown blackbox:blackbox \/usr\/local\/bin\/blackbox_exporter\nsudo chown -R blackbox:blackbox \/etc\/blackbox\/*<\/code><\/pre>\n<p>Create a service file for the Blackbox Exporter <strong>blackbox.service<\/strong><\/p>\n<pre><code>sudo cat &lt;&lt;EOT &gt; \/lib\/systemd\/system\/blackbox.service\n[Unit]\nDescription=Blackbox Exporter Service\nWants=network-online.target\nAfter=network-online.target\n\n[Service]\nType=simple\nUser=blackbox\nGroup=blackbox\nExecStart=\/usr\/local\/bin\/blackbox_exporter \\\n  --config.file=\/etc\/blackbox\/blackbox.yml \\\n  --web.listen-address=\":9115\"\n\nRestart=always\n\n[Install]\nWantedBy=multi-user.target\nEOT\n<\/code><\/pre>\n<p>Enable and start the <strong>blackbox.service<\/strong><\/p>\n<pre><code>sudo systemctl enable blackbox.service\nsudo systemctl start blackbox.service<\/code><\/pre>\n<p>To check the status of the service, use the following command.<\/p>\n<pre><code>sudo systemctl status blackbox.service<\/code><\/pre>\n<p>The port number of the Blackbox Exporter is <strong>9115<\/strong>, by default, the <strong>external probe metrics<\/strong> will be saved in the <code>\/probe<\/code> directory and the <strong>internal metrics<\/strong> will be stored in <strong>\/metrics<\/strong> the directory.<\/p>\n<p>If you want to check it from inside the instance, use the following method.<\/p>\n<pre><code>curl http:\/\/localhost:9115\/metrics<\/code><\/pre>\n<p>If you want to access it over the internet, in the browser, use your instance public IP with the port number <strong>&lt;Public IP&gt;:9115<\/strong>. Then you will get this output.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-152-6.png\" class=\"kg-image\" alt=\"prometheus blackbox exporter dashboard\n\" loading=\"lazy\" width=\"527\" height=\"571\"><\/figure>\n<p>Based on modules, the probe data will be stored here.<\/p>\n<h2 id=\"prometheus-blackbox-exporter-probe-module\"><strong>Prometheus Blackbox Exporter Probe Module<\/strong><\/h2>\n<p>We have to create <strong>modules<\/strong> in Blackbox, then we will get the <strong>probe metrics<\/strong>. Fundamentally, we have to know which type of <strong>endpoint<\/strong> we are going to monitor because the module should be related to the endpoint.<\/p>\n<p>A simple example module for an HTTP endpoint is<\/p>\n<pre><code>http_endpoint:\n  prober: http\n  timeout: 10s\n  http:\n    valid_http_versions: [\"HTTP\/1.1\", \"HTTP\/2.0\"]\n    valid_status_codes: [200, 204]\n    no_follow_redirects: false\n    preferred_ip_protocol: \"ip4\"<\/code><\/pre>\n<p>This module will be configured in the Blackbox Exporter configuration file, which is <strong>\/etc\/blackbox\/blackbox.yml.<\/strong><\/p>\n<p>The collected probe metrics by this particular module are this<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-2-30.png\" class=\"kg-image\" alt=\"probe metrics\n\" loading=\"lazy\" width=\"2000\" height=\"1717\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-2-30.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/image-2-30.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1600\/2025\/03\/image-2-30.png 1600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w2400\/2025\/03\/image-2-30.png 2400w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>We can further filter and visualize these metrics using <a href=\"https:\/\/devopscube.com\/setup-prometheus-using-docker\/\">Prometheus<\/a> and Grafana utilities.<\/p>\n<h2 id=\"prometheus-blackbox-exporter-endpoint\"><strong>Prometheus Blackbox Exporter Endpoint<\/strong><\/h2>\n<p>The Blackbox Exporter probes the metrics using responses from the endpoint, protocol defining the endpoint types and the supporting protocols,<\/p>\n<ol>\n<li>HTTP<\/li>\n<li>HTTPS<\/li>\n<li>ICMP<\/li>\n<li>TCP<\/li>\n<li>DNS<\/li>\n<li>gRPC<\/li>\n<\/ol>\n<p>We should choose one of the protocols to create a module, for example, if I am taking the <strong>DNS<\/strong> protocol to create a module, I could get the probe metrics like DNS query failure counts, query duration, query count, response size, etc<\/p>\n<h2 id=\"prometheus-blackbox-exporter-real-world-examples\"><strong>Prometheus Blackbox Exporter Real-World Examples<\/strong><\/h2>\n<h3 id=\"create-a-module-using-https-protocol\">Create a module using <code>HTTP(S)<\/code> protocol<\/h3>\n<p>HTTP(S) module can track the SSL\/TLS certificate validation and expiration, so I am creating this module to know that the target web server has a valid SSL\/TLS certificate.<\/p>\n<p>Add this configuration to your Blackbox Exporter configuration file <strong>\/etc\/blackbox\/blackbox.yml<\/strong>.<\/p>\n<pre><code>modules:\n  https_endpoint:\n    prober: http\n    timeout: 15s\n    http:\n      method: GET\n      valid_http_versions:\n        - HTTP\/1.1\n        - HTTP\/2.0\n      fail_if_not_ssl: true\n      no_follow_redirects: false\n      ip_protocol_fallback: false\n      preferred_ip_protocol: ip4\n<\/code><\/pre>\n<p>Here, you can see that the prober is <strong>HTTP<\/strong>, which indicates this module is meant to be an HTTP endpoint, also I am passing another argument <strong>fail_if_not_ssl: true<\/strong> so that if the web server doesn&#8217;t have an SSL\/TLS certificate, the status would fail.<\/p>\n<p>Restart and check the status of the Blackbox Exporter.<\/p>\n<pre><code>sudo systemctl restart blackbox.service\nsudo systemctl status blackbox.service<\/code><\/pre>\n<h3 id=\"update-the-prometheus-configuration-file\">Update the Prometheus configuration file<\/h3>\n<p>Open the <a href=\"https:\/\/devopscube.com\/setup-prometheus-monitoring-on-kubernetes\/\">Prometheus<\/a> configuration file <strong>\/etc\/prometheus\/prometheus.yml<\/strong>, and append the Blackbox configuration with your existing Prometheus configuration.<\/p>\n<p>In the global section, I have given the <strong>scrape_interval<\/strong> time as <strong>5s<\/strong>, which means <a href=\"https:\/\/devopscube.com\/node-exporter-kubernetes\/\">Prometheus<\/a> will pull the metrics from the exporters every 5 seconds. you can modify with your required value.<\/p>\n<p>Under the <strong>scrape_configs<\/strong> section, we have to create a new job for Blackbox Exporter and have to give the <code>metrics_path<\/code>, we already know that the probe metrics will be stored in the<strong>\/probe <\/strong>directory.<\/p>\n<p>I am giving the module value <strong>https_endpoint, which<\/strong> is my module name, and modifying the replacement value with your Blackbox Exporter servers private (if same network) or public IP with port number.<\/p>\n<pre><code>global:\n  scrape_interval: 5s\n  evaluation_interval: 5s\n\nscrape_configs:\n  - job_name: \"blackbox\"\n    metrics_path: \/probe\n    params:\n      module: [https_endpoint]\n    static_configs:\n      - targets:\n        - 35.80.157.25\n        - devopscube.com\n    relabel_configs:\n      - source_labels: [__address__]\n        target_label: __param_target\n      - source_labels: [__param_target]\n        target_label: instance\n      - target_label: __address__\n        replacement: 172.31.19.73:9115<\/code><\/pre>\n<p>I have given <strong>two targets<\/strong> in this configuration file, which are <strong><code>35.80.157.25<\/code><\/strong> and <strong>devopscube.com<\/strong>. The first one has a Nginx web server and doesn&#8217;t have an SSL\/TLS certificate, but the second one has a valid certificate.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-167-4.png\" class=\"kg-image\" alt=\"ssl certificate check\" loading=\"lazy\" width=\"665\" height=\"736\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-167-4.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-167-4.png 665w\"><\/figure>\n<p>Let&#8217;s see if our setup identifies that, before that, we have to restart the Blackbox service and ensure the configurations are properly done.<\/p>\n<pre><code>sudo systemctl restart blackbox.service\nsudo systemctl status blackbox.service<\/code><\/pre>\n<p>Check the <strong>Blackbox Exporter<\/strong> directly. For that open any browser, and paste your Blackbox Exporter public IP and the port number.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-168-3.png\" class=\"kg-image\" alt=\"prometheus black box exporter output\" loading=\"lazy\" width=\"567\" height=\"569\"><\/figure>\n<p>Here it shows that the result of the <strong>devopscube.com<\/strong> is successful and the <strong>35.80.157.24<\/strong> is failed.<\/p>\n<p>If you click the logs, you can view all the probe metrics, which is related to the target.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/carbon-1-1-1.png\" class=\"kg-image\" alt=\"prometheus blackbox exporter metrics dashboard\" loading=\"lazy\" width=\"2000\" height=\"2610\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/carbon-1-1-1.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/carbon-1-1-1.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1600\/2025\/03\/carbon-1-1-1.png 1600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/carbon-1-1-1.png 2152w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>Now I am picking one of the metrics from that to see the results in Prometheus.<\/p>\n<p>To see the presence of the SSL\/TLS certificate, we can use <strong>probe_http_ssl<\/strong> metrics.<\/p>\n<pre><code>probe_http_ssl<\/code><\/pre>\n<p><strong>Prometheus output<\/strong><\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-169-3.png\" class=\"kg-image\" alt=\"prometheus dashboard query\n\" loading=\"lazy\" width=\"717\" height=\"359\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-169-3.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-169-3.png 717w\"><\/figure>\n<p><strong>Grafana output<\/strong><\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-170-2.png\" class=\"kg-image\" alt=\"grafana dashboard visualization\n\" loading=\"lazy\" width=\"712\" height=\"802\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-170-2.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-170-2.png 712w\"><\/figure>\n<h2 id=\"create-a-module-using-tcp-protocol\">Create a module using <code>TCP<\/code> protocol<\/h2>\n<p>The main use case of the <code>TCP<\/code> the based module is used to identify whether a user can reach the target over TCP or not also we can check some SSL-related metrics.<\/p>\n<p>Add this to the Blackbox configuration file <strong>\/etc\/blackbox\/blackbox.yml<\/strong><\/p>\n<pre><code>modules:\n  tcp_module:\n    prober: tcp\n    timeout: 10s\n    tcp:\n      preferred_ip_protocol: \"ip4\"\n      tls: true\n      tls_config:\n        insecure_skip_verify: false\n<\/code><\/pre>\n<p><code>tcp_module<\/code> is the module name, you can modify it if you want, and the <code>prober<\/code> value should be <strong>tcp<\/strong>.<\/p>\n<p>Don&#8217;t forget to restart and view the status of the black-box service <strong>blackbox.service<\/strong>, this will ensure the configurations are properly done.<\/p>\n<p>Update the Prometheus configuration file <strong>\/etc\/prometheus\/prometheus.yml.<\/strong> Add another job or replace it with the existing job if you want.<\/p>\n<pre><code>scrape_configs:\n  - job_name: \"blackbox-tcp\"\n    metrics_path: \/probe\n    params:\n      module: [tcp_module]\n    static_configs:\n      - targets:\n        - 35.80.157.25:443\n        - devopscube.com:443\n    relabel_configs:\n      - source_labels: [__address__]\n        target_label: __param_target\n      - source_labels: [__param_target]\n        target_label: instance\n      - target_label: __address__\n        replacement: 172.31.19.73:9115<\/code><\/pre>\n<p>After updating the configuration file, restart and check the status of the Prometheus service <strong>prometheus.service<\/strong><\/p>\n<blockquote><p>Providing target with the port number is necessary for the TCP module.<\/p><\/blockquote>\n<p>The Blackbox Exporter output is<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-3-34.png\" class=\"kg-image\" alt=\"prometheus blackbox exporter output\" loading=\"lazy\" width=\"868\" height=\"950\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-3-34.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-3-34.png 868w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>Here, the first server doesn&#8217;t have the Transport Layer Security, so it fails and we can view the probe metrics of the second server.<\/p>\n<p>This <strong>tcp_module <\/strong>module collects the probe metrics.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-4-30.png\" class=\"kg-image\" alt=\"blackbox exporter metrics\" loading=\"lazy\" width=\"2000\" height=\"1770\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-4-30.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/image-4-30.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1600\/2025\/03\/image-4-30.png 1600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w2400\/2025\/03\/image-4-30.png 2400w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>I want to know the SSL\/TLS certificate expiry date of the server, for that, I am using <strong>probe_ssl_last_chain_expiry_timestamp_seconds<\/strong> metrics.<\/p>\n<pre><code>probe_ssl_last_chain_expiry_timestamp_seconds<\/code><\/pre>\n<p><strong>Prometheus output<\/strong><\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-5-40.png\" class=\"kg-image\" alt=\"prometheus query\" loading=\"lazy\" width=\"745\" height=\"308\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-5-40.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-5-40.png 745w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>Let&#8217;s calculate this value <strong>1706436139<\/strong> to find the actual date and time of the expiration.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-6-26.png\" class=\"kg-image\" alt=\"timestamp conversion\" loading=\"lazy\" width=\"681\" height=\"559\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-6-26.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-6-26.png 681w\"><\/figure>\n<p>We can cross-verify this by searching the website on Google and viewing the certificate details.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-8-28.png\" class=\"kg-image\" alt=\"ssl certificate\" loading=\"lazy\" width=\"566\" height=\"719\"><\/figure>\n<h3 id=\"create-a-module-using-icmp-the-protocol\">Create a Module Using ICMP the Protocol<\/h3>\n<p>Example for the ICMP module in Blackbox configuration file <strong><code>\/etc\/blackbox\/blackbox.yml<\/code><\/strong>.<\/p>\n<pre><code>modules: \n  ping:\n    prober: icmp\n    timeout: 5s\n    icmp:\n      preferred_ip_protocol: \"ip4\"<\/code><\/pre>\n<p>With this module, we can able to know whether the particular web server or network is reachable or not.<\/p>\n<p>Update the Prometheus configuration file with this module <strong>\/etc\/prometheus\/prometheus.yml<\/strong><\/p>\n<pre><code>scrape_configs:\n  - job_name: \"blackbox-icmp\"\n    metrics_path: \/probe\n    params:\n      module: [ping]\n    static_configs:\n      - targets:\n        - 35.80.157.25\n        - devopscube.com\n    relabel_configs:\n      - source_labels: [__address__]\n        target_label: __param_target\n      - source_labels: [__param_target]\n        target_label: instance\n      - target_label: __address__\n        replacement: 172.31.19.73:9115<\/code><\/pre>\n<p>Before starting testing, I am blocking the port for ICMP protocol in my EC2 instance so that the result should fail.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-172-3.png\" class=\"kg-image\" alt=\"ec2 instance security group inbound rule\" loading=\"lazy\" width=\"1243\" height=\"463\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-172-3.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/image-172-3.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-172-3.png 1243w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>In the Blackbox Exporter, you can see the failure result<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-177-2.png\" class=\"kg-image\" alt=\"blackbox exporter dashboard\" loading=\"lazy\" width=\"812\" height=\"933\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-177-2.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-177-2.png 812w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>I am enabling the <strong>ICMP<\/strong> protocol in the target EC2 instance.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-178-2.png\" class=\"kg-image\" alt=\"aws security group inbound rules\" loading=\"lazy\" width=\"1147\" height=\"667\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-178-2.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/image-178-2.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-178-2.png 1147w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>Now the result is <strong>Success<\/strong>, this ensures that the target server is reachable.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-179-2.png\" class=\"kg-image\" alt=\"blackbox exporter dashboard\n\" loading=\"lazy\" width=\"890\" height=\"1099\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-179-2.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-179-2.png 890w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>If you click the <strong>Logs<\/strong>, you can able to see what are the probe metrics this module collects.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-180-3.png\" class=\"kg-image\" alt=\"blackbox exporter metrics\" loading=\"lazy\" width=\"2000\" height=\"1589\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-180-3.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/image-180-3.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1600\/2025\/03\/image-180-3.png 1600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w2400\/2025\/03\/image-180-3.png 2400w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>Let&#8217;s take one of the metrics from this and make a query in Prometheus to see the results, also we can visualize them with Grafana.<\/p>\n<p>I am choosing the <strong>probe_icmp_duration_seconds <\/strong>metric.<\/p>\n<p><strong>Prometheus output<\/strong><\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-181-2.png\" class=\"kg-image\" alt=\"prometheus operator query\" loading=\"lazy\" width=\"732\" height=\"455\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-181-2.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-181-2.png 732w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p><strong>Grafana output<\/strong><\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-182-3.png\" class=\"kg-image\" alt=\"grafana dashboard\" loading=\"lazy\" width=\"2000\" height=\"795\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-182-3.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/image-182-3.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1600\/2025\/03\/image-182-3.png 1600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-182-3.png 2156w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<h2 id=\"prometheus-blackbox-exporter-use-cases\"><strong>Prometheus Blackbox Exporter Use Cases<\/strong><\/h2>\n<ol>\n<li>We can know whether a particular website or server is currently reachable or not and also analyze how much time it takes to reach it.<\/li>\n<li>Create alerts based on the server&#8217;s health, for example, if the server is not reachable or it is taking too much time to respond, we will get alerts.<\/li>\n<li>SSL\/TLS certificate is one of the essential security components of our servers, we can track whether the certificate is present in the server or is valid.<\/li>\n<li>We all know, that the DNS resolution should be very fast, only then can we access a website real quick, if it is taking too much time, that will kill the user experience, this exporter can check the DNS-related responses.<\/li>\n<\/ol>\n<h2 id=\"conclusion\"><strong>Conclusion<\/strong><\/h2>\n<p>This setup gives you an overall idea about, what is <strong>Blackbox<\/strong> <strong>Exporter <\/strong>and how this utility works with Prometheus.<\/p>\n<p>Here, I have created modules, only for testing purposes, but you can create modules with a lot of customization because the requirements will differ from person to person.<\/p>\n<p>I am attaching the <a href=\"https:\/\/github.com\/prometheus\/blackbox_exporter\/blob\/master\/CONFIGURATION.md?ref=devopscube.com\">official documentation<\/a> with this for your further customization.<\/p>\n<hr>\n<p><strong>Ngu\u1ed3n:<\/strong> <a href=\"https:\/\/devopscube.com\/set-up-blackbox-exporter-on-vm\/\" target=\"_blank\" rel=\"noopener noreferrer\">How To Set Up Blackbox Exporter On VM &#8211; Ultimate Guide \u2014 DevOpsCube<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Source: https:\/\/devopscube.com\/set-up-blackbox-exporter-on-vm\/<\/p>\n","protected":false},"author":1,"featured_media":754,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-753","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops"],"_links":{"self":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts\/753","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=753"}],"version-history":[{"count":0,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts\/753\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/media\/754"}],"wp:attachment":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=753"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=753"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=753"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}