failed to create fsnotify watcher: too many open files

This is quite possibly caused by one of the limits set too low. It is common when using promtail (with Loki for example) to tail log files.

One of the ways to get over this is to increase the value (in this example max_user_instances) either for the session or by making the change permanent by adding to a file (/etc/sysctl.conf).

For testing and doing it for the session, login to the affected server and do the following

ubuntu@server:~$ cat /proc/sys/fs/inotify/max_user_instances 
128
ubuntu@server:~$ sudo sysctl fs.inotify.max_user_instances=8192
fs.inotify.max_user_instances = 8192
ubuntu@server:~$ cat /proc/sys/fs/inotify/max_user_instances 
8192

Convert a single line string ‘a b c’ to a multiple line string with double quotes and commas like [“a”, “b”, “c”] using bash and sed

Problem

You have single line output that contains multiple strings (could be output from a kubectl that gives all the instance names) and you want to convert it to text that can be used as the a variable enclosed by double quotes, one string on one line and separated by commas.

So having the string in a file called input.txt:

a b c

you want to convert it to the following and save it in another file called output.txt

"a",
"b",
"c"


Solution

You can use the following:

cat input.txt | tr ' ' '\n' | sed 's/^/"/g' | sed 's/$/",/g' > output.txt

which will first replace the spaces separating the strings to newlines, and then use two passes with sed, in the first adding the first quote, and the second adding the second quote and the comma.

Flushing dns caching in linux

Problem

You want to update your dns resolution locally after some change in DNS.

You want to do this because your local dns cache still holds the old information about the domain. For example using your local dns and the google one returns two different results

host changed_domain.com
returns the old ip

host changed_domain.com 8.8.8.8
returns the new ip.

Solution

Check your systemd-resolved is active:

sudo systemctl is-active systemd-resolved
active

Get some statistics:

sudo systemd-resolve --statistics

Transactions
Current Transactions: 0
  Total Transactions: 38818

Cache
  Current Cache Size: 73
          Cache Hits: 21120
        Cache Misses: 19745

DNSSEC Verdicts
              Secure: 0
            Insecure: 0
               Bogus: 0
       Indeterminate: 0

Flush the cache (make the Current Cache Size above 0)

sudo systemd-resolve --flush-caches

Check the cache again (should be 0 now):

sudo systemd-resolve --statistics

ransactions
Current Transactions: 0
  Total Transactions: 38818

Cache
  Current Cache Size: 0
          Cache Hits: 21120
        Cache Misses: 19745

DNSSEC Verdicts
              Secure: 0
            Insecure: 0
               Bogus: 0
       Indeterminate: 0

Information taken from https://www.techrepublic.com/article/how-to-flush-the-dns-cache-on-linux/