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.