<?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>DEV Community: Enes Altınorak</title>
    <description>The latest articles on DEV Community by Enes Altınorak (@ealtinor).</description>
    <link>https://dev.to/ealtinor</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%2F2454798%2Faadbbe57-01be-4d51-beee-0985f978b4c4.jpg</url>
      <title>DEV Community: Enes Altınorak</title>
      <link>https://dev.to/ealtinor</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ealtinor"/>
    <language>en</language>
    <item>
      <title>Red Hat License Renewal and System Registration Guide</title>
      <dc:creator>Enes Altınorak</dc:creator>
      <pubDate>Sat, 22 Feb 2025 22:22:57 +0000</pubDate>
      <link>https://dev.to/ealtinor/red-hat-license-renewal-and-system-registration-guide-c0</link>
      <guid>https://dev.to/ealtinor/red-hat-license-renewal-and-system-registration-guide-c0</guid>
      <description>&lt;p&gt;This document provides a step-by-step guide on how to renew a Red Hat license and register a system. It also includes common errors and their solutions.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. Checking System Registration Status
&lt;/h2&gt;

&lt;p&gt;To check if the system is registered, run the following command:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;If the system is &lt;strong&gt;not registered&lt;/strong&gt;, you may see an error like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;This system is not registered with an entitlement server. You can use subscription-manager to register.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To check if identity:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;If the system is &lt;strong&gt;not registered&lt;/strong&gt;, you need to register the system.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. Registering the System
&lt;/h2&gt;

&lt;p&gt;Run the following command to register your system using an activation key and organization ID:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;subscription-manager register &lt;span class="nt"&gt;--activationkey&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;YOUR_ACTIVATION_KEY &lt;span class="nt"&gt;--org&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;YOUR_ORG_ID
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;subscription-manager register &lt;span class="nt"&gt;--username&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;****&lt;/span&gt; &lt;span class="nt"&gt;--password&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;****&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I prefer that you register using an activation key.&lt;/p&gt;

&lt;p&gt;Example output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;The system has been registered with ID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After registration, check for available subscriptions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;subscription-manager list &lt;span class="nt"&gt;--available&lt;/span&gt; &lt;span class="nt"&gt;--all&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Find the &lt;strong&gt;Pool ID&lt;/strong&gt; from the output and attach it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;subscription-manager attach &lt;span class="nt"&gt;--pool&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;YOUR_POOL_ID
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Common Issue: Simple Content Access (SCA) Enabled
&lt;/h3&gt;

&lt;p&gt;If you see this message:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Ignoring the request to attach. Attaching subscriptions is disabled &lt;span class="k"&gt;for &lt;/span&gt;organization because Simple Content Access &lt;span class="o"&gt;(&lt;/span&gt;SCA&lt;span class="o"&gt;)&lt;/span&gt; is enabled.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It means the system has &lt;strong&gt;Simple Content Access (SCA) enabled&lt;/strong&gt;, so you don't need to attach a subscription manually.&lt;/p&gt;

&lt;p&gt;You can verify this with:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;If SCA is enabled, you can directly enable repositories.&lt;/p&gt;




&lt;h2&gt;
  
  
  3. Enabling Repositories
&lt;/h2&gt;

&lt;p&gt;Once the system is registered, enable the required repositories:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;subscription-manager repos &lt;span class="nt"&gt;--enable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;rhel-9-for-x86_64-appstream-rpms
subscription-manager repos &lt;span class="nt"&gt;--enable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;rhel-9-for-x86_64-baseos-rpms
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, check available repositories:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;If Red Hat repositories appear in the list, your system is correctly registered.&lt;/p&gt;




&lt;h2&gt;
  
  
  4. Installing Packages and Common Errors
&lt;/h2&gt;

