<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Sending logs from the cloud on Grafana Labs</title><link>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/cloud/</link><description>Recent content in Sending logs from the cloud on Grafana Labs</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="/docs/enterprise-logs/v3.6.x/send-data/promtail/cloud/index.xml" rel="self" type="application/rss+xml"/><item><title>Run the Promtail client on AWS EC2</title><link>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/cloud/ec2/</link><pubDate>Sat, 11 Apr 2026 00:53:11 +0000</pubDate><guid>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/cloud/ec2/</guid><content><![CDATA[&lt;h1 id=&#34;run-the-promtail-client-on-aws-ec2&#34;&gt;Run the Promtail client on AWS EC2&lt;/h1&gt;
&lt;p&gt;In this tutorial we&amp;rsquo;re going to setup &lt;a href=&#34;../../&#34;&gt;Promtail&lt;/a&gt; on an AWS EC2 instance and configure it to sends all its logs to a Grafana Loki instance.&lt;/p&gt;


&lt;div data-shared=&#34;promtail-deprecation.md&#34;&gt;
            

&lt;div class=&#34;admonition admonition-caution&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Caution&lt;/p&gt;&lt;p&gt;Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href=&#34;/docs/alloy/latest/set-up/migrate/from-promtail/&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;/div&gt;

        
&lt;h2 id=&#34;requirements&#34;&gt;Requirements&lt;/h2&gt;
&lt;p&gt;Before you start you&amp;rsquo;ll need:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;An AWS account (with the &lt;code&gt;AWS_ACCESS_KEY&lt;/code&gt; and &lt;code&gt;AWS_SECRET_KEY&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;A VPC that is routable from the internet. (Follow those &lt;a href=&#34;https://docs.aws.amazon.com/vpc/latest/userguide/vpc-subnets-commands-example.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;instructions&lt;/a&gt; if you need to create one)&lt;/li&gt;
&lt;li&gt;A SSH public key. (Follow those &lt;a href=&#34;https://confluence.atlassian.com/bitbucketserver/creating-ssh-keys-776639788.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;instructions&lt;/a&gt; if you need a new one)&lt;/li&gt;
&lt;li&gt;The &lt;a href=&#34;https://aws.amazon.com/cli/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;AWS CLI&lt;/a&gt; configured (run &lt;code&gt;aws configure&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;A Grafana instance with a Loki data source already configured, you can use &lt;a href=&#34;/signup/&#34;&gt;GrafanaCloud&lt;/a&gt; free trial.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For the sake of simplicity we&amp;rsquo;ll use a Grafana Cloud Loki and Grafana instances, you can get a free account for this tutorial at [Grafana Cloud], but all the steps are the same if you&amp;rsquo;re running your own Open Source version of Loki and Grafana instances.&lt;/p&gt;
&lt;p&gt;To make it easy to learn all the following instructions are manual, however in a real setup we recommend you to use provisioning tools such as &lt;a href=&#34;https://www.terraform.io/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Terraform&lt;/a&gt;, &lt;a href=&#34;https://aws.amazon.com/fr/cloudformation/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;CloudFormation&lt;/a&gt;, &lt;a href=&#34;https://www.ansible.com/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Ansible&lt;/a&gt; or &lt;a href=&#34;https://www.chef.io/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Chef&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;creating-an-ec2-instance&#34;&gt;Creating an EC2 instance&lt;/h2&gt;
&lt;p&gt;As a first step we&amp;rsquo;re going to import our SSH key to AWS so that we can SSH to our future EC2 instance, let&amp;rsquo;s run our first command:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;aws ec2 import-key-pair --key-name &amp;#34;promtail-ec2&amp;#34; --public-key-material fileb://~/.ssh/id_rsa.pub&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Next we&amp;rsquo;re going to create a &lt;a href=&#34;https://docs.aws.amazon.com/vpc/latest/userguide/VPC_SecurityGroups.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;security group&lt;/a&gt;, make sure to note the group id, we&amp;rsquo;ll need it for the following command:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;aws ec2 create-security-group --group-name promtail-ec2  --description &amp;#34;promtail on ec2&amp;#34; --vpc-id vpc-668d120f
{
    &amp;#34;GroupId&amp;#34;: &amp;#34;sg-02c489bbdeffdca1d&amp;#34;
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Now let&amp;rsquo;s authorize inbound access for SSH and &lt;a href=&#34;../../&#34;&gt;Promtail&lt;/a&gt; server:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;aws ec2 authorize-security-group-ingress --group-id sg-02c489bbdeffdca1d --protocol tcp --port 22 --cidr 0.0.0.0/0
aws ec2 authorize-security-group-ingress --group-id sg-02c489bbdeffdca1d --protocol tcp --port 3100 --cidr 0.0.0.0/0&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;You don&amp;rsquo;t need to open those ports to all IPs as shown above you can use your own IP range.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;We&amp;rsquo;re going to create an &lt;a href=&#34;https://aws.amazon.com/amazon-linux-2/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Amazon Linux 2&lt;/a&gt; instance as this is one of the most popular but feel free to use the AMI of your choice.&lt;/p&gt;
&lt;p&gt;To create the instance use the following command, make sure to note the instance id:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;aws ec2 run-instances --image-id ami-016b213e65284e9c9 --count 1 --instance-type t2.micro --key-name promtail-ec2 --security-groups promtail-ec2&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;To make it more interesting later let&amp;rsquo;s tag (&lt;code&gt;Name=promtail-demo&lt;/code&gt;) our instance:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;aws ec2 create-tags --resources i-041b0be05c2d5cfad --tags Key=Name,Value=promtail-demo&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;Tags enable you to categorize your AWS resources in different ways, for example, by purpose, owner, or environment. This is useful when you have many resources of the same type—you can quickly identify a specific resource based on the tags that you&amp;rsquo;ve assigned to it. You&amp;rsquo;ll see later, Promtail can transform those tags into [Loki labels][labels].&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;Finally let&amp;rsquo;s grab the public DNS of our instance:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;aws ec2 describe-instances --filters &amp;#34;Name=tag:Name,Values=promtail-demo&amp;#34; --query &amp;#34;Reservations[].Instances[].NetworkInterfaces[].Association.PublicDnsName&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;and start an SSH session:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;ssh ec2-user@ec2-13-59-62-37.us-east-2.compute.amazonaws.com&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;setting-up-promtail&#34;&gt;Setting up Promtail&lt;/h2&gt;
&lt;p&gt;First let&amp;rsquo;s make sure we&amp;rsquo;re running as root by using &lt;code&gt;sudo -s&lt;/code&gt;.
Next we&amp;rsquo;ll download, install and give executable right to &lt;a href=&#34;../../&#34;&gt;Promtail&lt;/a&gt;.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;mkdir /opt/promtail &amp;amp;&amp;amp; cd /opt/promtail
curl -O -L &amp;#34;https://github.com/grafana/loki/releases/download/v2.0.0/promtail-linux-amd64.zip&amp;#34;
unzip &amp;#34;promtail-linux-amd64.zip&amp;#34;
chmod a&amp;#43;x &amp;#34;promtail-linux-amd64&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Now we&amp;rsquo;re going to download the &lt;a href=&#34;../../&#34;&gt;Promtail configuration&lt;/a&gt; file below and edit it, don&amp;rsquo;t worry we will explain what those means.
The file is also available as a gist at &lt;a href=&#34;https://gist.github.com/cyriltovena/d0881cc717757db951b642be48c01445&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;cyriltovena/promtail-ec2.yaml&lt;/a&gt;.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;curl https://raw.githubusercontent.com/grafana/loki/main/docs/sources/send-data/promtail/cloud/ec2/promtail-ec2.yaml &amp;gt; ec2-promtail.yaml
vi ec2-promtail.yaml&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;YAML&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-yaml&#34;&gt;server:
  http_listen_port: 3100
  grpc_listen_port: 0

clients:
  - url: https://&amp;lt;user id&amp;gt;:&amp;lt;api secret&amp;gt;@logs-prod-us-central1.grafana.net/loki/api/v1/push

positions:
  filename: /opt/promtail/positions.yaml

scrape_configs:
  - job_name: ec2-logs
    ec2_sd_configs:
      - region: us-east-2
        access_key: REDACTED
        secret_key: REDACTED
    relabel_configs:
      - source_labels: [__meta_ec2_tag_Name]
        target_label: name
        action: replace
      - source_labels: [__meta_ec2_instance_id]
        target_label: instance
        action: replace
      - source_labels: [__meta_ec2_availability_zone]
        target_label: zone
        action: replace
      - action: replace
        replacement: /var/log/**.log
        target_label: __path__
      - source_labels: [__meta_ec2_private_dns_name]
        regex: &amp;#34;(.*)&amp;#34;
        target_label: __host__&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The &lt;strong&gt;server&lt;/strong&gt; section indicates Promtail to bind his http server to 3100. Promtail serves HTTP pages for &lt;a href=&#34;../../troubleshooting/&#34;&gt;troubleshooting&lt;/a&gt; service discovery and targets.&lt;/p&gt;
&lt;p&gt;The &lt;strong&gt;clients&lt;/strong&gt; section allow you to target your loki instance, if you&amp;rsquo;re using GrafanaCloud simply replace &lt;code&gt;&amp;lt;user id&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;api secret&amp;gt;&lt;/code&gt; with your credentials. Otherwise just replace the whole URL with your custom Loki instance.(e.g &lt;code&gt;http://my-loki-instance.my-org.com/loki/api/v1/push&lt;/code&gt;)&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;../../&#34;&gt;Promtail&lt;/a&gt; uses the same &lt;a href=&#34;https://prometheus.io/docs/prometheus/latest/configuration/configuration/#scrape_config&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Prometheus &lt;strong&gt;scrape_configs&lt;/strong&gt;&lt;/a&gt;. This means if you already own a Prometheus instance the config will be very similar and easy to grasp.&lt;/p&gt;
&lt;p&gt;Since we&amp;rsquo;re running on AWS EC2 we want to uses EC2 service discovery, this will allows us to scrape metadata about the current instance (and even your custom tags) and attach those to our logs. This way managing and querying on logs will be much easier.&lt;/p&gt;
&lt;p&gt;Make sure to replace accordingly you current &lt;code&gt;region&lt;/code&gt;, &lt;code&gt;access_key&lt;/code&gt; and &lt;code&gt;secret_key&lt;/code&gt;, alternatively you can use an &lt;a href=&#34;https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;AWS Role&lt;/a&gt; ARN, for more information about this, see documentation for &lt;a href=&#34;https://prometheus.io/docs/prometheus/latest/configuration/configuration/#ec2_sd_config&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;&lt;code&gt;ec2_sd_config&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Finally the &lt;a href=&#34;https://prometheus.io/docs/prometheus/latest/configuration/configuration/#relabel_config&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;&lt;code&gt;relabeling_configs&lt;/code&gt;&lt;/a&gt; section has three purposes:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Selecting the labels discovered you want to attach to your targets. In our case here, we&amp;rsquo;re keeping &lt;code&gt;instance_id&lt;/code&gt; as instance, the tag &lt;code&gt;Name&lt;/code&gt; as name and the &lt;code&gt;zone&lt;/code&gt; of the instance. Make sure to check out the Prometheus &lt;a href=&#34;https://prometheus.io/docs/prometheus/latest/configuration/configuration/#ec2_sd_config&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;&lt;code&gt;ec2_sd_config&lt;/code&gt;&lt;/a&gt; documentation for the full list of available labels.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Choosing where Promtail should find log files to tail, in our example we want to include all log files that exist in &lt;code&gt;/var/log&lt;/code&gt; using the glob &lt;code&gt;/var/log/**.log&lt;/code&gt;. If you need to use multiple glob, you can simply add another job in your &lt;code&gt;scrape_configs&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Ensuring discovered targets are only for the machine Promtail currently runs on. This is achieved by adding the label &lt;code&gt;__host__&lt;/code&gt; using the incoming metadata &lt;code&gt;__meta_ec2_private_dns_name&lt;/code&gt;. If it doesn&amp;rsquo;t match the current &lt;code&gt;HOSTNAME&lt;/code&gt; environment variable, the target will be dropped.
If &lt;code&gt;__meta_ec2_private_dns_name&lt;/code&gt; doesn&amp;rsquo;t match your instance&amp;rsquo;s hostname (on EC2 Windows instance for example, where it is the IP address and not the hostname), you can hardcode the hostname at this stage, or check if any of the instances tag contain the hostname (&lt;code&gt;__meta_ec2_tag_&amp;lt;tagkey&amp;gt;: each tag value of the instance&lt;/code&gt;)&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Alright we should be ready to fire up Promtail, we&amp;rsquo;re going to run it using the flag &lt;code&gt;--dry-run&lt;/code&gt;. This is perfect to ensure everything is correctly, specially when you&amp;rsquo;re still playing around with the configuration. Don&amp;rsquo;t worry when using this mode, Promtail won&amp;rsquo;t send any logs and won&amp;rsquo;t remember any file positions.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt; ./promtail-linux-amd64 -config.file=./ec2-promtail.yaml --dry-run&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;If everything is going well Promtail should print out log lines with their labels discovered instead of sending them to Loki, like shown below:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;2020-07-08T14:51:38-0700	{filename=&amp;#34;/var/log/cloud-init.log&amp;#34;, instance=&amp;#34;i-041b0be05c2d5cfad&amp;#34;, name=&amp;#34;promtail-demo&amp;#34;, zone=&amp;#34;us-east-2c&amp;#34;}	Jul 07 21:37:24 cloud-init[3035]: util.py[DEBUG]: loaded blob returned None, returning default.&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Don&amp;rsquo;t hesitate to edit the your config file and start Promtail again to try your config out.&lt;/p&gt;
&lt;p&gt;If you want to see existing targets and available labels you can reach Promtail server using the public dns assigned to your instance:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;open http://ec2-13-59-62-37.us-east-2.compute.amazonaws.com:3100/&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;For example the page below is the service discovery page. It shows you all discovered targets, with their respective available labels and the reason it was dropped if it was the case.&lt;/p&gt;
&lt;figure
    class=&#34;figure-wrapper figure-wrapper__lightbox w-100p &#34;
    style=&#34;max-width: px;&#34;
    itemprop=&#34;associatedMedia&#34;
    itemscope=&#34;&#34;
    itemtype=&#34;http://schema.org/ImageObject&#34;
  &gt;&lt;a
        class=&#34;lightbox-link&#34;
        href=&#34;./promtail-ec2-discovery.png&#34;
        itemprop=&#34;contentUrl&#34;
      &gt;&lt;div class=&#34;img-wrapper w-100p h-auto&#34;&gt;&lt;img
          class=&#34;lazyload &#34;
          data-src=&#34;./promtail-ec2-discovery.png&#34;alt=&#34;Service discovery page&#34;/&gt;
        &lt;noscript&gt;
          &lt;img
            src=&#34;./promtail-ec2-discovery.png&#34;
            alt=&#34;Service discovery page&#34;/&gt;
        &lt;/noscript&gt;&lt;/div&gt;&lt;/a&gt;&lt;/figure&gt;
&lt;p&gt;This page is really useful to understand what labels are available to forward with the &lt;code&gt;relabeling&lt;/code&gt; configuration but also why Promtail is not scraping your target.&lt;/p&gt;
&lt;h2 id=&#34;configuring-promtail-as-a-service&#34;&gt;Configuring Promtail as a service&lt;/h2&gt;
&lt;p&gt;Now that we have correctly configured Promtail. We usually want to make sure it runs as a &lt;a href=&#34;https://www.freedesktop.org/software/systemd/man/systemd.service.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;systemd service&lt;/a&gt;, so it can automatically restart on failure or when the instance restart.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s create a new service using &lt;code&gt;vim /etc/systemd/system/promtail.service&lt;/code&gt; and copy the service definition below:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;systemd&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-systemd&#34;&gt;[Unit]
Description=Promtail

[Service]
User=root
WorkingDirectory=/opt/promtail/
ExecStartPre=/bin/sleep 30
ExecStart=/opt/promtail/promtail-linux-amd64 --config.file=./ec2-promtail.yaml
SuccessExitStatus=143
TimeoutStopSec=10
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Let&amp;rsquo;s reload the systemd, enable then start the Promtail service:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;systemctl daemon-reload
systemctl enable promtail.service
systemctl start promtail.service&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;You can verify that the service run correctly using the following command:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;systemctl status promtail.service -l

● promtail.service - Promtail
   Loaded: loaded (/etc/systemd/system/promtail.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2020-07-08 15:48:57 UTC; 4s ago
 Main PID: 2732 (promtail-linux-)
   CGroup: /system.slice/promtail.service
           └─2732 /opt/promtail/promtail-linux-amd64 --config.file=./ec2-promtail.yaml

Jul 08 15:48:57 ip-172-31-45-69.us-east-2.compute.internal systemd[1]: Started Promtail.
Jul 08 15:48:57 ip-172-31-45-69.us-east-2.compute.internal systemd[1]: Starting Promtail...
Jul 08 15:48:57 ip-172-31-45-69.us-east-2.compute.internal promtail-linux-amd64[2732]: level=warn ts=2020-07-08T15:48:57.559085451Z caller=filetargetmanager.go:98 msg=&amp;#34;WARNING!!! entry_parser config is deprecated, please change to pipeline_stages&amp;#34;
Jul 08 15:48:57 ip-172-31-45-69.us-east-2.compute.internal promtail-linux-amd64[2732]: level=info ts=2020-07-08T15:48:57.559869071Z caller=server.go:179 http=[::]:3100 grpc=[::]:35127 msg=&amp;#34;server listening on addresses&amp;#34;
Jul 08 15:48:57 ip-172-31-45-69.us-east-2.compute.internal promtail-linux-amd64[2732]: level=info ts=2020-07-08T15:48:57.56029474Z caller=main.go:67 msg=&amp;#34;Starting Promtail&amp;#34; version=&amp;#34;(version=1.6.0, branch=HEAD, revision=12c7eab8)&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;You can now verify in Grafana that Loki has correctly received your instance logs by using the &lt;a href=&#34;../../../../query/&#34;&gt;LogQL&lt;/a&gt; query &lt;code&gt;{zone=&amp;quot;us-east-2&amp;quot;}&lt;/code&gt;.&lt;/p&gt;
&lt;figure
    class=&#34;figure-wrapper figure-wrapper__lightbox w-100p &#34;
    style=&#34;max-width: px;&#34;
    itemprop=&#34;associatedMedia&#34;
    itemscope=&#34;&#34;
    itemtype=&#34;http://schema.org/ImageObject&#34;
  &gt;&lt;a
        class=&#34;lightbox-link&#34;
        href=&#34;./promtail-ec2-logs.png&#34;
        itemprop=&#34;contentUrl&#34;
      &gt;&lt;div class=&#34;img-wrapper w-100p h-auto&#34;&gt;&lt;img
          class=&#34;lazyload &#34;
          data-src=&#34;./promtail-ec2-logs.png&#34;alt=&#34;Grafana Loki logs&#34;/&gt;
        &lt;noscript&gt;
          &lt;img
            src=&#34;./promtail-ec2-logs.png&#34;
            alt=&#34;Grafana Loki logs&#34;/&gt;
        &lt;/noscript&gt;&lt;/div&gt;&lt;/a&gt;&lt;/figure&gt;
&lt;h2 id=&#34;sending-systemd-logs&#34;&gt;Sending systemd logs&lt;/h2&gt;
&lt;p&gt;Just like we did with Promtail, you&amp;rsquo;ll most likely manage your applications with &lt;a href=&#34;https://www.freedesktop.org/software/systemd/man/systemd.service.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;systemd&lt;/a&gt; which usually store applications logs in &lt;a href=&#34;https://www.freedesktop.org/software/systemd/man/systemd-journald.service.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;journald&lt;/a&gt;. Promtail actually support scraping logs from &lt;a href=&#34;https://www.freedesktop.org/software/systemd/man/systemd-journald.service.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;journald&lt;/a&gt; so let&amp;rsquo;s configure it.&lt;/p&gt;
&lt;p&gt;We will edit our previous config (&lt;code&gt;vi ec2-promtail.yaml&lt;/code&gt;) and add the following block in the &lt;code&gt;scrape_configs&lt;/code&gt; section.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;YAML&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-yaml&#34;&gt;  - job_name: journal
    journal:
      json: false
      max_age: 12h
      path: /var/log/journal
      labels:
        job: systemd-journal
    relabel_configs:
      - source_labels: [&amp;#39;__journal__systemd_unit&amp;#39;]
        target_label: &amp;#39;unit&amp;#39;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Note that you can use &lt;a href=&#34;https://prometheus.io/docs/prometheus/latest/configuration/configuration/#relabel_config&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;relabeling&lt;/a&gt; to convert systemd labels to match what you want. Finally make sure that the path of journald logs is correct, it might be different on some systems.&lt;/p&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;You can download the final config example from our [GitHub repository][final config].&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;That&amp;rsquo;s it, save the config and you can &lt;code&gt;reboot&lt;/code&gt; the machine (or simply restart the service &lt;code&gt;systemctl restart promtail.service&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s head back to Grafana and verify that your Promtail logs are available in Grafana by using the &lt;a href=&#34;../../../../query/&#34;&gt;LogQL&lt;/a&gt; query &lt;code&gt;{unit=&amp;quot;promtail.service&amp;quot;}&lt;/code&gt; in Explore. Finally make sure to checkout &lt;a href=&#34;/docs/grafana/latest/features/datasources/loki/#live-tailing&#34;&gt;live tailing&lt;/a&gt; to see logs appearing as they are ingested in Loki.&lt;/p&gt;
&lt;h1 id=&#34;troubleshooting-promtail-on-aws-ec2&#34;&gt;Troubleshooting Promtail on AWS EC2&lt;/h1&gt;
&lt;p&gt;If you encounter the error &lt;code&gt;error=&amp;quot;filetarget.fsnotify.NewWatcher: too many open files&amp;quot;&lt;/code&gt; in standalone EC2, you can resolve it by adding the &lt;code&gt;LimitNOFILE&lt;/code&gt; setting to your &lt;code&gt;promtail.service&lt;/code&gt; file as follows:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;YAML&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-yaml&#34;&gt;# /etc/systemd/system/promtail.service
[Service]
...
LimitNOFILE=500000&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The complete &lt;code&gt;promtail.service&lt;/code&gt; file should look like this:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;YAML&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-yaml&#34;&gt;# /etc/systemd/system/promtail.service
[Unit]
Description=Promtail

[Service]
User=root
WorkingDirectory=/opt/promtail/
ExecStartPre=/bin/sleep 30
ExecStart=/opt/promtail/promtail-linux-amd64 --config.file=./ec2-promtail.yaml
SuccessExitStatus=143
TimeoutStopSec=10
Restart=on-failure
RestartSec=5
LimitNOFILE=500000

[Install]
WantedBy=multi-user.target&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Reload and restart the promtail daemon to apply the changed systemd settings.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;systemctl daemon-reload
systemctl restart promtail.service&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Continue to monitor whether the too many open files error occurs again.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;watch -d -n2 &amp;#34;systemctl status promtail -l&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="run-the-promtail-client-on-aws-ec2">Run the Promtail client on AWS EC2&lt;/h1>
&lt;p>In this tutorial we&amp;rsquo;re going to setup &lt;a href="../../">Promtail&lt;/a> on an AWS EC2 instance and configure it to sends all its logs to a Grafana Loki instance.&lt;/p></description></item><item><title>Run the Promtail client on AWS ECS</title><link>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/cloud/ecs/</link><pubDate>Sat, 11 Apr 2026 00:53:11 +0000</pubDate><guid>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/cloud/ecs/</guid><content><![CDATA[&lt;h1 id=&#34;run-the-promtail-client-on-aws-ecs&#34;&gt;Run the Promtail client on AWS ECS&lt;/h1&gt;
&lt;p&gt;&lt;a href=&#34;https://aws.amazon.com/ecs/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;ECS&lt;/a&gt; is the fully managed container orchestration service by Amazon. Combined with &lt;a href=&#34;https://aws.amazon.com/fargate/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Fargate&lt;/a&gt; you can run your container workload without the need to provision your own compute resources. In this tutorial we will see how you can leverage &lt;a href=&#34;https://docs.aws.amazon.com/AmazonECS/latest/developerguide/using_firelens.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Firelens&lt;/a&gt; an AWS log router to forward all your logs and your workload metadata to a Grafana Loki instance.&lt;/p&gt;


&lt;div data-shared=&#34;promtail-deprecation.md&#34;&gt;
            

&lt;div class=&#34;admonition admonition-caution&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Caution&lt;/p&gt;&lt;p&gt;Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href=&#34;/docs/alloy/latest/set-up/migrate/from-promtail/&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;/div&gt;

        
&lt;p&gt;After this tutorial you will able to query all your logs in one place using Grafana.&lt;/p&gt;
&lt;h2 id=&#34;requirements&#34;&gt;Requirements&lt;/h2&gt;
&lt;p&gt;Before we start you&amp;rsquo;ll need:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;a href=&#34;https://aws.amazon.com/cli/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;AWS CLI&lt;/a&gt; configured (run &lt;code&gt;aws configure&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;A Grafana instance with a Loki data source already configured, you can use &lt;a href=&#34;/auth/sign-up/create-user&#34;&gt;GrafanaCloud&lt;/a&gt; free trial.&lt;/li&gt;
&lt;li&gt;A Subnet in VPC that is routable from the internet. (Follow those &lt;a href=&#34;https://docs.aws.amazon.com/vpc/latest/userguide/vpc-subnets-commands-example.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;instructions&lt;/a&gt; if you need to create one).&lt;/li&gt;
&lt;li&gt;A &lt;a href=&#34;https://docs.aws.amazon.com/vpc/latest/userguide/VPC_SecurityGroups.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Security group&lt;/a&gt; of your choice for your containers. (Follow those &lt;a href=&#34;https://docs.aws.amazon.com/cli/latest/userguide/cli-services-ec2-sg.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;instructions&lt;/a&gt; if you need to create one).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For the sake of simplicity we&amp;rsquo;ll use a GrafanaCloud Loki and Grafana instances, you can get an free account for this tutorial on our &lt;a href=&#34;/auth/sign-up/create-user&#34;&gt;website&lt;/a&gt;, but all the steps are the same if you&amp;rsquo;re running your own Open Source version of Loki and Grafana instances.&lt;/p&gt;
&lt;h2 id=&#34;setting-up-the-ecs-cluster&#34;&gt;Setting up the ECS cluster&lt;/h2&gt;
&lt;p&gt;To run containers with ECS you need an &lt;a href=&#34;https://docs.aws.amazon.com/AmazonECS/latest/developerguide/clusters.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;ECS cluster&lt;/a&gt;, we&amp;rsquo;ll use a &lt;a href=&#34;https://aws.amazon.com/fargate/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Fargate&lt;/a&gt; cluster, but if you prefer to use an EC2 cluster all the given steps are still applicable.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s create the cluster with awscli:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;aws ecs create-cluster --cluster-name ecs-firelens-cluster&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;We will also need an &lt;a href=&#34;https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_execution_IAM_role.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;IAM Role to run containers&lt;/a&gt; with, let&amp;rsquo;s create a new one and authorize &lt;a href=&#34;https://aws.amazon.com/ecs/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;ECS&lt;/a&gt; to endorse this role.&lt;/p&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;You might already have this &lt;code&gt;ecsTaskExecutionRole&lt;/code&gt; role in your AWS account if that&amp;rsquo;s the case you can skip this step.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;


&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;curl https://raw.githubusercontent.com/grafana/loki/main/docs/sources/send-data/promtail/cloud/ecs/ecs-role.json &amp;gt; ecs-role.json
aws iam create-role --role-name ecsTaskExecutionRole  --assume-role-policy-document file://ecs-role.json

{
    &amp;#34;Role&amp;#34;: {
        &amp;#34;Path&amp;#34;: &amp;#34;/&amp;#34;,
        &amp;#34;RoleName&amp;#34;: &amp;#34;ecsTaskExecutionRole&amp;#34;,
        &amp;#34;RoleId&amp;#34;: &amp;#34;AROA5FW5RZWLXFPU656SQ&amp;#34;,
        &amp;#34;Arn&amp;#34;: &amp;#34;arn:aws:iam::0000000000:role/ecsTaskExecutionRole&amp;#34;,
        &amp;#34;CreateDate&amp;#34;: &amp;#34;2020-07-09T14:51:49&amp;#43;00:00&amp;#34;,
        &amp;#34;AssumeRolePolicyDocument&amp;#34;: {
            &amp;#34;Version&amp;#34;: &amp;#34;2012-10-17&amp;#34;,
            &amp;#34;Statement&amp;#34;: [
                {
                    &amp;#34;Effect&amp;#34;: &amp;#34;Allow&amp;#34;,
                    &amp;#34;Principal&amp;#34;: {
                        &amp;#34;Service&amp;#34;: [
                            &amp;#34;ecs-tasks.amazonaws.com&amp;#34;
                        ]
                    },
                    &amp;#34;Action&amp;#34;: &amp;#34;sts:AssumeRole&amp;#34;
                }
            ]
        }
    }
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Note down the &lt;a href=&#34;https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;ARN&lt;/a&gt; of this new role, we&amp;rsquo;ll use it later to create an ECS task.&lt;/p&gt;
&lt;p&gt;Finally we&amp;rsquo;ll give the &lt;a href=&#34;https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_execution_IAM_role.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;ECS task execution policy&lt;/a&gt; &lt;code&gt;AmazonECSTaskExecutionRolePolicy&lt;/code&gt; to the created role, this will allows us to manage logs with &lt;a href=&#34;https://docs.aws.amazon.com/AmazonECS/latest/developerguide/using_firelens.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Firelens&lt;/a&gt;:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;aws iam attach-role-policy --role-name ecsTaskExecutionRole --policy-arn &amp;#34;arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;creating-your-task-definition&#34;&gt;Creating your task definition&lt;/h2&gt;
&lt;p&gt;Amazon &lt;a href=&#34;https://docs.aws.amazon.com/AmazonECS/latest/developerguide/using_firelens.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Firelens&lt;/a&gt; is a log router (usually &lt;code&gt;fluentd&lt;/code&gt; or &lt;code&gt;fluentbit&lt;/code&gt;) you run along the same task definition next to your application containers to route their logs to Loki.&lt;/p&gt;
&lt;p&gt;In this example we will use &lt;a href=&#34;https://fluentbit.io/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;fluentbit&lt;/a&gt; with the 
    &lt;a href=&#34;/docs/loki/v3.6.x/send-data/fluentbit/&#34;&gt;fluentbit output plugin&lt;/a&gt; installed but if you prefer &lt;a href=&#34;https://www.fluentd.org/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;fluentd&lt;/a&gt; make sure to check the 
    &lt;a href=&#34;/docs/loki/v3.6.x/send-data/fluentd/&#34;&gt;fluentd output plugin&lt;/a&gt; documentation.&lt;/p&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;We recommend you to use [fluentbit][fluentbit] as it&amp;rsquo;s less resources consuming than [fluentd][fluentd].&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;Our &lt;a href=&#34;https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definitions.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;task definition&lt;/a&gt; will be made of two containers, the &lt;a href=&#34;https://docs.aws.amazon.com/AmazonECS/latest/developerguide/using_firelens.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Firelens&lt;/a&gt; log router to send logs to Loki (&lt;code&gt;log_router&lt;/code&gt;) and a sample application to generate log with (&lt;code&gt;sample-app&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s download the task definition, we&amp;rsquo;ll go through the most important parts.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;curl https://raw.githubusercontent.com/grafana/loki/main/docs/sources/send-data/promtail/cloud/ecs/ecs-task.json &amp;gt; ecs-task.json&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JSON&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-json&#34;&gt; {
    &amp;#34;essential&amp;#34;: true,
    &amp;#34;image&amp;#34;: &amp;#34;grafana/fluent-bit-plugin-loki:2.9.3-amd64&amp;#34;,
    &amp;#34;name&amp;#34;: &amp;#34;log_router&amp;#34;,
    &amp;#34;firelensConfiguration&amp;#34;: {
        &amp;#34;type&amp;#34;: &amp;#34;fluentbit&amp;#34;,
        &amp;#34;options&amp;#34;: {
            &amp;#34;enable-ecs-log-metadata&amp;#34;: &amp;#34;true&amp;#34;
        }
    },
    &amp;#34;logConfiguration&amp;#34;: {
        &amp;#34;logDriver&amp;#34;: &amp;#34;awslogs&amp;#34;,
        &amp;#34;options&amp;#34;: {
            &amp;#34;awslogs-group&amp;#34;: &amp;#34;firelens-container&amp;#34;,
            &amp;#34;awslogs-region&amp;#34;: &amp;#34;us-east-2&amp;#34;,
            &amp;#34;awslogs-create-group&amp;#34;: &amp;#34;true&amp;#34;,
            &amp;#34;awslogs-stream-prefix&amp;#34;: &amp;#34;firelens&amp;#34;
        }
    },
    &amp;#34;memoryReservation&amp;#34;: 50
},&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The &lt;code&gt;log_router&lt;/code&gt; container image is the &lt;a href=&#34;https://hub.docker.com/r/grafana/fluent-bit-plugin-loki&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Fluent bit Loki docker image&lt;/a&gt; which contains the Loki plugin pre-installed. As you can see the &lt;code&gt;firelensConfiguration&lt;/code&gt; type is set to &lt;code&gt;fluentbit&lt;/code&gt; and we&amp;rsquo;ve also added &lt;code&gt;options&lt;/code&gt; to enable ECS log metadata. This will be useful when querying your logs with Loki LogQL label matchers.&lt;/p&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;The &lt;code&gt;logConfiguration&lt;/code&gt; is mostly there for debugging the fluent-bit container, but feel free to remove that part when you&amp;rsquo;re done testing and configuring.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;


&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JSON&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-json&#34;&gt; {
    &amp;#34;command&amp;#34;: [
        &amp;#34;/bin/sh -c \&amp;#34;while true; do sleep 15 ;echo hello_world; done\&amp;#34;&amp;#34;
    ],
    &amp;#34;entryPoint&amp;#34;: [&amp;#34;sh&amp;#34;,&amp;#34;-c&amp;#34;],
    &amp;#34;essential&amp;#34;: true,
    &amp;#34;image&amp;#34;: &amp;#34;alpine:3.13&amp;#34;,
    &amp;#34;logConfiguration&amp;#34;: {
        &amp;#34;logDriver&amp;#34;: &amp;#34;awsfirelens&amp;#34;,
        &amp;#34;options&amp;#34;: {
            &amp;#34;Name&amp;#34;: &amp;#34;loki&amp;#34;,
            &amp;#34;Host&amp;#34;: &amp;#34;&amp;lt;grafanacloud host&amp;gt;&amp;#34;,
            &amp;#34;Http_User&amp;#34;: &amp;#34;&amp;lt;userid&amp;gt;&amp;#34;, 
            &amp;#34;Labels&amp;#34;: &amp;#34;{job=\&amp;#34;firelens\&amp;#34;}&amp;#34;,
            &amp;#34;RemoveKeys&amp;#34;: &amp;#34;container_id,ecs_task_arn&amp;#34;,
            &amp;#34;LabelKeys&amp;#34;: &amp;#34;container_name,ecs_task_definition,source,ecs_cluster&amp;#34;,
            &amp;#34;LineFormat&amp;#34;: &amp;#34;key_value&amp;#34;
        },
        &amp;#34;secretOptions&amp;#34;: [{
            &amp;#34;name&amp;#34;: &amp;#34;Http_Passwd&amp;#34;,
            &amp;#34;valueFrom&amp;#34;: &amp;#34;data.aws_secretsmanager_secret.grafana_cloud_loki_http_password.id&amp;#34;
        }]
    },
    &amp;#34;name&amp;#34;: &amp;#34;sample-app&amp;#34;
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The second container is our &lt;code&gt;sample-app&lt;/code&gt;, a simple &lt;a href=&#34;https://hub.docker.com/_/alpine&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;alpine&lt;/a&gt; container that prints to stdout welcoming messages. To send those logs to Loki, we will configure this container to use the log driver &lt;code&gt;awsfirelens&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Go ahead and replace the &lt;code&gt;Host&lt;/code&gt; and &lt;code&gt;HTTP_User&lt;/code&gt; property with your &lt;a href=&#34;/auth/sign-up/create-user&#34;&gt;GrafanaCloud&lt;/a&gt; credentials, you can find them in your &lt;a href=&#34;/login&#34;&gt;account&lt;/a&gt; in the Loki instance page. If you&amp;rsquo;re running your own Loki instance replace completely the URL (for example, &lt;code&gt;http://my-loki.com:3100/loki/api/v1/push&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;We include plain text credentials in &lt;code&gt;options&lt;/code&gt; for simplicity. However, this exposes credentials in your ECS task definition and in any version-controlled configuration. Mitigate this issue by using a secret store such as &lt;a href=&#34;https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;AWS Secrets Manager&lt;/a&gt;, combined with the &lt;code&gt;secretOptions&lt;/code&gt; configuration option for &lt;a href=&#34;https://docs.aws.amazon.com/AmazonECS/latest/developerguide/specifying-sensitive-data-secrets.html#secrets-logconfig&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;injecting sensitive data in a log configuration&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;All &lt;code&gt;options&lt;/code&gt; of the &lt;code&gt;logConfiguration&lt;/code&gt; will be automatically translated into &lt;a href=&#34;https://fluentbit.io/documentation/0.14/output/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;fluentbit output&lt;/a&gt;. For example, the above options will produce this fluent bit &lt;code&gt;OUTPUT&lt;/code&gt; config section:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;conf&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-conf&#34;&gt;[OUTPUT]
    Name grafana-loki
    Match awsfirelens*
    Url https://&amp;lt;userid&amp;gt;:&amp;lt;grafancloud apikey&amp;gt;@logs-prod-us-central1.grafana.net/loki/api/v1/push
    Labels {job=&amp;#34;firelens&amp;#34;}
    RemoveKeys container_id,ecs_task_arn
    LabelKeys container_name,ecs_task_definition,source,ecs_cluster
    LineFormat key_value&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This &lt;code&gt;OUTPUT&lt;/code&gt; config will forward logs to &lt;a href=&#34;/auth/sign-up/create-user&#34;&gt;GrafanaCloud&lt;/a&gt; Loki, to learn more about those options make sure to read the 
    &lt;a href=&#34;/docs/loki/v3.6.x/send-data/fluentbit/&#34;&gt;fluentbit output plugin&lt;/a&gt; documentation.
We&amp;rsquo;ve kept some interesting and useful labels such as &lt;code&gt;container_name&lt;/code&gt;, &lt;code&gt;ecs_task_definition&lt;/code&gt; , &lt;code&gt;source&lt;/code&gt; and &lt;code&gt;ecs_cluster&lt;/code&gt; but you can statically add more via the &lt;code&gt;Labels&lt;/code&gt; option.&lt;/p&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;If you want run multiple containers in your task, all of them needs a &lt;code&gt;logConfiguration&lt;/code&gt; section, this give you the opportunity to add different labels depending on the container.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;


&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JSON&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-json&#34;&gt;{
    &amp;#34;containerDefinitions&amp;#34;: [
     ...
    ],
    &amp;#34;cpu&amp;#34;: &amp;#34;256&amp;#34;,
    &amp;#34;executionRoleArn&amp;#34;: &amp;#34;arn:aws:iam::00000000:role/ecsTaskExecutionRole&amp;#34;,
    &amp;#34;family&amp;#34;: &amp;#34;loki-fargate-task-definition&amp;#34;,
    &amp;#34;memory&amp;#34;: &amp;#34;512&amp;#34;,
    &amp;#34;networkMode&amp;#34;: &amp;#34;awsvpc&amp;#34;,
    &amp;#34;requiresCompatibilities&amp;#34;: [
        &amp;#34;FARGATE&amp;#34;
    ]
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Finally, you need to replace the &lt;code&gt;executionRoleArn&lt;/code&gt; with the &lt;a href=&#34;https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;ARN&lt;/a&gt; of the role we created in the &lt;a href=&#34;#setting-up-the-ecs-cluster&#34;&gt;first section&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Once you&amp;rsquo;ve finished editing the task definition we can then run the command below to create the task:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;aws ecs register-task-definition --region us-east-2 --cli-input-json  file://ecs-task.json&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Now let&amp;rsquo;s create and start a service.&lt;/p&gt;
&lt;h2 id=&#34;running-your-service&#34;&gt;Running your service&lt;/h2&gt;
&lt;p&gt;To run the service you need to provide the task definition name &lt;code&gt;loki-fargate-task-definition:1&lt;/code&gt; which is the combination of task family plus the task revision &lt;code&gt;:1&lt;/code&gt;. You also need your own subnet and security group, you can replace respectively &lt;code&gt;subnet-306ca97d&lt;/code&gt; and &lt;code&gt;sg-02c489bbdeffdca1d&lt;/code&gt; in the command below and start the your service:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;aws ecs create-service --cluster ecs-firelens-cluster \
--service-name firelens-loki-fargate \
--task-definition loki-fargate-task-definition:1 \
--desired-count 1 --region us-east-2 --launch-type &amp;#34;FARGATE&amp;#34; \
--network-configuration &amp;#34;awsvpcConfiguration={subnets=[subnet-306ca97d],securityGroups=[sg-02c489bbdeffdca1d],assignPublicIp=ENABLED}&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;Make sure public (&lt;code&gt;assignPublicIp&lt;/code&gt;) is enabled otherwise ECS won&amp;rsquo;t connect to the internet and you won&amp;rsquo;t be able to pull external docker images.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;You can now access the ECS console and you should see your task running. Now let&amp;rsquo;s open Grafana and use explore with the Loki data source to explore our task logs. Enter the query &lt;code&gt;{job=&amp;quot;firelens&amp;quot;}&lt;/code&gt; and you should see our &lt;code&gt;sample-app&lt;/code&gt; logs showing up as shown below:&lt;/p&gt;
&lt;figure
    class=&#34;figure-wrapper figure-wrapper__lightbox w-100p &#34;
    style=&#34;max-width: px;&#34;
    itemprop=&#34;associatedMedia&#34;
    itemscope=&#34;&#34;
    itemtype=&#34;http://schema.org/ImageObject&#34;
  &gt;&lt;a
        class=&#34;lightbox-link&#34;
        href=&#34;./ecs-grafana.png&#34;
        itemprop=&#34;contentUrl&#34;
      &gt;&lt;div class=&#34;img-wrapper w-100p h-auto&#34;&gt;&lt;img
          class=&#34;lazyload &#34;
          data-src=&#34;./ecs-grafana.png&#34;alt=&#34;grafana logs firelens&#34;/&gt;
        &lt;noscript&gt;
          &lt;img
            src=&#34;./ecs-grafana.png&#34;
            alt=&#34;grafana logs firelens&#34;/&gt;
        &lt;/noscript&gt;&lt;/div&gt;&lt;/a&gt;&lt;/figure&gt;
&lt;p&gt;Using the &lt;code&gt;Log Labels&lt;/code&gt; dropdown you should be able to discover your workload via the ECS metadata, which is also visible if you expand a log line.&lt;/p&gt;
&lt;p&gt;That&amp;rsquo;s it. Make sure to checkout 
    &lt;a href=&#34;/docs/loki/v3.6.x/logql/&#34;&gt;LogQL&lt;/a&gt; to learn more about Loki powerful query language.&lt;/p&gt;
]]></content><description>&lt;h1 id="run-the-promtail-client-on-aws-ecs">Run the Promtail client on AWS ECS&lt;/h1>
&lt;p>&lt;a href="https://aws.amazon.com/ecs/" target="_blank" rel="noopener noreferrer">ECS&lt;/a> is the fully managed container orchestration service by Amazon. Combined with &lt;a href="https://aws.amazon.com/fargate/" target="_blank" rel="noopener noreferrer">Fargate&lt;/a> you can run your container workload without the need to provision your own compute resources. In this tutorial we will see how you can leverage &lt;a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/using_firelens.html" target="_blank" rel="noopener noreferrer">Firelens&lt;/a> an AWS log router to forward all your logs and your workload metadata to a Grafana Loki instance.&lt;/p></description></item><item><title>Run the Promtail client on AWS EKS</title><link>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/cloud/eks/</link><pubDate>Sat, 11 Apr 2026 00:53:11 +0000</pubDate><guid>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/cloud/eks/</guid><content><![CDATA[&lt;h1 id=&#34;run-the-promtail-client-on-aws-eks&#34;&gt;Run the Promtail client on AWS EKS&lt;/h1&gt;
&lt;p&gt;In this tutorial we&amp;rsquo;ll see how to set up Promtail on &lt;a href=&#34;https://aws.amazon.com/eks/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;EKS&lt;/a&gt;. Amazon Elastic Kubernetes Service (Amazon &lt;a href=&#34;https://aws.amazon.com/eks/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;EKS&lt;/a&gt;) is a fully managed Kubernetes service, using Promtail we&amp;rsquo;ll get full visibility into our cluster logs. We&amp;rsquo;ll start by forwarding pods logs then nodes services and finally Kubernetes events.&lt;/p&gt;


&lt;div data-shared=&#34;promtail-deprecation.md&#34;&gt;
            

&lt;div class=&#34;admonition admonition-caution&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Caution&lt;/p&gt;&lt;p&gt;Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href=&#34;/docs/alloy/latest/set-up/migrate/from-promtail/&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;/div&gt;

        
&lt;p&gt;After this tutorial you will able to query all your logs in one place using Grafana.&lt;/p&gt;
&lt;h2 id=&#34;requirements&#34;&gt;Requirements&lt;/h2&gt;
&lt;p&gt;Before we start you&amp;rsquo;ll need:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;a href=&#34;https://aws.amazon.com/cli/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;AWS CLI&lt;/a&gt; configured (run &lt;code&gt;aws configure&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://kubernetes.io/docs/tasks/tools/install-kubectl/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;kubectl&lt;/a&gt; and &lt;a href=&#34;https://docs.aws.amazon.com/eks/latest/userguide/getting-started-eksctl.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;eksctl&lt;/a&gt; installed.&lt;/li&gt;
&lt;li&gt;A Grafana instance with a Grafana Loki data source already configured, you can use &lt;a href=&#34;/signup/&#34;&gt;GrafanaCloud&lt;/a&gt; free trial.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For the sake of simplicity we&amp;rsquo;ll use a &lt;a href=&#34;/signup/&#34;&gt;GrafanaCloud&lt;/a&gt; Loki and Grafana instances, you can get an free account for this tutorial on our &lt;a href=&#34;/signup/&#34;&gt;website&lt;/a&gt;, but all the steps are the same if you&amp;rsquo;re running your own Open Source version of Loki and Grafana instances.&lt;/p&gt;
&lt;h2 id=&#34;setting-up-the-cluster&#34;&gt;Setting up the cluster&lt;/h2&gt;
&lt;p&gt;In this tutorial we&amp;rsquo;ll use &lt;a href=&#34;https://docs.aws.amazon.com/eks/latest/userguide/getting-started-eksctl.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;eksctl&lt;/a&gt;, a simple command line utility for creating and managing Kubernetes clusters on Amazon EKS. AWS requires creating many resources such as IAM roles, security groups and networks, by using &lt;code&gt;eksctl&lt;/code&gt; all of this is simplified.&lt;/p&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;We&amp;rsquo;re not going to use a Fargate cluster. Do note that if you want to use Fargate daemonset are not allowed, the only way to ship logs with EKS Fargate is to run a fluentd or fluentbit or Promtail as a sidecar and tee your logs into a file. For more information on how to do so, you can read this [blog post][blog ship log with fargate].&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;


&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;eksctl create cluster --name loki-promtail --managed&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This usually takes about 15 minutes. When this is finished you should have &lt;code&gt;kubectl context&lt;/code&gt; configured to communicate with your newly created cluster. To verify, run the following command:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;kubectl version&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;You should see output similar to the following:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;Client Version: version.Info{Major:&amp;#34;1&amp;#34;, Minor:&amp;#34;18&amp;#34;, GitVersion:&amp;#34;v1.18.5&amp;#34;, GitCommit:&amp;#34;e6503f8d8f769ace2f338794c914a96fc335df0f&amp;#34;, GitTreeState:&amp;#34;clean&amp;#34;, BuildDate:&amp;#34;2020-07-04T15:01:15Z&amp;#34;, GoVersion:&amp;#34;go1.14.4&amp;#34;, Compiler:&amp;#34;gc&amp;#34;, Platform:&amp;#34;darwin/amd64&amp;#34;}
Server Version: version.Info{Major:&amp;#34;1&amp;#34;, Minor:&amp;#34;16&amp;#43;&amp;#34;, GitVersion:&amp;#34;v1.16.8-eks-fd1ea7&amp;#34;, GitCommit:&amp;#34;fd1ea7c64d0e3ccbf04b124431c659f65330562a&amp;#34;, GitTreeState:&amp;#34;clean&amp;#34;, BuildDate:&amp;#34;2020-05-28T19:06:00Z&amp;#34;, GoVersion:&amp;#34;go1.13.8&amp;#34;, Compiler:&amp;#34;gc&amp;#34;, Platform:&amp;#34;linux/amd64&amp;#34;}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;adding-promtail-daemonset&#34;&gt;Adding Promtail DaemonSet&lt;/h2&gt;
&lt;p&gt;To ship all your pods logs we&amp;rsquo;re going to set up &lt;a href=&#34;../../&#34;&gt;Promtail&lt;/a&gt; as a DaemonSet in our cluster. This means it will run on each nodes of the cluster, we will then configure it to find the logs of your containers on the host.&lt;/p&gt;
&lt;p&gt;What&amp;rsquo;s nice about Promtail is that it uses the same &lt;a href=&#34;https://prometheus.io/docs/prometheus/latest/configuration/configuration/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;service discovery as Prometheus&lt;/a&gt;, you should make sure the &lt;code&gt;scrape_configs&lt;/code&gt; of Promtail matches the Prometheus one. Not only this is simpler to configure, but this also means Metrics and Logs will have the same metadata (labels) attached by the Prometheus service discovery. When querying Grafana you will be able to correlate metrics and logs very quickly, you can read more about this on our &lt;a href=&#34;/blog/2020/03/31/how-to-successfully-correlate-metrics-logs-and-traces-in-grafana/&#34;&gt;blogpost&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s add the Loki repository and list all available charts. To add the repo, run the following command:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;helm repo add grafana https://grafana.github.io/helm-charts
helm upgrade -i promtail grafana/promtail&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;You should see the following message.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;&amp;#34;loki&amp;#34; has been added to your repositories&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;To list the available charts, run the following command:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;helm search repo&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;You should see output similar to the following:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;NAME                   CHART VERSION   APP VERSION     DESCRIPTION
loki/fluent-bit 0.3.0           v1.6.0          Uses fluent-bit Loki go plugin for gathering lo...
loki/loki       0.31.0          v1.6.0          Loki: like Prometheus, but for logs.
loki/loki-stack 0.40.0          v1.6.0          Loki: like Prometheus, but for logs.
loki/promtail   0.24.0          v1.6.0          Responsible for gathering logs and sending them...&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;If you want to install Loki, Grafana, Prometheus and Promtail all together you can use the &lt;code&gt;loki-stack&lt;/code&gt; chart, for now we&amp;rsquo;ll focus on Promtail. Let&amp;rsquo;s create a new helm value file, we&amp;rsquo;ll fetch the &lt;a href=&#34;https://github.com/grafana/helm-charts/blob/main/charts/promtail/values.yaml&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;default&lt;/a&gt; one and work from there:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;curl https://raw.githubusercontent.com/grafana/helm-charts/main/charts/promtail/values.yaml &amp;gt; values.yaml&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;First we&amp;rsquo;re going to tell Promtail to send logs to our Loki instance, the example below shows how to send logs to &lt;a href=&#34;/signup/&#34;&gt;GrafanaCloud&lt;/a&gt;, replace your credentials. The default value will send to your own Loki and Grafana instance if you&amp;rsquo;re using the &lt;code&gt;loki-chart&lt;/code&gt; repository.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;YAML&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-yaml&#34;&gt;loki:
  serviceName: &amp;#34;logs-prod-us-central1.grafana.net&amp;#34;
  servicePort: 443
  serviceScheme: https
  user: &amp;lt;userid&amp;gt;
  password: &amp;lt;grafancloud apikey&amp;gt;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Once you&amp;rsquo;re ready let&amp;rsquo;s create a new namespace monitoring and add Promtail to it.  To create the namespace, run the following command:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;kubectl create namespace monitoring&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;You should see the following message.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;namespace/monitoring created&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;To add Promtail, run the following command:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;helm install promtail --namespace monitoring loki/promtail -f values.yaml&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;You should see output similar to the following:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;NAME: promtail
LAST DEPLOYED: Fri Jul 10 14:41:37 2020
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
Verify the application is working by running these commands:
  kubectl --namespace default port-forward daemonset/promtail 3101
  curl http://127.0.0.1:3101/metrics&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Verify that Promtail pods are running. You should see only two since we&amp;rsquo;re running a two nodes cluster.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;kubectl get -n monitoring pods&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;You should see output similar to the following:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;NAME             READY   STATUS    RESTARTS   AGE
promtail-87t62   1/1     Running   0          35s
promtail-8c2r4   1/1     Running   0          35s&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;You can reach your Grafana instance and start exploring your logs. For example if you want to see all logs in the &lt;code&gt;monitoring&lt;/code&gt; namespace use &lt;code&gt;{namespace=&amp;quot;monitoring&amp;quot;}&lt;/code&gt;, you can also expand a single log line to discover all labels available from the Kubernetes service discovery.&lt;/p&gt;
&lt;p&gt;&lt;img
  class=&#34;lazyload d-inline-block&#34;
  data-src=&#34;namespace-grafana.png&#34;
  alt=&#34;grafana logs namespace&#34;/&gt;&lt;/p&gt;
&lt;h2 id=&#34;fetching-kubelet-logs-with-systemd&#34;&gt;Fetching kubelet logs with systemd&lt;/h2&gt;
&lt;p&gt;So far we&amp;rsquo;re scrapings logs from containers, but if you want to get more visibility you could also scrape systemd logs from each of your machine. This means you can also get access to &lt;code&gt;kubelet&lt;/code&gt; logs.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s edit our values file again and &lt;code&gt;extraScrapeConfigs&lt;/code&gt; to add the systemd job:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;YAML&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-yaml&#34;&gt;extraScrapeConfigs:
  - job_name: journal
    journal:
      path: /var/log/journal
      max_age: 12h
      labels:
        job: systemd-journal
    relabel_configs:
      - source_labels: [&amp;#39;__journal__systemd_unit&amp;#39;]
        target_label: &amp;#39;unit&amp;#39;
      - source_labels: [&amp;#39;__journal__hostname&amp;#39;]
        target_label: &amp;#39;hostname&amp;#39;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;blockquote&gt;
&lt;p&gt;Feel free to change the &lt;a href=&#34;https://prometheus.io/docs/prometheus/latest/configuration/configuration/#relabel_config&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;relabel_configs&lt;/a&gt; to match what you would use in your own environnement.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Now we need to add a volume for accessing systemd logs:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;YAML&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-yaml&#34;&gt;extraVolumes:
  - name: journal
    hostPath:
      path: /var/log/journal&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;And add a new volume mount in Promtail:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;YAML&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-yaml&#34;&gt;extraVolumeMounts:
  - name: journal
    mountPath: /var/log/journal
    readOnly: true&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Now that we&amp;rsquo;re ready we can update the Promtail deployment:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;helm upgrade  promtail loki/promtail -n monitoring -f values.yaml&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Let go back to Grafana and type in the query below to fetch all logs related to Volume from Kubelet:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;{unit=&amp;#34;kubelet.service&amp;#34;} |= &amp;#34;Volume&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Filter expressions are powerful in LogQL they help you scan through your logs, in this case it will filter out all your &lt;a href=&#34;https://kubernetes.io/docs/reference/command-line-tools-reference/kubelet/#:~:text=The%20kubelet%20works%20in%20terms,PodSpecs%20are%20running%20and%20healthy.&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;kubelet&lt;/a&gt; logs not having the &lt;code&gt;Volume&lt;/code&gt; word in it.&lt;/p&gt;
&lt;p&gt;The workflow is simple, you always select a set of labels matchers first, this way you reduce the data you&amp;rsquo;re planing to scan.(such as an application, a namespace or even a cluster).
Then you can apply a set of filters to find the logs you want.&lt;/p&gt;
&lt;p&gt;Promtail also supports syslog.&lt;/p&gt;
&lt;h2 id=&#34;adding-kubernetes-events&#34;&gt;Adding Kubernetes events&lt;/h2&gt;
&lt;p&gt;Kubernetes Events (&lt;code&gt;kubectl get events -n monitoring&lt;/code&gt;)  are a great way to debug and troubleshoot your kubernetes cluster. Events contains information such as Node reboot, OOMKiller and Pod failures.&lt;/p&gt;
&lt;p&gt;We&amp;rsquo;ll deploy a the &lt;code&gt;eventrouter&lt;/code&gt; application created by &lt;a href=&#34;https://github.com/heptiolabs/eventrouter&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Heptio&lt;/a&gt; which logs those events to &lt;code&gt;stdout&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;But first we need to configure Promtail, we want to parse the namespace to add it as a label from the content, this way we can quickly access events by namespace.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s update our &lt;code&gt;pipelineStages&lt;/code&gt; to parse logs from the &lt;code&gt;eventrouter&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;YAML&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-yaml&#34;&gt;pipelineStages:
- docker:
- match:
    selector: &amp;#39;{app=&amp;#34;eventrouter&amp;#34;}&amp;#39;
    stages:
    - json:
        expressions:
          namespace: event.metadata.namespace
    - labels:
        namespace: &amp;#34;&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;blockquote&gt;
&lt;p&gt;Pipeline stages are great ways to parse log content and create labels (which are &lt;a href=&#34;/blog/2020/04/21/how-labels-in-loki-can-make-log-queries-faster-and-easier/&#34;&gt;indexed&lt;/a&gt;), if you want to configure more of them, check out the 
    &lt;a href=&#34;/docs/loki/v3.6.x/send-data/promtail/pipelines/&#34;&gt;pipeline&lt;/a&gt; documentation.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Now update Promtail again:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;helm upgrade  promtail loki/promtail -n monitoring -f values.yaml&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;And deploy the &lt;code&gt;eventrouter&lt;/code&gt; using:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;kubectl create -f https://raw.githubusercontent.com/grafana/loki/main/docs/sources/send-data/promtail/cloud/eks/eventrouter.yaml&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;You should see output similar to the following:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;serviceaccount/eventrouter created
clusterrole.rbac.authorization.k8s.io/eventrouter created
clusterrolebinding.rbac.authorization.k8s.io/eventrouter created
configmap/eventrouter-cm created
deployment.apps/eventrouter created&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Let&amp;rsquo;s go in Grafana &lt;a href=&#34;/docs/grafana/latest/features/explore/&#34;&gt;Explore&lt;/a&gt; and query events for our new &lt;code&gt;monitoring&lt;/code&gt; namespace using &lt;code&gt;{app=&amp;quot;eventrouter&amp;quot;,namespace=&amp;quot;monitoring&amp;quot;}&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;For more information about the &lt;code&gt;eventrouter&lt;/code&gt; make sure to read our &lt;a href=&#34;/blog/2019/08/21/how-grafana-labs-effectively-pairs-loki-and-kubernetes-events/&#34;&gt;blog post&lt;/a&gt; from Goutham.&lt;/p&gt;
&lt;h2 id=&#34;conclusion&#34;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;That&amp;rsquo;s it ! You can download the final and complete &lt;a href=&#34;values.yaml&#34;&gt;&lt;code&gt;values.yaml&lt;/code&gt;&lt;/a&gt; if you need.&lt;/p&gt;
&lt;p&gt;Your EKS cluster is now ready, all your current and future application logs will now be shipped to Loki with Promtail. You will also able to &lt;a href=&#34;/docs/grafana/latest/features/explore/&#34;&gt;explore&lt;/a&gt; &lt;a href=&#34;https://kubernetes.io/docs/reference/command-line-tools-reference/kubelet/#:~:text=The%20kubelet%20works%20in%20terms,PodSpecs%20are%20running%20and%20healthy.&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;kubelet&lt;/a&gt; and Kubernetes events. Since we&amp;rsquo;ve used a DaemonSet you&amp;rsquo;ll automatically grab all your node logs as you scale them.&lt;/p&gt;
&lt;p&gt;If you want to push this further you can check out &lt;a href=&#34;/blog/2019/12/09/how-to-do-automatic-annotations-with-grafana-and-loki/&#34;&gt;Joe&amp;rsquo;s blog post&lt;/a&gt; on how to automatically create Grafana dashboard annotations with Loki when you deploy new Kubernetes applications.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;If you need to delete the cluster simply run &lt;code&gt;eksctl delete  cluster --name loki-promtail&lt;/code&gt;&lt;/p&gt;&lt;/blockquote&gt;
]]></content><description>&lt;h1 id="run-the-promtail-client-on-aws-eks">Run the Promtail client on AWS EKS&lt;/h1>
&lt;p>In this tutorial we&amp;rsquo;ll see how to set up Promtail on &lt;a href="https://aws.amazon.com/eks/" target="_blank" rel="noopener noreferrer">EKS&lt;/a>. Amazon Elastic Kubernetes Service (Amazon &lt;a href="https://aws.amazon.com/eks/" target="_blank" rel="noopener noreferrer">EKS&lt;/a>) is a fully managed Kubernetes service, using Promtail we&amp;rsquo;ll get full visibility into our cluster logs. We&amp;rsquo;ll start by forwarding pods logs then nodes services and finally Kubernetes events.&lt;/p></description></item><item><title>Run the Promtail client on Google Cloud Platform</title><link>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/cloud/gcp/</link><pubDate>Sat, 11 Apr 2026 00:53:11 +0000</pubDate><guid>https://grafana.com/docs/enterprise-logs/v3.6.x/send-data/promtail/cloud/gcp/</guid><content><![CDATA[&lt;h1 id=&#34;run-the-promtail-client-on-google-cloud-platform&#34;&gt;Run the Promtail client on Google Cloud Platform&lt;/h1&gt;
&lt;p&gt;This document explains how one can setup Google Cloud Platform to forward its cloud resource logs from a particular GCP project into Google Pubsub topic so that is available for Promtail to consume.&lt;/p&gt;


&lt;div data-shared=&#34;promtail-deprecation.md&#34;&gt;
            

&lt;div class=&#34;admonition admonition-caution&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Caution&lt;/p&gt;&lt;p&gt;Promtail has been deprecated and is in Long-Term Support (LTS) through February 28, 2026. Promtail will reach an End-of-Life (EOL) on March 2, 2026. You can find migration resources &lt;a href=&#34;/docs/alloy/latest/set-up/migrate/from-promtail/&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;/div&gt;

        
&lt;p&gt;This document assumes, that reader have &lt;code&gt;gcloud&lt;/code&gt; installed and have the required permissions (as mentioned in &lt;a href=&#34;#roles-and-permission&#34;&gt;Roles and Permission&lt;/a&gt; section).&lt;/p&gt;
&lt;p&gt;There are two flavours of how to configure this:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Pull-based subscription: Promtail pulls log entries from a GCP PubSub topic&lt;/li&gt;
&lt;li&gt;Push-based subscription: GCP sends log entries to a web server that Promtail listens&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Overall, the setup between GCP, Promtail and Loki will look like the following:&lt;/p&gt;
&lt;img src=&#34;./gcp-logs-diagram.png&#34; width=&#34;1200px&#34;/&gt;
&lt;h2 id=&#34;roles-and-permission&#34;&gt;Roles and Permission&lt;/h2&gt;
&lt;p&gt;The user should have following roles to complete the setup.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&amp;ldquo;roles/pubsub.editor&amp;rdquo;&lt;/li&gt;
&lt;li&gt;&amp;ldquo;roles/logging.configWriter&amp;rdquo;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;setup-pubsub-topic&#34;&gt;Setup Pubsub Topic&lt;/h2&gt;
&lt;p&gt;Google Pubsub Topic will act as the queue to persist log messages which then can be read from Promtail.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;$ gcloud pubsub topics create $TOPIC_ID&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;For example:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;$ gcloud pubsub topics create cloud-logs&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;setup-log-router&#34;&gt;Setup Log Router&lt;/h2&gt;
&lt;p&gt;We create a log sink to forward cloud logs into pubsub topic that we just created.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;$ gcloud logging sinks create $SINK_NAME $SINK_LOCATION $OPTIONAL_FLAGS&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;For example:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;$ gcloud logging sinks create cloud-logs pubsub.googleapis.com/projects/my-project/topics/cloud-logs \
--log-filter=&amp;#39;resource.type=(&amp;#34;gcs_bucket&amp;#34;)&amp;#39; \
--description=&amp;#34;Cloud logs&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The above command also adds &lt;code&gt;log-filter&lt;/code&gt; option which represents what type of logs should get into the destination &lt;code&gt;pubsub&lt;/code&gt; topic.
For more information on adding &lt;code&gt;log-filter&lt;/code&gt; refer this &lt;a href=&#34;https://cloud.google.com/logging/docs/export/configure_export_v2#creating_sink&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;document&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;We cover more advanced &lt;code&gt;log-filter&lt;/code&gt; &lt;a href=&#34;#Advanced-Log-filter&#34;&gt;below&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;grant-log-sink-the-pubsub-publisher-role&#34;&gt;Grant log sink the pubsub publisher role&lt;/h2&gt;
&lt;p&gt;Find the writer identity service account of the log sink just created:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;gcloud logging sinks describe \
 --format=&amp;#39;value(writerIdentity)&amp;#39; $SINK_NAME&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;For example:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;gcloud logging sinks describe \
 --format=&amp;#39;value(writerIdentity)&amp;#39; cloud-logs&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Create an IAM policy binding to allow log sink to publish messages to the topic:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;gcloud pubsub topics add-iam-policy-binding $TOPIC_ID \
--member=$WRITER_IDENTITY --role=roles/pubsub.publisher&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;For example:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;gcloud pubsub topics add-iam-policy-binding cloud-logs \
--member=serviceAccount:pxxxxxxxxx-xxxxxx@gcp-sa-logging.iam.gserviceaccount.com --role=roles/pubsub.publisher&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;create-pubsub-subscription-for-grafana-loki&#34;&gt;Create Pubsub subscription for Grafana Loki&lt;/h2&gt;
&lt;h3 id=&#34;pull&#34;&gt;Pull&lt;/h3&gt;
&lt;p&gt;We create subscription for the pubsub topic we create above and Promtail uses this subscription to consume the log messages.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;$ gcloud pubsub subscriptions create cloud-logs --topic=$TOPIC_ID \
--ack-deadline=$ACK_DEADLINE \
--message-retention-duration=$RETENTION_DURATION \&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;e.g:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;$ gcloud pubsub subscriptions create cloud-logs --topic=projects/my-project/topics/cloud-logs \
--ack-deadline=10 \
--message-retention-duration=7d&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;For more fine grained options, refer to the &lt;code&gt;gcloud pubsub subscriptions --help&lt;/code&gt;&lt;/p&gt;
&lt;h3 id=&#34;push&#34;&gt;Push&lt;/h3&gt;
&lt;p&gt;Since GCP PubSub push subscriptions is a rather new service, In some cases, it is necessary to grant Google permission. First, check the date the GCP project was created on:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;&amp;gt; gcloud projects describe $GCP_PROJECT_ID

createTime: &amp;#39;some date&amp;#39;
...
projectId: $GCP_PROJECT_ID
projectNumber: &amp;#39;$GCP_PROJECT_NUMBER&amp;#39;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;If the &lt;code&gt;createTime&lt;/code&gt; is earlier than &lt;strong&gt;April 8, 2021&lt;/strong&gt;, skip the following step. Otherwise, you &lt;a href=&#34;https://cloud.google.com/pubsub/docs/push#configure_for_push_authentication&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;need to grant the&lt;/a&gt; the &lt;code&gt;iam.serviceAccountTokenCreator&lt;/code&gt; role to a Google-managed service account:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;PUBSUB_SERVICE_ACCOUNT=&amp;#34;service-${GCP_PROJECT_NUMBER}@gcp-sa-pubsub.iam.gserviceaccount.com&amp;#34;
gcloud projects add-iam-policy-binding ${GCP_PROJECT_ID} \
 --member=&amp;#34;serviceAccount:${PUBSUB_SERVICE_ACCOUNT}&amp;#34;\
 --role=&amp;#39;roles/iam.serviceAccountTokenCreator&amp;#39;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;have configured Promtail with the &lt;a href=&#34;#push&#34;&gt;GCP Logs Push target&lt;/a&gt;, hosted in an internet-facing and HTTPS enabled deployment, we can continue with creating
the push subscription.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;gcloud pubsub subscriptions create cloud-logs \
--topic=$TOPIC_ID \
--push-endpoint=$HTTPS_PUSH_ENDPOINT_URI&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;setup-using-terraform&#34;&gt;Setup using Terraform&lt;/h2&gt;
&lt;p&gt;You also have the option of creating the required resources for GCP Log collection with terraform. First, the following snippet will add the resources needed for both &lt;code&gt;pull&lt;/code&gt; and &lt;code&gt;push&lt;/code&gt; flavours.&lt;/p&gt;
&lt;p&gt;How to use Terraform is outside the scope of this guide. You can find &lt;a href=&#34;https://developer.hashicorp.com/terraform/tutorials/gcp-get-started/google-cloud-platform-build&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;this tutorial&lt;/a&gt; on how to work with Terraform and GCP useful.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;terraform&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-terraform&#34;&gt;// Provider module
provider &amp;#34;google&amp;#34; {
  project = &amp;#34;$GCP_PROJECT_ID&amp;#34;
}

// Topic
resource &amp;#34;google_pubsub_topic&amp;#34; &amp;#34;main&amp;#34; {
  name = &amp;#34;cloud-logs&amp;#34;
}

// Log sink
variable &amp;#34;inclusion_filter&amp;#34; {
  type        = string
  description = &amp;#34;Optional GCP Logs query which can filter logs being routed to the pub/sub topic and promtail&amp;#34;
}

resource &amp;#34;google_logging_project_sink&amp;#34; &amp;#34;main&amp;#34; {
  name                   = &amp;#34;cloud-logs&amp;#34;
  destination            = &amp;#34;pubsub.googleapis.com/${google_pubsub_topic.main.id}&amp;#34;
  filter                 = var.inclusion_filter
  unique_writer_identity = true
}

resource &amp;#34;google_pubsub_topic_iam_binding&amp;#34; &amp;#34;log-writer&amp;#34; {
  topic = google_pubsub_topic.main.name
  role  = &amp;#34;roles/pubsub.publisher&amp;#34;
  members = [
    google_logging_project_sink.main.writer_identity,
  ]
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Then, another snippet needs to be added depending on whether the &lt;code&gt;pull&lt;/code&gt; or &lt;code&gt;push&lt;/code&gt; flavour is chosen.&lt;/p&gt;
&lt;h3 id=&#34;pull-1&#34;&gt;Pull&lt;/h3&gt;
&lt;p&gt;The following snippet configures a subscription to the pub/sub topic which Promtail will subscribe to.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;terraform&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-terraform&#34;&gt;// Subscription
resource &amp;#34;google_pubsub_subscription&amp;#34; &amp;#34;main&amp;#34; {
  name  = &amp;#34;cloud-logs&amp;#34;
  topic = google_pubsub_topic.main.name
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Then, to create the new resources run the snippet below after filling in the required variables.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;terraform apply \
    -var=&amp;#34;inclusion_filter=&amp;lt;GCP Logs query of what logs to include&amp;gt;&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;push-1&#34;&gt;Push&lt;/h3&gt;
&lt;p&gt;The following snippet configures a push subscription to the pub/sub topic which will forward logs to Promtail.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;terraform&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-terraform&#34;&gt;// Subscription
variable &amp;#34;push_endpoint_url&amp;#34; {
  type        = string
  description = &amp;#34;Public URL where Promtail is hosted.&amp;#34;
}

resource &amp;#34;google_pubsub_subscription&amp;#34; &amp;#34;main&amp;#34; {
  name  = &amp;#34;cloud-logs&amp;#34;
  topic = google_pubsub_topic.main.name
  push_config {
    push_endpoint = var.push_endpoint_url
    attributes = {
      x-goog-version = &amp;#34;v1&amp;#34;
    }
  }
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;To create the new resources, run the snippet below after filling in the required variables.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;terraform apply \
    -var=&amp;#34;push_endpoint_url=&amp;lt;Promtail public URL&amp;gt;&amp;#34; \
    -var=&amp;#34;inclusion_filter=&amp;lt;GCP Logs query of what logs to include&amp;gt;&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;serviceaccount-for-promtail&#34;&gt;ServiceAccount for Promtail&lt;/h2&gt;
&lt;p&gt;We need a service account with the following permissions:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;pubsub.subscriber&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This enables Promtail to read log entries from the pubsub subscription created before.&lt;/p&gt;
&lt;p&gt;You can find an example for Promtail scrape config for &lt;code&gt;gcplog&lt;/code&gt; &lt;a href=&#34;../../scraping/#gcp-log-scraping&#34;&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;If you are scraping logs from multiple GCP projects, then this serviceaccount should have above permissions in all the projects you are tyring to scrape.&lt;/p&gt;
&lt;h2 id=&#34;operations&#34;&gt;Operations&lt;/h2&gt;
&lt;p&gt;Sometimes, you may wish to clear the pending pubsub queue containing logs.&lt;/p&gt;
&lt;p&gt;These messages stays in Pubsub Subscription until they&amp;rsquo;re acknowledged. The following command removes log messages without needing to be consumed via Promtail or any other pubsub consumer.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;gcloud pubsub subscriptions seek &amp;lt;subscription-path&amp;gt; --time=&amp;lt;yyyy-mm-ddThh:mm:ss&amp;gt;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;To delete all the old messages until now, set &lt;code&gt;--time&lt;/code&gt; to current time.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;gcloud pubsub subscriptions seek projects/my-project/subscriptions/cloud-logs --time=$(date &amp;#43;%Y-%m-%dT%H:%M:%S)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;advanced-log-filter&#34;&gt;Advanced log filter&lt;/h2&gt;
&lt;p&gt;So far we&amp;rsquo;ve covered admitting GCS bucket logs into Grafana Loki, but often one may need to add multiple cloud resource logs and may also need to exclude unnecessary logs. The following is a more complex example.&lt;/p&gt;
&lt;p&gt;We use the &lt;code&gt;log-filter&lt;/code&gt; option to include logs and the &lt;code&gt;exclusion&lt;/code&gt; option to exclude specific logs.&lt;/p&gt;
&lt;h3 id=&#34;use-case&#34;&gt;Use Case&lt;/h3&gt;
&lt;p&gt;Include the following cloud resource logs:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;GCS bucket&lt;/li&gt;
&lt;li&gt;Kubernetes&lt;/li&gt;
&lt;li&gt;IAM&lt;/li&gt;
&lt;li&gt;HTTP Load balancer&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;We also exclude specific HTTP load balancer logs based on payload and status code.&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;$ gcloud logging sinks create cloud-logs pubsub.googleapis.com/projects/my-project/topics/cloud-logs \
--log-filter=&amp;#39;resource.type=(&amp;#34;gcs_bucket OR k8s_cluster OR service_account OR iam_role OR api OR audited_resource OR http_load_balancer&amp;#34;)&amp;#39; \
--description=&amp;#34;Cloud logs&amp;#34; \
--exclusion=&amp;#39;name=http_load_balancer,filter=&amp;lt;&amp;lt;EOF
resource.type=&amp;#34;http_load_balancer&amp;#34;
(
	(
		jsonPayload.statusDetails=(&amp;#34;byte_range_caching&amp;#34; OR &amp;#34;websocket_closed&amp;#34;)
	)
		OR
	(
		http_request.status=(101 OR 206)
	)
)
EOF&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="run-the-promtail-client-on-google-cloud-platform">Run the Promtail client on Google Cloud Platform&lt;/h1>
&lt;p>This document explains how one can setup Google Cloud Platform to forward its cloud resource logs from a particular GCP project into Google Pubsub topic so that is available for Promtail to consume.&lt;/p></description></item></channel></rss>