Fl4m3Ph03n1x

Fl4m3Ph03n1x

How to configure extra_application in elixir?

Background

I have an app that checks the machine’s memory usage using :memsup.get_memory_data/0 before proceeding with an operation. If said memory usage is too high, I just refuse to do the operation.

Problem

Now, according to the documentation, :memsup.get_memory_data asks the machine how much memory it has allocated every X time. By default X is 60 minutes. This is wwaaaayyy too long.

There is a way to configure it using :memsup.set_check_interval/1 but the new interval I pass only takes effect after the first check, so it means that if I start the app and then use :memsup.set_check_interval(1) to check the memory every minute, I will have to wait 60 minutes before I start checking the memory every minute like I want. What’s even worst, is that if the application or process is restarted, I go back to waiting 60 minutes again because any changes using this function are not persisted.

Code

So in order to use :memsup you need to include os_mon into your extra_applications mix.exs file:


  def application do
    [
      extra_applications: [:logger, :runtime_tools, :os_mon],
      mod: {MyApp.Application, []}
    ]
  end

However, this doesn’t tell me how I can configure the os_mon app, and reading the erlang documentation lead me to this config page which only confused me further.

I was hopping to see something simple, like changing my config.exs file but I found no information regarding it.

Question

How do I configure os_mon on startup, so its memory check interval is 1 minute instead of 60?

Marked As Solved

peerreynders

peerreynders

Don’t know.

As far as I can tell sys.config would need something like

{os_mon, [{memory_check_interval, 5}]}

So according to this

config :os_mon,
  memory_check_interval: 5

via the config.exs (or any file it references).

At least that would be my starting point …


In any case - the fact that set_check_interval/1 takes minutes but get_check_interval/0 returns ms is confusing.

Where Next?

Popular in Questions Top

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
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
earth10
Hi, I’m just starting to build a side-project with Elixir and Phoenix and doing some basic test with Elixir alone. What strikes me is th...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> somethi...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
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 t...
New

Other popular topics Top

Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39297 209
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
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
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 126479 1222
New

We're in Beta

About us Mission Statement