&lt;p&gt;To install a package, such as &lt;strong&gt;net-tools&lt;/strong&gt;, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dnf &lt;span class="nb"&gt;install &lt;/span&gt;net-tools
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you see an error like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Error: Unable to find a match: net-tools
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It means the required repositories are not enabled. Run:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Then retry the installation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dnf &lt;span class="nb"&gt;install &lt;/span&gt;net-tools
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then system update:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dnf update &lt;span class="nt"&gt;-y&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By following these steps, you can successfully renew your Red Hat license and register your system.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to Generate Prometheus Metrics from Logs Collected by Fluentd</title>
      <dc:creator>Enes Altınorak</dc:creator>
      <pubDate>Tue, 19 Nov 2024 14:47:10 +0000</pubDate>
      <link>https://dev.to/ealtinor/how-to-generate-prometheus-metrics-from-logs-collected-by-fluentd-46j8</link>
      <guid>https://dev.to/ealtinor/how-to-generate-prometheus-metrics-from-logs-collected-by-fluentd-46j8</guid>
      <description>&lt;p&gt;In this article, I demonstrate how to generate metrics and create alert on Prometheus from the pod logs. I used &lt;strong&gt;Prometheus&lt;/strong&gt; and &lt;strong&gt;Fluentd&lt;/strong&gt;, both installed via helm charts in my k8s cluster.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Prometheus&lt;/em&gt;&lt;/strong&gt; is an open-source monitoring and alerting toolkit designed for reliability and scalability. It collects and stores metrics as time-series data, providing powerful query capabilities and integrations for setting up alerts based on predefined thresholds.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Fluentd&lt;/em&gt;&lt;/strong&gt; is an open-source data collector used to unify logging infrastructure. It allows users to collect, filter, and route log data from various sources, making it easier to manage logs across distributed systems and direct them to storage or analysis tools like Prometheus.&lt;/p&gt;

&lt;p&gt;By the end of this article, you'll have a clear understanding of how to set up &lt;strong&gt;Prometheus&lt;/strong&gt; and &lt;strong&gt;Fluentd&lt;/strong&gt; in a Kubernetes environment to monitor pod logs, generate metrics, and create custom alerts.&lt;/p&gt;




&lt;p&gt;I have an existing installation of Prometheus on my cluster. If you'd like to install Prometheus, you can look here &lt;a href="https://artifacthub.io/packages/helm/prometheus-community/prometheus" rel="noopener noreferrer"&gt;Prometheus&lt;/a&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We install Prometheus with helm chart, you need to install and configure it to scrape your cluster. Below is an example;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
helm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;RELEASE_NAME] prometheus-community/prometheus &lt;span class="nt"&gt;-n&lt;/span&gt; your-namespace


