<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ruslan Kh. on Medium]]></title>
        <description><![CDATA[Stories by Ruslan Kh. on Medium]]></description>
        <link>https://medium.com/@xakrume?source=rss-43b00e45fce3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*wPjV_qQqkO9JUqLw5ciNfQ.jpeg</url>
            <title>Stories by Ruslan Kh. on Medium</title>
            <link>https://medium.com/@xakrume?source=rss-43b00e45fce3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 18:33:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@xakrume/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Mastering Go-templates in Ansible with Jinja2.]]></title>
            <link>https://medium.com/@xakrume/mastering-go-templates-in-ansible-with-jinja2-1605b2398928?source=rss-43b00e45fce3------2</link>
            <guid isPermaLink="false">https://medium.com/p/1605b2398928</guid>
            <category><![CDATA[jinja2]]></category>
            <category><![CDATA[ansible]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[linux]]></category>
            <dc:creator><![CDATA[Ruslan Kh.]]></dc:creator>
            <pubDate>Sat, 31 Jan 2026 21:12:37 GMT</pubDate>
            <atom:updated>2026-01-31T21:12:37.624Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ezYpwNXPE55FdkQN" /><figcaption>Photo by <a href="https://unsplash.com/fr/@alanaktion?utm_source=medium&amp;utm_medium=referral">Alan Hardman</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>Introduction: Streamline DevOps Workflow with Ansible, Jinja2 and Go-templates.</h4><p>For seasoned DevOps professionals, YAML files with Go-inspired string interpolation like those in Prometheus, Loki, Promtail, and Kapacitor can be challenging. However, with the power of Jinja2-a robust Python templating engine-you can overcome these hurdles and effectively manage your Ansible configurations. In this guide, we’ll discuss the nuances of handling Go-templates in Ansible with Jinja2, and provide you with actionable insights and techniques to refine your DevOps workflow.</p><h4>Section 1: Unraveling the Challenges of Go-templates in Ansible for DevOps.</h4><p>One obstacle DevOps professionals face when using Ansible is distinguishing between Ansible variables and Go template expressions in YAML files. It’s critical to create a YAML file that contains literal {{ mustaches }} that Ansible should not interpolate. This is where Jinja2, a widely used Python templating engine, can be a game changer.</p><h4>Section 2: Leveraging Jinja2 to Manage Go-templates in Ansible.</h4><p>Ansible can process Go-templates using Jinja2’s {% raw %} and {% endraw %} tags. These tags tell Ansible not to treat the text they enclose as Jinja2 code, thus preventing variable interpolation. By incorporating these Jinja2 tags, you can easily manage your Ansible configurations that contain Go-templates, greatly simplifying your DevOps workflow.</p><h4>Section 3: Hands-on Examples for DevOps Professionals.</h4><p>To better understand how to use Jinja2 with Ansible while working with Go templates, we’ll walk you through some practical examples.</p><p>In promtail.yaml:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f876e2c98bbaab95406bc90cae2c26d3/href">https://medium.com/media/f876e2c98bbaab95406bc90cae2c26d3/href</a></iframe><p>In Ansible jinja2 template:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b0f64b0759d721993dd52a56b031bbfe/href">https://medium.com/media/b0f64b0759d721993dd52a56b031bbfe/href</a></iframe><p>With these example at your disposal, you’ll be well equipped to handle Go-templates in your Ansible configurations, making your DevOps tasks more efficient and manageable.</p><h4>Conclusion: Enhancing Your DevOps Workflow with Ansible, Jinja2, and Go-templates</h4><p>Using Jinja2 to manage Go-templates in Ansible is an efficient technique that can greatly enhance your DevOps workflow. By mastering the methods discussed in this guide, you’ll be well-positioned to manage your Ansible configurations that include Go-templates, simplifying your tasks as a DevOps professional.</p><h4>Sources</h4><p>Jinja2 documentation — <a href="https://jinja.palletsprojects.com/en/3.0.x/templates/">https://jinja.palletsprojects.com/en/3.0.x/templates/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1605b2398928" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Challenges in Customizing the Command Prompt in Linux and Their Solutions.]]></title>
            <link>https://faun.pub/challenges-in-customizing-the-command-prompt-in-linux-and-their-solutions-c489bada22fa?source=rss-43b00e45fce3------2</link>
            <guid isPermaLink="false">https://medium.com/p/c489bada22fa</guid>
            <category><![CDATA[bash]]></category>
            <category><![CDATA[prompt-engineering]]></category>
            <category><![CDATA[prompt]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Ruslan Kh.]]></dc:creator>
            <pubDate>Wed, 07 Jun 2023 14:51:00 GMT</pubDate>
            <atom:updated>2023-06-07T19:21:47.981Z</atom:updated>
            <content:encoded><![CDATA[<h4>Transform the Command Prompt: A Journey of Color, Creativity, and Customization</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/1*cpMMeK17n9yvPpYj2WP5bw.gif" /><figcaption>recording a screen from a terminal with an incorrectly configured bash prompt</figcaption></figure><h4>Section 1: The Quest for a Customized Command Prompt</h4><p>As a passionate Linux enthusiast, I’ve always appreciated the unparalleled level of customization that Linux offers. One of the most enjoyable activities for Linux users is personalizing the command line interface (CLI) to suit their unique preferences and style. Today, I want to address a challenge that often leaves users feeling frustrated and confused-customizing the prompt in popular shells like Bash or Zsh.</p><h4>Section 2: Unleashing the Power of ANSI Escape Sequences</h4><p>The command prompt serves as the gateway to the shell, providing users with valuable information and a means to interact with the system. It allows us to execute commands, navigate directories, and monitor the state of our environment. While the default prompt is functional, many users seek to enhance their CLI experience by turning the prompt into a canvas for self-expression.</p><p>Imagine this scenario: You’ve stumbled into the fascinating world of ANSI escape sequences. These powerful sequences allow you to infuse your prompt with vibrant colors, dynamic information, and visual flair. Intrigued by the possibilities, you embark on a quest to create the perfect prompt — a reflection of your personality and style.</p><h4>Section 3: The Frustration of Cursor Positioning</h4><p>Hours are spent meticulously tinkering with colors, experimenting with different layouts, and adding timestamps or system details. With eager anticipation, you save your changes and launch your terminal, only to be confronted with a cursor that seems to have a mind of its own. It jumps around unpredictably, causing frustration and confusion. Was the quest for an aesthetically pleasing prompt worth all the trouble?</p><h4>Section 4: The Culprit: Improperly Enclosed ANSI Escape Sequences</h4><p>The root of this problem lies in the way the shell interprets ANSI escape sequences. While these sequences are responsible for the colorful and dynamic elements in your prompt, they can also interfere with cursor positioning if they are not properly enclosed. The shell interprets certain ANSI escape sequences as printable characters, resulting in the erratic cursor behavior you’re experiencing.</p><h4>Section 5: Demystifying the Bash Prompt Setup</h4><p>To better understand the cursor positioning problem, let’s examine the structure of a typical Bash prompt, which is controlled by the PS1 variable. PS1 defines the format and content of the primary prompt displayed to the user. It is a string that contains text, escape sequences, and special variables.</p><h4>Section 6: Commonly Used Variables for Bash PS1</h4><p>Here’s an example of a misconfigured bash prompt:</p><pre>if [[ ${EUID} == 0 ]]; then<br>  PS1=&quot;[\[\e[1;34m\]\u\e[m@\[\e[1;31m\]\H\[\e[0m\] \W]\\$ &quot;<br>else<br>  PS1=&quot;[\[\e[1;34m\]\u\e[m@\[\e[1;32m\]\H\[\e[0m\] \W]\$ &quot;<br>fi</pre><p>In this code snippet, the ANSI escape sequences, such as \[\e[1;34m\] and \[\e[1;31m\], are used to change the color of the text. However, some escape sequences are not properly enclosed in \[ and \]. This omission causes the shell to treat them as printable characters, leading to the cursor misbehavior you&#39;ve encountered.</p><h4>Section 7: Fixing the Cursor Positioning Issue</h4><p>To rectify this issue, we can modify the prompt setup as follows:</p><pre>if [[ ${EUID} == 0 ]]; then<br>  PS1=&quot;\[\e[1;34m\][\u@\[\e[1;31m\]\H\[\e[0m\] \W]\\$\[\e[0m\] &quot;<br>else<br>  PS1=&quot;\[\e[1;34m\][\u@\[\e[1;32m\]\H\[\e[0m\] \W]\$\[\e[0m\] &quot;<br>fi</pre><p>By encapsulating all ANSI escape sequences within \[ and \], we instruct the shell to disregard the non-printable characters, ensuring correct cursor placement.</p><p>Let’s take a look at the diff to clearly see the changes and errors that have been made:</p><pre>if [[ ${EUID} == 0 ]]; then<br>-  PS1=&quot;[\[\e[1;34m\]\u\e[m@\[\e[1;31m\]\H\[\e[0m\] \W]\\$ &quot;<br>+  PS1=&quot;\[\e[1;34m\][\u@\[\e[1;31m\]\H\[\e[0m\] \W]\\$\[\e[0m\] &quot;<br>else<br>-  PS1=&quot;[\[\e[1;34m\]\u\e[m@\[\e[1;32m\]\H\[\e[0m\] \W]\$ &quot;<br>+  PS1=&quot;\[\e[1;34m\][\u@\[\e[1;32m\]\H\[\e[0m\] \W]\$\[\e[0m\] &quot;<br>fi</pre><h4>Section 8: Expanding the Horizons: Prompt Configurations</h4><p>But why leave it at that? Let’s look at some other prompt configurations:</p><pre># Make the user part of the prompt bold and underlined<br>PS1=&quot;\[\e[1;4m\]\u\[\e[0m\]@\H \W \$ &quot;<br><br># Add a timestamp to your prompt<br>PS1=&quot;\t \u@\H \W \$ &quot;</pre><p>These variations demonstrate the vast creative potential of customizing your prompt. You can combine different colors, styles, and informational elements to make your prompt truly unique and tailored to your needs.</p><h4>Section 9: Extending the Customization to Zsh</h4><p>In addition to Bash, Zsh-a shell designed to be more user-friendly and flexible-offers similar prompt customization capabilities. Zsh also uses the PS1 variable to define the prompt. However, Zsh introduces its own set of special prompt sequences denoted by %, such as %n for the username and %m for the hostname. ANSI escape sequences can still be used in Zsh, but they should be enclosed in %{ and %} instead of \[ and \].</p><p>Here is an example of how to customize the zsh prompt:</p><pre>PROMPT=&#39;%F{blue}%n%f@%m %~ %# &#39;</pre><p>In this configuration, %F{blue} sets the color of the following text to blue, %n represents the username, %f resets the color, %m represents the hostname, %~ represents the current working directory, and %# displays a &#39;#&#39; symbol for the root user and a &#39;%&#39; symbol for others.</p><h4>Section 10: Embracing the Journey of Customization</h4><p>Customizing your shell prompt can be an interesting and enlightening process. It allows you to create an environment that reflects your personality, preferences, and workflow. While it may seem daunting at first, once you grasp the basics and understand how to properly enclose escape sequences, the effort becomes worthwhile.</p><h4>Section 11: Conclusion: Your Personalized Command Prompt</h4><p>In conclusion, customizing the Linux command prompt is an exciting endeavor. By incorporating ANSI escape sequences, using special variables, and experimenting with colors and layouts, you can create a prompt that is both aesthetically pleasing and functional. Embrace the challenges you encounter along the way, as they provide valuable learning experiences. Remember, a Linux enthusiast’s journey is marked by a curiosity to explore and a willingness to overcome obstacles. So go ahead, unleash your creativity, and make your command prompt truly yours.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*UxaN3pUM1ladd-NK.png" /></figure><h4>👋 If you find this helpful, please click the clap 👏 button below a few times to show your support for the author 👇</h4><h4>🚀<a href="http://from.faun.to/r/8zxxd">Join FAUN Developer Community &amp; Get Similar Stories in your Inbox Each Week</a></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c489bada22fa" width="1" height="1" alt=""><hr><p><a href="https://faun.pub/challenges-in-customizing-the-command-prompt-in-linux-and-their-solutions-c489bada22fa">Challenges in Customizing the Command Prompt in Linux and Their Solutions.</a> was originally published in <a href="https://faun.pub/">FAUN.dev() 🐾</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Enhancing Medium Articles with Recorded Terminal GIFs using agg, ascinema]]></title>
            <link>https://medium.com/@xakrume/how-to-enrich-your-medium-articles-with-recorded-terminal-gifs-using-agg-d25a0acf5223?source=rss-43b00e45fce3------2</link>
            <guid isPermaLink="false">https://medium.com/p/d25a0acf5223</guid>
            <category><![CDATA[gif]]></category>
            <category><![CDATA[ascinema]]></category>
            <category><![CDATA[medium]]></category>
            <category><![CDATA[bash]]></category>
            <category><![CDATA[terminal]]></category>
            <dc:creator><![CDATA[Ruslan Kh.]]></dc:creator>
            <pubDate>Sun, 28 May 2023 19:04:14 GMT</pubDate>
            <atom:updated>2023-05-28T19:24:05.607Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*eSGVD5s0Oodj5VHZ" /><figcaption>Photo by <a href="https://unsplash.com/@black_onion?utm_source=medium&amp;utm_medium=referral">Konstantinos Hasandras</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>As we continue to see a shift towards visual content, adding animated GIFs of your coding terminal sessions to your articles can greatly increase user engagement and understanding. In this step-by-step guide, we’ll explore how to do this using the <strong>agg</strong> (asciinema gif generator) tool, the successor to <strong>asciicast2gif</strong>. This tutorial assumes that you’re running MacOS with Homebrew or MacPorts installed or Linux (Debian or RedHat based distros).</p><figure><img alt="ascinema converted to gif" src="https://cdn-images-1.medium.com/max/843/1*V0qC8wiD_2hJqtWYGdVPzg.gif" /><figcaption>Recording of terminal operation in GIF format</figcaption></figure><h3>Getting Started: Installation</h3><p>First we need to install <strong>asciinema</strong> and <strong>agg</strong>. If you used <strong>asciicast2gif</strong> before, you can forget about it, it’s no longer needed. Here are the commands you need to run:</p><h4>Linux users:</h4><p><strong>Arch Linux</strong></p><pre>pacman -S asciinema</pre><p><strong>Debian</strong></p><pre>sudo apt-get install asciinema</pre><p><strong>Fedora</strong> (For Fedora &lt; 22)</p><pre>sudo yum install asciinema</pre><p><strong>Fedora</strong> &gt;= 22</p><pre>sudo dnf install asciinema</pre><p><strong>Gentoo Linux</strong></p><pre>emerge -av asciinema</pre><p><strong>NixOS / Nix</strong></p><pre>nix-env -i asciinema</pre><p><strong>openSUSE</strong></p><pre>zypper in asciinema</pre><p><strong>Ubuntu</strong></p><pre>sudo apt install software-properties-common<br>sudo apt-add-repository ppa:zanchey/asciinema<br>sudo apt-get update<br>sudo apt-get install asciinema</pre><h4>macOS users:</h4><p>macOS users can install two programs from the same repository</p><p><strong>Homebrew</strong>:</p><pre>brew install asciinema agg</pre><p><strong>MacPorts:</strong></p><pre>sudo port install asciinema agg</pre><h3>Installing <strong>agg</strong> (asciinema gif generator) for Linux.</h3><ol><li>Navigate to the releases section of the project on GitHub <a href="https://github.com/asciinema/agg/releases">https://github.com/asciinema/agg/releases</a>.</li><li>Locate the appropriate binary for your system. The naming convention usually includes the version number and target operating system.</li><li>Use a command such as wget or curl to download the binary file for Linux:</li></ol><pre># Create the user&#39;s home binary directory<br>mkdir ~/bin<br><br># Linux x86_64<br>wget https://github.com/asciinema/agg/releases/latest/download/agg-x86_64-unknown-linux-gnu -O ~/bin/agg<br><br># Linux aarch64 (arm64)<br>wget https://github.com/asciinema/agg/releases/latest/download/agg-aarch64-unknown-linux-gnu -O ~/bin/agg<br><br># Add execution rights<br>chmod +x ~/bin/agg</pre><blockquote>macOS users install <strong>agg</strong> in the previous section.</blockquote><h3>Recording a Terminal Session:</h3><p>Now that everything is installed, you’re ready to record your terminal session. The recording process is straightforward. Here’s how to do it:</p><pre>asciinema rec &lt;name_of_file&gt;.cast</pre><p>This command will record all terminal actions until you press <strong>Ctrl + d</strong> or type <strong>exit</strong>. Your screencast will be saved locally in a .cast file.</p><h3>Creating a GIF</h3><p>Now that you have your <strong>.cast</strong> file, converting it to a <strong>.gif</strong> is as simple as running the following command:</p><pre>agg &lt;name_of_file&gt;.cast &lt;name_of_file&gt;.gif</pre><p><strong>And voilà!</strong> You’ve created your GIF. <br><strong>agg</strong> also offers several customization options. For example, you can adjust the playback speed, choose a color theme, specify the font size, and more. Here’s an example of how to select the Monokai theme, use a larger font size, and set the playback speed to 2x:</p><pre>agg --theme monokai \<br>--font-size 20 \<br>--speed 2 \<br>&lt;name_of_source_file&gt;.cast &lt;name_of_gif_file&gt;.gif</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XTcwodZwq6EJCazxQAD6Dw.png" /><figcaption>converting ascinema file to GIF with additional options</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*in_77nqPF38vG3iRVQUmHA.gif" /><figcaption>converted ascinema file to GIF for playback at x2 speed</figcaption></figure><p>For a complete list of available options, run <strong>agg -h</strong>.</p><p>And that’s it! Now you can easily create animated GIFs of your terminal sessions and add them to your articles. Happy writing!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d25a0acf5223" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Efficient Data Migration Between Retention Policies in InfluxDB 1.8]]></title>
            <link>https://medium.com/@xakrume/efficient-data-migration-between-retention-policies-in-influxdb-1-8-ccea4da921a7?source=rss-43b00e45fce3------2</link>
            <guid isPermaLink="false">https://medium.com/p/ccea4da921a7</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[influxdb]]></category>
            <dc:creator><![CDATA[Ruslan Kh.]]></dc:creator>
            <pubDate>Tue, 25 Apr 2023 11:25:49 GMT</pubDate>
            <atom:updated>2023-04-26T08:26:40.253Z</atom:updated>
            <content:encoded><![CDATA[<h3>Efficient Data Migration Between Retention Policies in InfluxDB 1.8: Solving Memory and Timeout Issues</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MzpclhSFds7U6sWOeHzwjg.png" /><figcaption>influxdb logo</figcaption></figure><h4>Introduction:</h4><p>InfluxDB 1.8, already a popular time-series database, designed to efficiently store and manage time-stamped data. One of its features, retention policies, allows users to manage how long their data is kept. However, migrating data between different retention policies can be a challenging task, especially when dealing with systems with limited memory or slow disk speeds. In this article, we will discuss a Python script that automates the process of migrating data between retention policies in InfluxDB, overcoming memory and timeout issues.</p><h4>Prerequisites:</h4><ul><li>Familiarity with Python</li><li>Basic understanding of InfluxDB and its retention policy</li></ul><h4>The Problem:</h4><p>Migrating data between retention policies can be done with a simple InfluxDB query. The basic query for copying data between retention policies is as follows</p><pre>SELECT * INTO target_database.&quot;target_retention_policy&quot;.measurement FROM source_database.&quot;source_retention_policy&quot;.measurement GROUP BY *</pre><h4>The Solution:</h4><p>To address the challenges of data migration, a Python script was developed to automate the process of copying data between retention policies, taking into account the limitations of the system. The script breaks the data migration task into smaller chunks, ensuring that the InfluxDB process does not consume too much memory or exceed query timeouts.</p><p>The Python script uses the following steps:</p><ol><li>Get the list of retention policies and measurements.</li><li>Query the field keys for each measurement.</li><li>Determine the time range of the data you want to migrate.</li><li>Divide the data into smaller chunks based on a specified duration (e.g., a day).</li><li>Copy the data chunk by chunk using the SELECT INTO query.</li></ol><pre>import argparse<br>import datetime<br>import subprocess<br>import json<br>import time<br><br># Function to run InfluxDB queries<br>def run_influx_query(query):<br>    try:<br>        command = f&#39;/usr/bin/influx -username {USERNAME} -password {PASSWORD} -database &quot;{DATABASE}&quot; -execute &quot;{query}&quot; -format json&#39;<br>        result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, text=True)<br>        json_output = &quot;&quot;.join([line for line in result.stdout.splitlines() if line.strip().startswith(&#39;{&#39;) or line.strip().startswith(&#39;[&#39;)])<br>        return json_output<br>    except Exception as e:<br>        print(f&quot;Error running query: {e}&quot;)<br>        return None<br><br># Function to fix JSON output (convert &quot;true&quot; to &quot;True&quot; and &quot;false&quot; to &quot;False&quot;)<br>def fix_json_output(output):<br>    return output.replace(&quot;true&quot;, &quot;True&quot;).replace(&quot;false&quot;, &quot;False&quot;)<br><br># Set up command line arguments<br>parser = argparse.ArgumentParser(description=&quot;Copy data between retention policies in InfluxDB&quot;)<br>parser.add_argument(&#39;-d&#39;, &#39;--database&#39;, required=True, help=&#39;Database name&#39;)<br>parser.add_argument(&#39;-u&#39;, &#39;--username&#39;, required=True, help=&#39;InfluxDB username&#39;)<br>parser.add_argument(&#39;-p&#39;, &#39;--password&#39;, required=True, help=&#39;InfluxDB password&#39;)<br>args = parser.parse_args()<br><br># Assign command line arguments to variables<br>DATABASE = args.database<br>USERNAME = args.username<br>PASSWORD = args.password<br><br># Get list of retention policies<br>rp_list_output = fix_json_output(run_influx_query(&quot;SHOW RETENTION POLICIES&quot;))<br>rp_list = eval(rp_list_output)[&quot;results&quot;][0][&quot;series&quot;][0][&quot;values&quot;]<br><br># Display retention policies and ask the user to choose source and target<br>print(&quot;Retention policies:&quot;)<br>for i, rp in enumerate(rp_list):<br>    print(f&quot;{i}: {rp[0]}&quot;)<br><br>source_rp_index = int(input(&quot;Choose the source retention policy index: &quot;))<br>target_rp_index = int(input(&quot;Choose the target retention policy index: &quot;))<br>source_rp = rp_list[source_rp_index][0]<br>target_rp = rp_list[target_rp_index][0]<br><br># Get list of measurements<br>measurements_output = fix_json_output(run_influx_query(&quot;SHOW MEASUREMENTS&quot;))<br>measurements = eval(measurements_output)[&quot;results&quot;][0][&quot;series&quot;][0][&quot;values&quot;]<br><br># Iterate over measurements<br>for measurement in measurements:<br>    measurement_name = measurement[0]<br><br>    # Get field keys for each measurement<br>    field_keys_output = fix_json_output(run_influx_query(f&#39;SHOW FIELD KEYS FROM \\&quot;{source_rp}\\&quot;.{measurement_name}&#39;))<br>    field_keys_data = eval(field_keys_output)[&quot;results&quot;]<br><br>    # Check if field keys are found<br>    if field_keys_data and &quot;series&quot; in field_keys_data[0]:<br>        field_keys = field_keys_data[0][&quot;series&quot;][0][&quot;values&quot;]<br>    else:<br>        print(f&quot;No field keys found for measurement {measurement_name}, skipping...&quot;)<br>        continue<br><br>    # Iterate over field keys<br>    for field_key in field_keys:<br>        field = field_key[0]<br><br>        # Get the first timestamp of each field<br>        first_timestamp_output = fix_json_output(run_influx_query(f&#39;SELECT FIRST(&quot;{field}&quot;) FROM \\&quot;{source_rp}\\&quot;.{measurement_name}&#39;))<br>        first_point = eval(first_timestamp_output)[&quot;results&quot;][0][&quot;series&quot;][0][&quot;values&quot;][0]<br>        start_time = first_point[0]<br><br>        # Calculate time range and chunk size<br>        start_dt = datetime.datetime.fromtimestamp(start_time // 1000000000)<br>        end_dt = datetime.datetime.utcnow()<br>        time_difference = end_dt - start_dt<br>        chunk_size = datetime.timedelta(days=1)<br>        total_chunks = (time_difference // chunk_size) + 1<br><br>        # Iterate over chunks<br>        for i in range(total_chunks):<br>            current_start = start_dt + i * chunk_size<br>            current_end = start_dt + (i + 1) * chunk_size<br><br>            # Check if current_end is greater than end_dt<br>            if current_end &gt; end_dt:<br>                current_end = end_dt<br><br>            current_start_str = current_start.isoformat() + &quot;Z&quot;<br>            current_end_str = current_end.isoformat() + &quot;Z&quot;<br><br>            # Print the current processing range and field<br>            print(f&quot;Processing data from {current_start_str} to {current_end_str} : {measurement_name} - {field}&quot;)<br><br>            # Measure elapsed time for each import cycle<br>            start_time = time.time()<br><br>            # Run the SELECT INTO query to copy data<br>            query = f&#39;SELECT {field} INTO {DATABASE}.\\&quot;{target_rp}\\&quot;.{measurement_name} FROM {DATABASE}.\\&quot;{source_rp}\\&quot;.{measurement_name} WHERE time &gt;= \&#39;{current_start_str}\&#39; AND time &lt; \&#39;{current_end_str}\&#39; GROUP BY *&#39;<br>            run_influx_query(query)<br><br>            # Calculate and print elapsed time<br>            elapsed_time = time.time() - start_time<br>            print(f&quot;Finished processing data from {current_start_str} to {current_end_str} (elapsed time: {elapsed_time:.2f} seconds)&quot;)<br><br># Print completion message<br>print(&quot;Data copy process has finished.&quot;)</pre><p>Save the above code as a file named influxdb_migration.py.</p><h4>Usage:</h4><pre>python influxdb_migration.py -d &lt;database&gt; -u &lt;username&gt; -p &lt;password&gt;</pre><p>Before using the script, we need to create a retention policy into which we will copy the data. The script does not create a new retention policy.</p><h4>Task</h4><p>Copy the data from retention policy 180d to 6M to rename the retention policy. Then delete the 180d retention policy.</p><p><strong>Example of creating a new retention policy (6 months)</strong>:</p><pre>CREATE RETENTION POLICY &quot;6M&quot; ON &quot;telegraf&quot; DURATION 180d REPLICATION 1 SHARD DURATION 168h</pre><h4>Example of the script:</h4><pre>$ python influxdb_migration.py -d telegraf -u monitoring -p uynKqLavUwMfNE7s4bNY<br>Retention policies:<br>0: autogen<br>1: 30d<br>2: 180d<br>3: 6M<br>4: 1y<br>Choose the source retention policy index: 2<br>Choose the target retention policy index: 3<br>...<br>Processing data from 2022-11-23T03:00:00Z to 2022-11-24T03:00:00Z : cgroup - mem <br>Finished processing data from 2022-11-23T03:00:00Z to 2022-11-24T03:00:00Z (elapsed time: 38.06 seconds)<br>Processing data from 2022-11-24T03:00:00Z to 2022-11-25T03:00:00Z : cgroup - mem <br>Finished processing data from 2022-11-24T03:00:00Z to 2022-11-25T03:00:00Z (elapsed time: 35.12 seconds)<br>Processing data from 2022-11-25T03:00:00Z to 2022-11-26T03:00:00Z : cgroup - mem <br>Finished processing data from 2022-11-25T03:00:00Z to 2022-11-26T03:00:00Z (elapsed time: 27.00 seconds)<br>Processing data from 2022-11-26T03:00:00Z to 2022-11-27T03:00:00Z : cgroup - mem <br>Finished processing data from 2022-11-26T03:00:00Z to 2022-11-27T03:00:00Z (elapsed time: 27.20 seconds)<br>Processing data from 2022-11-27T03:00:00Z to 2022-11-28T03:00:00Z : cgroup - mem <br>Finished processing data from 2022-11-27T03:00:00Z to 2022-11-28T03:00:00Z (elapsed time: 39.26 seconds)<br>Processing data from 2022-11-28T03:00:00Z to 2022-11-29T03:00:00Z : cgroup - mem <br>Finished processing data from 2022-11-28T03:00:00Z to 2022-11-29T03:00:00Z (elapsed time: 47.62 seconds)<br>Processing data from 2022-11-29T03:00:00Z to 2022-11-30T03:00:00Z : cgroup - mem <br>Finished processing data from 2022-11-29T03:00:00Z to 2022-11-30T03:00:00Z (elapsed time: 32.51 seconds)<br>Processing data from 2022-12-01T03:00:00Z to 2022-12-02T03:00:00Z : cgroup - mem <br>Finished processing data from 2022-12-01T03:00:00Z to 2022-12-02T03:00:00Z (elapsed time: 29.93 seconds)<br>Processing data from 2022-12-02T03:00:00Z to 2022-12-03T03:00:00Z : cgroup - mem <br>Finished processing data from 2022-12-02T03:00:00Z to 2022-12-03T03:00:00Z (elapsed time: 25.90 seconds)<br>...<br>Data copy process has finished.</pre><h4>Conclusion:</h4><p>The Python script presented in this article provides an efficient solution for migrating data between retention policies in InfluxDB, especially on systems with memory or disk speed limitations. By breaking the data migration task into smaller chunks, it ensures that the process remains stable and does not exceed resource constraints or query timeouts. This script provides a convenient and reliable way to manage data retention in InfluxDB, allowing users to optimize their database configurations to meet their needs.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ccea4da921a7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Traceoute vs. MTR: A Comparison for Network Troubleshooting]]></title>
            <link>https://medium.com/@xakrume/traceoute-vs-mtr-a-comparison-for-network-troubleshooting-e982065910b9?source=rss-43b00e45fce3------2</link>
            <guid isPermaLink="false">https://medium.com/p/e982065910b9</guid>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[networking]]></category>
            <category><![CDATA[troubleshooting]]></category>
            <dc:creator><![CDATA[Ruslan Kh.]]></dc:creator>
            <pubDate>Wed, 12 Apr 2023 18:55:23 GMT</pubDate>
            <atom:updated>2023-05-18T20:49:51.808Z</atom:updated>
            <content:encoded><![CDATA[<h3>Traceroute vs MTR: A Comparison for Network Troubleshooting with Expanded Options</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M03DyZ6ymNz3sk1g4Op7Wg.png" /></figure><p>Hello network enthusiasts! Today we’re going to compare two popular network diagnostic tools, Traceoute and MTR (My TraceRoute), to help you decide which one to use for your specific needs. We’ll dive into their functionality, output, use cases, and more, as well as provide some handy examples.</p><h4>Functionality:</h4><ul><li><strong>Traceoute: </strong>A simple and easy-to-use tool that traces the path packets take to reach their destination. It does this by sending packets with increasing TTL (Time To Live) values, identifying each hop (intermediate device) along the way, and measuring the round-trip time (RTT) for each hop.</li><li><strong>MTR:</strong> A more advanced tool that combines the functionality of traceroute with the ping utility. In addition to tracing the route, it continuously sends ICMP or UDP packets to each hop, collecting real-time statistics on packet loss and latency.</li></ul><h4>Output:</h4><ul><li><strong>Traceoute:</strong> Provides a single snapshot of the route taken by packets, along with the RTT for each hop.</li><li><strong>MTR</strong>: Provides a dynamic output that displays an updated report of the route, latency, and packet loss for each hop, making it easy to monitor network performance over time and quickly identify problematic nodes.</li></ul><h4>Use Cases:</h4><ul><li><strong>Traceroute: </strong>Ideal for a quick, one-time analysis of network paths and latency. It can help identify routing problems and confirm that a particular path is reachable. Example command:</li></ul><pre>traceroute google.com</pre><ul><li><strong>MTR:</strong> Perfect for continuous monitoring and troubleshooting of network performance issues. It can help identify intermittent problems such as packet loss, high latency, or routing fluctuations. Example command:</li></ul><pre>mtr google.com</pre><h4>Pros and Cons:</h4><ul><li><strong>Traceoute.<br>+ <em>Pros:</em></strong> Simple, easy to use, and provides a quick overview of route and latency.<br> — <strong><em>Cons:</em></strong> Limited information (single snapshot) and may not be useful for diagnosing intermittent problems.</li><li><strong>MTR.<br><em>+ Pros:</em></strong> Combines the functionality of traceroute and ping, provides real-time monitoring of network performance, and is useful for diagnosing intermittent issues.<br> — <strong><em>Cons: </em></strong>More complex output (may require experience to interpret) and may consume more network resources due to continuous probing.</li></ul><h4>Expanded MTR:</h4><p>Options MTR offers an extensive range of options and customization features, such as:</p><ul><li>Reading hostname(s) from a file</li><li>IPv4 only or IPv6 only mode</li><li>Using UDP or TCP instead of ICMP echo</li><li>Specifying a named network interface</li><li>Binding the outgoing socket to an address</li><li>Adjusting the TTL to start, maximum number of hops, and maximum unknown host</li><li>Setting target and source port numbers for TCP, SCTP, or UDP</li><li>Changing packet size and payload bit pattern</li><li>Adjusting ICMP echo request interval and response wait time</li><li>Modifying the type of service field in the IP header</li><li>Displaying information from ICMP extensions</li><li>Adjusting the time to keep probe sockets open</li><li>Different output formats: report, wide report, JSON, XML, CSV, raw, and split</li><li>Using the curses terminal interface</li><li>Selecting the initial display mode</li><li>Enabling or disabling DNS resolution</li><li>Showing IP numbers and host names</li><li>Selecting output fields and IP information</li><li>Displaying AS number</li><li>Accessing help and version information</li></ul><h4>Expanded Traceroute:</h4><p>Options Traceroute also provides a variety of options, including:</p><ul><li>IPv4 or IPv6 mode</li><li>Socket-level debugging</li><li>Do not fragment packets</li><li>Starting from a custom first TTL hop</li><li>Specifying a gateway for routing packets</li><li>Using ICMP ECHO, TCP SYN, or custom protocol for tracerouting</li><li>Specifying a network interface to operate with</li><li>Setting the max number of hops (max TTL to be reached)</li><li>Adjusting the number of probes to be tried simultaneously</li><li>Disabling IP address resolution to domain names</li><li>Configuring the destination port to use</li><li>Setting the TOS (IPv4 type of service) or TC (IPv6 traffic class) value for outgoing packets</li><li>Using a specified flow_label for IPv6 packets</li><li>Customizing the wait time for a probe response</li><li>Adjusting the number of probes per each hop</li><li>Bypassing normal routing and sending directly to a host on an attached network</li><li>Using a custom source address for outgoing packets</li><li>Setting the minimal time interval between probes</li><li>Showing ICMP extensions (if present), including MPLS</li><li>Performing AS path lookups in routing registries and printing results directly after the corresponding addresses</li><li>Using a specified module (either built-in or external) for traceroute operations</li><li>Applying module-specific options for the traceroute module</li><li>Using a custom source port for outgoing packets</li><li>Setting a firewall mark for outgoing packets</li><li>Using UDP, UDPLITE, DCCP Request, or raw packet for tracerouting with a custom destination port</li><li>Discovering MTU along the path being traced</li><li>Guessing the number of hops in the backward path and printing if it differs</li></ul><h4>Source code:</h4><p>Here is the source code repositories for different traceroute implementations across various platforms. Here’s a summary of the traceroute package sources for Apple, Linux, and OpenBSD. <br>By comparing and analyzing these different implementations, you can gain a deeper understanding of the traceroute command’s functionality and behavior across various operating systems. Additionally, you can learn how each platform has adapted and optimized the tool for its specific requirements and features.</p><ol><li><strong>Apple’s traceroute package sources: <br></strong>Apple’s implementation of the traceroute command can be found in their network_cmds package. The source code is available at:<br><a href="https://opensource.apple.com/source/network_cmds/network_cmds-77/traceroute.tproj/">https://opensource.apple.com/source/network_cmds/network_cmds-77/traceroute.tproj/</a></li><li><strong>Linux traceroute package sources: </strong><br>The traceroute package for Linux is available on SourceForge. This version of traceroute is commonly used on Linux systems and has been developed by Dmitry Butskoy:<br><a href="https://traceroute.sourceforge.net/">https://traceroute.sourceforge.net</a></li><li><strong>OpenBSD’s traceroute package sources: </strong><br>The OpenBSD project has its own implementation of the traceroute command, which can be found in the OpenBSD source repository on GitHub. The source code is available at:<br><a href="https://github.com/openbsd/src/tree/master/usr.sbin/traceroute">https://github.com/openbsd/src/tree/master/usr.sbin/traceroute</a></li></ol><p><strong>In conclusion</strong>, both Traceoute and MTR serve different purposes and cater to various network troubleshooting scenarios. Traceoute is best for simple, one-time analyses, while MTR excels at providing in-depth, real-time information for continuous monitoring. Each tool has an extensive set of options to tailor its functionality to your specific requirements and the network issues you’re looking to diagnose. Happy troubleshooting!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e982065910b9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[mtr — basic usage]]></title>
            <link>https://medium.com/@xakrume/mtr-basic-usage-649cabf37f40?source=rss-43b00e45fce3------2</link>
            <guid isPermaLink="false">https://medium.com/p/649cabf37f40</guid>
            <category><![CDATA[networking]]></category>
            <category><![CDATA[traceroute]]></category>
            <category><![CDATA[ping]]></category>
            <category><![CDATA[mtr]]></category>
            <category><![CDATA[linux]]></category>
            <dc:creator><![CDATA[Ruslan Kh.]]></dc:creator>
            <pubDate>Sun, 09 Apr 2023 15:13:45 GMT</pubDate>
            <atom:updated>2023-04-11T06:37:59.453Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>mtr (M</strong>y TraceRoute<strong>) — usage and practice</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gAcSts0hEYt6_HR9DTH4kg.png" /></figure><p>The <strong>mtr</strong> (My Traceroute) command is a network diagnostic tool that combines the functionality of the <strong>traceroute</strong> and <strong>ping</strong> utilities into a single tool. It is used to trace the route of packets from your system to a remote host, displaying latency and packet loss statistics along the way.</p><p>Here’s a breakdown of the columns in the <strong>mtr</strong> output:</p><ol><li><strong>Hop</strong> (counter in <strong>Host</strong> column): The number of hops on the route from your system to the target host.</li><li><strong>Hostname</strong>: The hostname (or IP address) of the network node at each hop.</li><li><strong>Loss%</strong>: The percentage of packets lost at each hop.</li><li><strong>Snt</strong>: The total number of packets sent at each hop.</li><li><strong>Last</strong>: The latency of the last packet, in milliseconds.</li><li><strong>Avg</strong>: The average latency of all packets sent to this hop, in milliseconds.</li><li><strong>Best</strong>: The lowest (best) latency of all packets sent to the hop, in milliseconds.</li><li><strong>Worst</strong>: The highest (worst) latency of all packets sent to the hop, in milliseconds.</li><li><strong>StDev</strong>: The standard deviation of the latency values for each hop, in milliseconds.</li></ol><p>In the <strong>mtr</strong> output, the “<strong>Loss</strong>” column represents the percentage of packets lost at each hop (network node) along the path. Packet loss is calculated by comparing the number of packets sent to a hop with the number of packets received back from that hop. This information can be useful in identifying problematic network links or nodes that may be causing performance problems.</p><p>By analyzing the “<strong>Loss</strong>” column, you can get an idea of where problems might be occurring in the network path, which can be helpful when troubleshooting or optimizing network performance.</p><p><strong>mtr</strong> is a versatile tool that provides valuable information about the network path between your system and a remote host. Here are some usage examples:</p><ol><li>Basic usage:</li></ol><p>To run <strong>mtr</strong> with default settings, simply specify the target hostname or IP address:</p><pre>mtr example.com</pre><figure><img alt="mtr example.com" src="https://cdn-images-1.medium.com/max/1024/1*gMBbl_870NYbd0tQuZ2iAA.gif" /><figcaption>mtr example.com</figcaption></figure><p>2. Display IP addresses instead of hostnames in the output:</p><p>By default, <strong>mtr</strong> displays hostnames in the output. Use the <strong>-n</strong> option to show IP addresses instead:</p><pre>mtr -n example.com</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kj0QyNRKzur-oLQvwJZdpw.gif" /></figure><p>3. Set the number of pings per hop:</p><p>Use the <strong>-c</strong> option to set the number of pings (ICMP Echo Requests) sent to each hop before <strong>mtr</strong> moves on to the next:</p><pre>mtr -c 20 example.com</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VrlGxJ8rCphe-AkDPIWAuw.gif" /></figure><p>4. Specify the interval between pings:</p><p>Use the <strong>-i</strong> option to set the interval (in seconds) between sending pings to each hop. <em>The default is 1 second</em>:</p><pre>mtr -i 0.5 example.com</pre><figure><img alt="mtr — interval setting example" src="https://cdn-images-1.medium.com/max/1024/1*FXa5pOgzQpF3lKFmhYnMSw.gif" /></figure><p>5. Use TCP or UDP instead of ICMP:</p><p>You can use the <strong>--tcp</strong> or <strong>--udp</strong> options to use TCP or UDP respectively. <em>By default, </em><strong><em>mtr</em></strong><em> uses ICMP for probing</em>:</p><pre>mtr --tcp -P 80 example.com</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y2HMzNLdygMefthoL1A6MQ.gif" /></figure><p>This example will use TCP probes on port 80 (the default HTTP port).</p><p>6. Display the results in another format:</p><p><strong>mtr</strong> supports several output formats, such as JSON, XML, CSV or plain text. Use the <strong>--report</strong> option for a plain text report, or the <strong>--json</strong>, <strong>--xml</strong> or <strong>--csv</strong> options for the corresponding formats:</p><pre>mtr --report example.com</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5bMVHVwtP295fbaQNeCPYg.gif" /></figure><p>7. Save the output to a file:</p><p>You can save the output of <strong>mtr</strong> to a file using shell redirection:</p><pre>mtr --report example.com &gt; ~/mtr_report.txt</pre><p>These examples should help you get started using <strong>mtr</strong> to diagnose network problems and better understand the path between your system and a remote host.</p><h3>Installation.</h3><p>To install <strong>mtr</strong> on various platforms, follow the instructions below:</p><h4>Debian-based Linux distributions (e.g., Ubuntu, Debian, Linux Mint).</h4><p>Open a terminal and run the following command:</p><pre>sudo apt-get update sudo apt-get install mtr</pre><h4>RHEL-based Linux distributions (e.g., Fedora, CentOS, RHEL).</h4><p>Open a terminal and run the following command:</p><pre>sudo yum install mtr -y</pre><p>On newer versions of Fedora, you might need to use `dnf` instead of `yum`:</p><pre>sudo dnf install mtr -y</pre><h4>Arch-based Linux distributions (e.g., Arch Linux, Manjaro).</h4><p>Open a terminal and run the following command:</p><pre>sudo pacman -S mtr</pre><h4>OpenSUSE.</h4><p>Open a terminal and run the following command:</p><pre>sudo zypper install mtr</pre><h4>macOS.</h4><p>If you have <strong>Homebrew</strong> installed, open a terminal and run the following command:</p><pre>brew install mtr</pre><p>If you have <strong>MacPorts</strong> installed, open a terminal and run the following command:</p><pre>sudo port install mtr<br><br>cat &lt;&lt; EOF &gt; ~/.bash_profile<br># fix MTR (MacPorts)<br>export MTR_PACKET=/usr/local/bin<br>EOF</pre><h4>Windows.</h4><p>While <strong>mtr</strong> is not natively available for Windows, you can use a Windows-compatible version called “WinMTR.” You can download it from the following URL <a href="https://sourceforge.net/projects/winmtr/">https://sourceforge.net/projects/winmtr/</a> .</p><p>Download and extract the ZIP file, then run `WinMTR.exe` to use the tool.</p><p>These installation steps should help you get `mtr` up and running on your system. Once installed, you can use it to diagnose and troubleshoot network issues by tracing packet paths and analyzing network performance.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=649cabf37f40" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>