<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Vizzscript</title>
    <description>The latest articles on DEV Community by Vizzscript (@vratik_zade_4a21c54662e64).</description>
    <link>https://dev.to/vratik_zade_4a21c54662e64</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2853856%2Fca4d4e28-aebb-417b-9f93-348a44ab3a73.jpeg</url>
      <title>DEV Community: Vizzscript</title>
      <link>https://dev.to/vratik_zade_4a21c54662e64</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vratik_zade_4a21c54662e64"/>
    <language>en</language>
    <item>
      <title>What is &amp; how did I setup Vector, Loki &amp; Grafana in Linux Ubuntu?</title>
      <dc:creator>Vizzscript</dc:creator>
      <pubDate>Wed, 12 Feb 2025 17:37:13 +0000</pubDate>
      <link>https://dev.to/vratik_zade_4a21c54662e64/what-is-how-did-i-setup-vector-loki-grafana-in-linux-ubuntu-3fnc</link>
      <guid>https://dev.to/vratik_zade_4a21c54662e64/what-is-how-did-i-setup-vector-loki-grafana-in-linux-ubuntu-3fnc</guid>
      <description>&lt;h3&gt;
  
  
  Prerequisites:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Vector:&lt;/strong&gt; It is observability pipeline that collects, transforms, routes logs, metrics, &amp;amp; traces from various sources to different destinations.
It is lightweight, high-performance, &amp;amp; written in Rust.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Loki:&lt;/strong&gt; Loki is a log aggregation system developed by Grafana Labs, similar to Prometheus but for logs. Loki can be used to collect application logs from multiple microservices &amp;amp; analyze them efficiently using Grafana dashboards.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Grafana:&lt;/strong&gt; Grafana is an open-source analytics &amp;amp; monitoring platform used for visualizing &amp;amp; analyzing data from various sources. Grafana is commonly used to create monitoring dashboardds for system metrics, logs &amp;amp; application performance, integrating with Loki for log visualization.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  How they work together?
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Vector&lt;/strong&gt; collects logs &amp;amp; metrics from applications, containers, or systems.&lt;/li&gt;
&lt;li&gt;It processes &amp;amp; sends logs to Loki for storage &amp;amp; indexing.&lt;/li&gt;
&lt;li&gt;Grafana queries and visualizes logs from Loki, providing insights through dashboards.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Why there is need of using such technologies?
&lt;/h3&gt;

&lt;p&gt;Okay! lets imagine that there is an open book test in your college, when you start solving first question you need to search each and every page for the correct solution and there might not just a single book to find solution so it will be a tough for you to solve the test in stipulated time.&lt;/p&gt;

&lt;p&gt;Now, let's bring in Vector, Loki &amp;amp; Grafana to help!&lt;/p&gt;

&lt;p&gt;Think of &lt;strong&gt;Vector&lt;/strong&gt; as a system that automatically adds bookmarks to important topics in all your books. Instead of flipping through every page, you can now quickly find the correct section based on the keywords of the question.&lt;/p&gt;

&lt;p&gt;Now, let's say you have multiple books, but instead of searching through each one manually, you have a smart bookshelf(Loki) that groups books by subjects. For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Math problems go in the "Math" section.&lt;/li&gt;
&lt;li&gt;C programming problems go in the "C" section.&lt;/li&gt;
&lt;li&gt;Java programming problems go in the "Java" section.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So, when you need to find an answer, you don't search the whole bookshelf; you just pick the right section &amp;amp; look there!&lt;/p&gt;

&lt;p&gt;Now, imagine you have a magic screen(Grafana) that, when you type your question, shows you exactly which book &amp;amp; page have the answer. You don't even need to check manually; you get the answer instantly!&lt;/p&gt;

&lt;p&gt;This is exactly how logs &amp;amp; monitoring work in real-world applications. Instead of searching through millions of logs manually, these tools helps you find issues quickly, analyze data efficiently, &amp;amp; keep systems running smoothly!!&lt;/p&gt;

&lt;h3&gt;
  
  
  Setting up Vector, Loki &amp;amp; Grafana on Linux Ubuntu
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Setting up Vector&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Install vector using following command:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; bash -c "$(curl -L https://setup.vector.dev)"
 sudo apt-get install vector
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Verify if Vector is properly installed:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; vector --version
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Start &amp;amp; check if the Vector is running in your local system using systemctl command&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; sudo systemctl start vector
 sudo systemctl status vector
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Run Vector using following command:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; sudo vector --config /path/to/vector.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Note: Example configuration(vector.yaml)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Vector Configuration

# Change this to use a non-default directory for Vector data storage:
# data_dir: "/var/lib/vector"

# Source configuration for reading logs
sources:
  my_source_id:
    type: file
    include:
      - /path/to/application.log
    read_from: beginning

# Transforms to parse logs
transforms:
  parse_file_logs:
    type: remap
    inputs: ["my_source_id"]
    source: |
      .timestamp = now()
      .message = string!(.message)
      .host = get_env_var!("HOSTNAME")
      .response_time = to_int!(.response_time)

# Sinks to output parsed logs
sinks:
  console:
    type: console
    inputs: ["parse_file_logs"]
    encoding:
      codec: json
      json:
        pretty: true
  loki:
    type: loki
    inputs: ["parse_file_logs"]
    endpoint: "http://localhost:3100"  # Change if Loki is running on another server
    Encoding:
      codec: json
      json:
        pretty: true
    labels:
      source: "vector"
      job: "application_logs"

# Vector's GraphQL API (disabled by default)
# Uncomment to enable API access at http://localhost:8686
# api:
#   enabled: true
#   address: "127.0.0.1:8686"

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2: Setting up Loki&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Install software-properties-common&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt install -y software-properties-common
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Fetch grafana package key from grafana:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt-key adv --fetch-keys https://packages.grafana.com/gpg.key
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add grafana repository:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Install Loki using following command:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   sudo apt install loki
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Start, enable &amp;amp; check if Loki is running in your system.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   sudo systemctl enable loki
   sudo systemctl start loki
   sudo systemctl status loki
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3: Setting up Grafana&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Run the following command:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   sudo apt install -y grafana
   sudo systemctl enable --now grafana-server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Access Grafana&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open browser &amp;amp; navigate to: &lt;a href="http://localhost:3000" rel="noopener noreferrer"&gt;http://localhost:3000&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Login with below credentials:

&lt;ul&gt;
&lt;li&gt;Username: admin&lt;/li&gt;
&lt;li&gt;Password: admin&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;You will be asked to setup new password &amp;amp; then will be redirect to Grafana homepage.&lt;/li&gt;

&lt;/ol&gt;

&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Add Loki as a Data Source&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Navigate to &lt;strong&gt;Configuration&lt;/strong&gt; &amp;gt; &lt;strong&gt;Data Sources&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Select &lt;strong&gt;Loki&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Enter &lt;a href="http://localhost:3100" rel="noopener noreferrer"&gt;http://localhost:3100&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Save &amp;amp; Test&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Visualize logs in Grafana&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Go to &lt;strong&gt;Explore&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Select &lt;strong&gt;Loki&lt;/strong&gt; as the data source.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Use the following query:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{job="application_logs"}
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click &lt;strong&gt;Run Query&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>vector</category>
      <category>loki</category>
      <category>grafana</category>
      <category>linux</category>
    </item>
  </channel>
</rss>