helm show values prometheus-community/prometheus &lt;span class="nt"&gt;-n&lt;/span&gt; your-namespace &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; values.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;prometheus.yml&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;rule_files&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="c1"&gt;#...&lt;/span&gt;
    &lt;span class="na"&gt;scrape_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;job_name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;prometheus&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;localhost:9090&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;helm upgrade &lt;span class="nt"&gt;--install&lt;/span&gt; release-name chart-name &lt;span class="nt"&gt;-f&lt;/span&gt; values.yaml &lt;span class="nt"&gt;--namespace&lt;/span&gt; your-namespace
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, we will install Fluentd using helm. You can look here &lt;a href="https://artifacthub.io/packages/helm/fluent/fluentd" rel="noopener noreferrer"&gt;Fluentd&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;helm repo add fluent https://fluent.github.io/helm-charts
helm repo update
helm &lt;span class="nb"&gt;install &lt;/span&gt;fluentd fluent/fluentd &lt;span class="nt"&gt;--namespace&lt;/span&gt; your-namespace
helm show values fluent/fluentd &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; values.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;After installation, patch the values.yaml file to configure. Be sure to replace "pod-name" with the actual name of your pod. If you'd like to more information, you can look at this documentation&lt;a href="https://docs.fluentd.org/" rel="noopener noreferrer"&gt;Fluentd Documentation&lt;/a&gt;.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;fileConfigs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;01_base_config.conf&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;|-&lt;/span&gt;
    &lt;span class="s"&gt;&amp;lt;source&amp;gt;&lt;/span&gt;
      &lt;span class="s"&gt;@type tail&lt;/span&gt;
      &lt;span class="s"&gt;path /var/log/containers/*pod-name*.log&lt;/span&gt;
      &lt;span class="s"&gt;pos_file /var/log/fluentd/pod-name.pos&lt;/span&gt;
      &lt;span class="s"&gt;tag fluentd&lt;/span&gt;
      &lt;span class="s"&gt;&amp;lt;parse&amp;gt;&lt;/span&gt;
        &lt;span class="s"&gt;@type multi_format&lt;/span&gt;
        &lt;span class="s"&gt;&amp;lt;pattern&amp;gt;&lt;/span&gt;
          &lt;span class="s"&gt;format json&lt;/span&gt;
          &lt;span class="s"&gt;time_key time&lt;/span&gt;
          &lt;span class="s"&gt;time_type string&lt;/span&gt;
          &lt;span class="s"&gt;time_format "%Y-%m-%dT%H:%M:%S.%NZ"&lt;/span&gt;
          &lt;span class="s"&gt;keep_time_key false&lt;/span&gt;
        &lt;span class="s"&gt;&amp;lt;/pattern&amp;gt;&lt;/span&gt;
        &lt;span class="s"&gt;&amp;lt;pattern&amp;gt;&lt;/span&gt;
          &lt;span class="s"&gt;format regexp&lt;/span&gt;
          &lt;span class="s"&gt;expression /^(?&amp;lt;time&amp;gt;.+) (?&amp;lt;stream&amp;gt;stdout|stderr)( (.))? (?&amp;lt;log&amp;gt;.*)$/&lt;/span&gt;
          &lt;span class="s"&gt;time_format '%Y-%m-%dT%H:%M:%S.%NZ'&lt;/span&gt;
          &lt;span class="s"&gt;keep_time_key false&lt;/span&gt;
        &lt;span class="s"&gt;&amp;lt;/pattern&amp;gt;&lt;/span&gt;
      &lt;span class="s"&gt;&amp;lt;/parse&amp;gt;&lt;/span&gt;
    &lt;span class="s"&gt;&amp;lt;/source&amp;gt;&lt;/span&gt;

    &lt;span class="s"&gt;&amp;lt;filter fluentd&amp;gt;&lt;/span&gt;
      &lt;span class="s"&gt;@type grep&lt;/span&gt;
      &lt;span class="s"&gt;@id grep_fluentd&lt;/span&gt;
      &lt;span class="s"&gt;&amp;lt;regexp&amp;gt;&lt;/span&gt;
        &lt;span class="s"&gt;key log&lt;/span&gt;
        &lt;span class="s"&gt;pattern /.*(ERROR|error).*/&lt;/span&gt;
      &lt;span class="s"&gt;&amp;lt;/regexp&amp;gt;&lt;/span&gt;
    &lt;span class="s"&gt;&amp;lt;/filter&amp;gt;&lt;/span&gt;

    &lt;span class="s"&gt;&amp;lt;filter fluentd&amp;gt;&lt;/span&gt;
      &lt;span class="s"&gt;@type prometheus&lt;/span&gt;
      &lt;span class="s"&gt;&amp;lt;metric&amp;gt;&lt;/span&gt;
        &lt;span class="s"&gt;name fluentd_error_count&lt;/span&gt;
        &lt;span class="s"&gt;type counter&lt;/span&gt;
        &lt;span class="s"&gt;desc fluentd error&lt;/span&gt;
      &lt;span class="s"&gt;&amp;lt;/metric&amp;gt;&lt;/span&gt;
    &lt;span class="s"&gt;&amp;lt;/filter&amp;gt;&lt;/span&gt;

    &lt;span class="s"&gt;&amp;lt;match fluentd&amp;gt;&lt;/span&gt;
      &lt;span class="s"&gt;@type stdout&lt;/span&gt;
      &lt;span class="s"&gt;@id match_fluentd&lt;/span&gt;
    &lt;span class="s"&gt;&amp;lt;/match&amp;gt;&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;helm upgrade &lt;span class="nt"&gt;--install&lt;/span&gt; fluentd fluent/fluentd &lt;span class="nt"&gt;-f&lt;/span&gt; values.yaml &lt;span class="nt"&gt;--namespace&lt;/span&gt; your-namespace
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The configuration includes a source for reading logs, filters for processing and filtering logs, and a match directive for outputting logs. Here's a breakdown of each section in this configuration:&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Source Section(&lt;code&gt;&amp;lt;source&amp;gt;&lt;/code&gt;):
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;&amp;lt;source&amp;gt;&lt;/code&gt; block defines where and how Fluentd should read logs. In this case, it's set up to tail log files.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="s"&gt;&amp;lt;source&amp;gt;&lt;/span&gt;
  &lt;span class="s"&gt;@type tail&lt;/span&gt;
  &lt;span class="s"&gt;path /var/log/containers/*pod-name*.log&lt;/span&gt;
  &lt;span class="s"&gt;pos_file /var/log/fluentd/pod-name.pos&lt;/span&gt;
  &lt;span class="s"&gt;tag fluentd&lt;/span&gt;
  &lt;span class="s"&gt;&amp;lt;parse&amp;gt;&lt;/span&gt;
    &lt;span class="s"&gt;@type multi_format&lt;/span&gt;
    &lt;span class="s"&gt;...&lt;/span&gt;
  &lt;span class="s"&gt;&amp;lt;/parse&amp;gt;&lt;/span&gt;
&lt;span class="s"&gt;&amp;lt;/source&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;@type tail&lt;/code&gt;: Specifies that Fluentd should read the logs by tailing a file (continuous reading as new lines are added).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;path /var/log/containers/*pod-name*.log&lt;/code&gt;: The path to the log files Fluentd should read. It looks for files that match &lt;code&gt;*pod-name*&lt;/code&gt; in their name, which allows filtering by specific pod names.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;pos_file /var/log/fluentd/pod-name.pos&lt;/code&gt;: The position file records the last read position in the log file, enabling Fluentd to continue from the last position if it restarts.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;tag fluentd&lt;/code&gt;: Assigns the tag &lt;code&gt;fluentd&lt;/code&gt; to the logs read from this source, which is useful for routing and filtering logs within Fluentd.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Log Parsing (&lt;code&gt;&amp;lt;parse&amp;gt;&lt;/code&gt;)
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;&amp;lt;parse&amp;gt;&lt;/code&gt; block defines the log formats that Fluentd should recognize in these files. This config uses a &lt;code&gt;multi_format&lt;/code&gt; parser, allowing it to handle different log formats.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="s"&gt;&amp;lt;parse&amp;gt;&lt;/span&gt;
  &lt;span class="s"&gt;@type multi_format&lt;/span&gt;
  &lt;span class="s"&gt;&amp;lt;pattern&amp;gt;&lt;/span&gt;
    &lt;span class="s"&gt;format json&lt;/span&gt;
    &lt;span class="s"&gt;time_key time&lt;/span&gt;
    &lt;span class="s"&gt;time_type string&lt;/span&gt;
    &lt;span class="s"&gt;time_format "%Y-%m-%dT%H:%M:%S.%NZ"&lt;/span&gt;
    &lt;span class="s"&gt;keep_time_key &lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;
  &lt;span class="s"&gt;&amp;lt;/pattern&amp;gt;&lt;/span&gt;
  &lt;span class="s"&gt;&amp;lt;pattern&amp;gt;&lt;/span&gt;
    &lt;span class="s"&gt;format regexp&lt;/span&gt;
    &lt;span class="s"&gt;expression /^(?&amp;lt;time&amp;gt;.+) (?&amp;lt;stream&amp;gt;stdout|stderr)( (.))? (?&amp;lt;log&amp;gt;.*)$/&lt;/span&gt;
    &lt;span class="s"&gt;time_format '%Y-%m-%dT%H:%M:%S.%NZ'&lt;/span&gt;
    &lt;span class="s"&gt;keep_time_key &lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;
  &lt;span class="s"&gt;&amp;lt;/pattern&amp;gt;&lt;/span&gt;
&lt;span class="s"&gt;&amp;lt;/parse&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;@type multi_format&lt;/code&gt;: Allows Fluentd to match multiple log formats.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;First &lt;code&gt;&amp;lt;pattern&amp;gt;&lt;/code&gt; (JSON):&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;format json&lt;/code&gt;: Specifies that the log format is JSON.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;time_key time&lt;/code&gt;: Identifies the key in JSON that represents the timestamp.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;time_format "%Y-%m-%dT%H:%M:%S.%NZ"&lt;/code&gt;: Specifies the timestamp format in the JSON logs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;keep_time_key false&lt;/code&gt;: Removes the original &lt;code&gt;time&lt;/code&gt; key after parsing.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Second &lt;code&gt;&amp;lt;pattern&amp;gt;&lt;/code&gt; (Regular Expression):&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;format regexp&lt;/code&gt;: Specifies that the format is a regular expression.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;expression&lt;/code&gt;: Regular expression pattern to extract fields from log lines that don’t follow JSON format.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;time_format&lt;/code&gt;: Specifies the timestamp format.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;This pattern captures the following fields:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;time&lt;/code&gt;: The timestamp.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;stream&lt;/code&gt;: Specifies if the log is from stdout or stderr.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;log&lt;/code&gt;: The main log message content.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  2. Filter Section (&lt;code&gt;&amp;lt;filter&amp;gt;&lt;/code&gt;):
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;&amp;lt;filter&amp;gt;&lt;/code&gt; blocks apply transformations and filters to the log entries tagged with &lt;code&gt;fluentd&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Filter - Grep&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="s"&gt;&amp;lt;filter fluentd&amp;gt;&lt;/span&gt;
  &lt;span class="s"&gt;@type grep&lt;/span&gt;
  &lt;span class="s"&gt;@id grep_fluentd&lt;/span&gt;
  &lt;span class="s"&gt;&amp;lt;regexp&amp;gt;&lt;/span&gt;
    &lt;span class="s"&gt;key log&lt;/span&gt;
    &lt;span class="s"&gt;pattern /.*(ERROR|error).*/&lt;/span&gt;
  &lt;span class="s"&gt;&amp;lt;/regexp&amp;gt;&lt;/span&gt;
&lt;span class="s"&gt;&amp;lt;/filter&amp;gt;&lt;/span&gt;


&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;`@type grep`&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;This filter only allows log entries that match certain patterns.&lt;/span&gt;
&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;`&amp;lt;regexp&amp;gt;`&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;`key log`&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Specifies that the `log` field should be checked.&lt;/span&gt;
&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;`pattern /.(ERROR|error)./`&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Matches log entries containing the words `ERROR` or `error`. Only logs that match this pattern will pass through, filtering out non-error logs.&lt;/span&gt;

&lt;span class="s"&gt;Second Filter - Prometheus Metrics&lt;/span&gt;

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

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
yaml&lt;br&gt;
&lt;br&gt;
  @type prometheus&lt;br&gt;
  &lt;br&gt;
    name fluentd_error_count&lt;br&gt;
    type counter&lt;br&gt;
    desc fluentd error&lt;br&gt;
  &lt;br&gt;
&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;@type prometheus&lt;/code&gt;: This filter creates Prometheus metrics based on the logs.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Metric Configuration&lt;/code&gt;:&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;name fluentd_error_count&lt;/code&gt;: The name of the Prometheus counter metric.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;type counter&lt;/code&gt;: Specifies that this metric is a counter, which increments with each matching log entry.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;desc fluentd error&lt;/code&gt;: A description for this metric, which could be displayed in Prometheus.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  3. Match Section (&lt;code&gt;&amp;lt;match&amp;gt;&lt;/code&gt;):
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;&amp;lt;match&amp;gt;&lt;/code&gt; block specifies what Fluentd should do with the filtered logs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="s"&gt;&amp;lt;match fluentd&amp;gt;&lt;/span&gt;
  &lt;span class="s"&gt;@type stdout&lt;/span&gt;
  &lt;span class="s"&gt;@id match_fluentd&lt;/span&gt;
