Exadra37

Exadra37

Is possible to use Observer with multiple applications?

I am playing around with Observer, and I am able to connect to any application I have running on the same docker network.

I start the application from each docker container like:

elixir --cookie super-long-secret-cookie --sname app1 -S mix phoenix.server

and I start the observer from another docker container with:

erl -sname observer -hidden -setcookie super-long-secret-cookie  -run observer

In the Observer GUI interface I am able to connect to app1 and app2 without any problem, and see them working as expected, but each time I need to swap between app1 and app2 I need to reenter the de node details to reconnect, because in the Nodes menu it does not keep a list of all apps I am connecting to during the current session…

So my expectation is to see a list of all nodes I have already connected to, and be able to click in any to reconnect to it, but as we can see in the image I only have the observer node itself, and none of the nodes of the app I have already connected to in this Observer session… is this the actual behavior of Observer or is just me having an issue with it?

Marked As Solved

Exadra37

Exadra37

Bingo you found it… It was splinting the command into a new line… I was not able to found how the string end ups with the new line, but I fixed it before I build the command with:

# REMOVING UNWANTED STUFF
    local app_node_name="$(echo ${app_node_name} | tr -d '\n\r\t')"

So the full working script is now:

#!/bin/bash

set -eu

Main()
{
  ##############################################################################
  # INPUT
  ##############################################################################

    if [ "$#" -ge 1 ]; then
        local node_name="${1? Missing node name!!!}"
        local node_address="${2? Missing node address!!!}"
        local node_cookie="${3? Missing node cookie!!!}"

        local app_node_name="${node_name}@${node_address}"
    else
        # GET FROM ENVIRONMENT WHEN NO ARGUMENTS ARE PASSED TO THE SCRIPT
        app_node_name="${APP_NODE_NAME}"
        node_cookie="${APP_NODE_COOKIE}"
    fi

    local observer_node_name="observer@$(hostname -i)"


  ##############################################################################
  # EXECUTION
  ##############################################################################

    # REMOVING UNWANTED STUFF
    local app_node_name="$(echo ${app_node_name} | tr -d '\n\r\t')"

    local node_connect="Node.connect(:\"${app_node_name}\")"

    iex --name "${observer_node_name}"  --cookie "${node_cookie}" -e "${node_connect}" -e ":observer.start()"

}

Main "${@}"

My default shell is also zsh with oh-my-zsh plugin, but scripting I do in sh by default and resort to bash only when I really need a bash-ism :wink:

Also Liked

Exadra37

Exadra37

I found the solution…

I was starting Observer with the Erlang shell instead of the Elixir shell.

So instead of using:

erl -sname observer -hidden -setcookie super-long-secret-cookie  -run observer

I need to use:

iex --sname observeriex --cookie super-long-secret-cookie -e ":observer.start"
OvermindDL1

OvermindDL1

Actually it was because you were using -hidden on the initial call, that means it doesn’t join the BEAM mesh (so you only see the thing you explicitly named and nothing else) but rather only joins that specific node. :slight_smile:

Exadra37

Exadra37

Thanks to point it out… I indeed forgot to connect to the node…

So the correct command is indeed:

iex --name 'observer@172.24.0.3'  --cookie 'super-long-secret-cookie' -e 'Node.connect(:"node_name@172.24.0.2")' -e ":observer.start()"

I am still learning all this stuff, and at same toime building a Docker stack for development in Elixir with all the tooling available.

Last Post!

OvermindDL1

OvermindDL1

That’s saving to a file though, which would have a newline. The thing about a variable in bash/zsh is that it doesn’t keep the newline because newlines are part of $IFS (well, unless you changed $IFS, which would break a lot of things), so I’m still thinking a " is in use somewhere where it shouldn’t be (which inhibits the this)?

For note though, replacing a newline via calling another program can be slow in a loop, so you’d probably want to use shell-string-replacement instead (like NR='\r' then %{blahvar%$NL}), but if not in a tight loop it doesn’t matter. ^.^

Still though:

╰─➤  BLAH=$(hostname -i) 

╰─➤  printf ">${BLAH}<"
>127.0.1.1<% 

╰─➤  printf ">${BLAH}<\n"
>127.0.1.1<

# Now of course streaming the variable into a program will include the newline:
╰─➤  wc <<< "$BLAH"
 1  1 10

# But passing it as an argument will not:
╰─➤  perl -e 'print $ARGV[0]; print " -> "; print length($ARGV[0])' $BLAH
127.0.1.1 -> 9%

╰─➤  python3 -c 'import sys; print(repr(sys.argv)); print(len(sys.argv[1]))' $BLAH
['-c', '127.0.1.1']
9

╰─➤  elixir -e 'System.argv() |> IO.inspect(); System.argv() |> hd() |> String.length() |> IO.inspect()' $BLAH
["127.0.1.1"]
9

So I think I’m still not seeing enough of your script to see the issue, like where and how the ENV_VAR is used… ^.^;

Where Next?

Popular in Questions Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New

Other popular topics Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement