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.

OvermindDL1

OvermindDL1

Hmm, put echo before your iex --name "${observer_node_name}" --cookie "${node_cookie}" -e "${node_connect}" -e ":observer.start()" line to become echo iex --name "${observer_node_name}" --cookie "${node_cookie}" -e "${node_connect}" -e ":observer.start()" and see what it prints out and if everything is appearing properly interpolated and matching your working line (excepting "'s and so forth of course)? Are you sure the shell is not interpolating out your "'s in the :"node_name@blah" part and so forth? I don’t quite remember the rules of bash in interpolation but I know the way it interpolates is rather broken so it wouldn’t surprise me (I use ZSH, which is basically bash done right, though I keep my scripts to full posix shell mode regardless).

Exadra37

Exadra37

Well the weird part is that if I put the command in a bash script with a variable to replace the node connect bit it will not work, but works fine if is only plain text…

#!/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
  ##############################################################################

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

    # DOES NOT CONNECT THE NODE: -e "${node_connect}"
    iex --name "${observer_node_name}"  --cookie "${node_cookie}" -e "${node_connect}" -e ":observer.start()"

    # BUT THIS WORKS FINE FROM INSIDE THIS SCRIPT OR EXECUTED DIRECTLY FROM A TERMINAL
    iex --name 'observer@172.24.0.3'  --cookie 'super-long-secret-cookie' -e 'Node.connect(:"node_name@172.24.0.2")' -e ":observer.start()"
}

Main "${@}"

Where Next?

Popular in Questions Top

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
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
idi527
I’ve been re-reading swift book again and noticed that multiline strings there don’t have a trailing line break, unlike in elixir iex(2)...
New

Other popular topics Top

peerreynders
Manning 2016 Halloween weekend sale via Deal of the Day Friday, October 28 - Half off all MEAPs - code WM102816LT Saturday, October 29 ...
326 29600 154
New
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
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
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 42633 214
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
273 38985 115
New

We're in Beta

About us Mission Statement