&lt;span class="s"&gt;&amp;lt;/match&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;@type stdout&lt;/code&gt;: This output plugin writes logs to stdout. In a Kubernetes environment, this means logs will be visible in the pod's logs.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;@id match_fluentd&lt;/code&gt;: Identifier for this match block.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;After upgrade, you can view the existing metrics. First, you must do port-forward to the relevant service or pod. You can send a request to access the metrics.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="s"&gt;kubectl port-forward service/fluentd 24231:24231 --namespace your-namespace&lt;/span&gt;
&lt;span class="s"&gt;curl http://127.0.0.1:24231/metrics&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;You can now view metrics. For example;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# TYPE fluentd_error_count counter
# HELP fluentd_error_count fluentd error
fluentd_error_count 42.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If everything has been successful up to this point, we now need to configure Prometheus to scrape Fluentd service or pod.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;If you have one or more nodes, you need to scrape the node where the pod whose logs you want to collect is running. Otherwise, you might not see the metrics. If there is only one nodes, this isn't an issue. If the pod is on multiple nodes, you can choose to scrape each node individually or you can scrape the Fluentd service directly.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;prometheus.yml&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;rule_files&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="c1"&gt;#...&lt;/span&gt;
    &lt;span class="na"&gt;scrape_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;job_name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;prometheus&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;localhost:9090&lt;/span&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="s"&gt;fluentd&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;/metrics&lt;/span&gt;
        &lt;span class="na"&gt;scrape_interval&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;15s&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;&amp;lt;node-ip or pod ip&amp;gt;:24231&lt;/span&gt;
            &lt;span class="na"&gt;labels&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
              &lt;span class="na"&gt;instance&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;fluentd-node-&amp;lt;node-name&amp;gt;&lt;/span&gt;

&lt;span class="c1"&gt;# or you can scrape service&lt;/span&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="s"&gt;fluentd&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;/metrics&lt;/span&gt;
        &lt;span class="na"&gt;scrape_interval&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;15s&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="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;fluentd.your-namespace.svc.cluster.local:24231'&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;helm upgrade &lt;span class="nt"&gt;--install&lt;/span&gt; release-name chart-name &lt;span class="nt"&gt;-f&lt;/span&gt; values.yaml &lt;span class="nt"&gt;--namespace&lt;/span&gt; your-namespace
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that Prometheus is installed and configured, we need to view the metrics in the Prometheus UI. To access it, you can use &lt;strong&gt;port-forwarding&lt;/strong&gt; to create a secure tunnel from your local machine to the Prometheus service or pod within your Kubernetes cluster.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl port-forward service/prometheus-server &amp;lt;local-port&amp;gt;:&amp;lt;target-port&amp;gt; &lt;span class="nt"&gt;--namespace&lt;/span&gt; your-namespace
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Then, open any browser and go to the following URL -&amp;gt; &lt;a href="http://localhost:local-port/graph" rel="noopener noreferrer"&gt;http://localhost:local-port/graph&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F3icociaxf05sctequnry.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F3icociaxf05sctequnry.png" alt="Prometheus UI" width="800" height="87"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After executing the request, you will be able to view the metrics and their counts.&lt;/p&gt;

&lt;p&gt;If everything has been successful up to this point, you can create an alert for the metric on Prometheus. You can create alert based on your needs. For example;&lt;br&gt;
&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;alerting_rules.yml&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;groups&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;fluentd_error_alerts&lt;/span&gt;
        &lt;span class="na"&gt;rules&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;alert&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;FluentdErrorsDetected&lt;/span&gt;
            &lt;span class="na"&gt;expr&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;increase(fluentd_error_count[1m]) &amp;gt; &lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;
            &lt;span class="na"&gt;labels&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
              &lt;span class="na"&gt;severity&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;critical&lt;/span&gt;
            &lt;span class="na"&gt;annotations&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
              &lt;span class="na"&gt;summary&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Fluentd&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;errors&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;detected&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;on&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;{{&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;$labels.instance&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;}}"&lt;/span&gt;
              &lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;The&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;fluentd_error_count&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;metric&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;increased.&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;Check&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;Fluentd&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;logs&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;on&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;{{&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;$labels.instance&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;}}&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;for&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;more&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;details."&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;helm upgrade &lt;span class="nt"&gt;--install&lt;/span&gt; release-name chart-name &lt;span class="nt"&gt;-f&lt;/span&gt; values.yaml &lt;span class="nt"&gt;--namespace&lt;/span&gt; your-namespace
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;Thank you for reading until the end! I hope this guide helped you understand how to deploy and configure Prometheus, Fluentd using Helm. With these basics covered, you're well on your way to monitoring and managing your Kubernetes environment effectively.&lt;/p&gt;

&lt;p&gt;In my next article, "How to Send Prometheus Alerts as Email and Teams Channel Notifications," we'll explore how to set up alerting for critical issues.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.linkedin.com/in/ensaltnrk/" rel="noopener noreferrer"&gt;Linkedin&lt;/a&gt;&lt;br&gt;
&lt;a href="https://medium.com/@enesaltinorak" rel="noopener noreferrer"&gt;Medium&lt;/a&gt;&lt;/p&gt;

</description>
      <category>devops</category>
      <category>kubernetes</category>
      <category>monitoring</category>
    </item>
  </channel>
</rss>
