Fl4m3Ph03n1x

Fl4m3Ph03n1x

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?

First 3 of 3 Posts Switch mode

peerreynders

peerreynders

The documentation states that the default is 1 minute (60000 ms). Is that incorrect?

Fl4m3Ph03n1x

Fl4m3Ph03n1x OP

Oops, you are correct. This a a confusion from my part. Turns out I forgot that memsup.get_check_interval/0 which returns in ms:

:memsup.get_check_interval()
60000

Converts to minutes like the following: :memsup.get_check_interval() /1000 / 60. I had forgotten the /60 part, my bad.

Still, now I have to know. How would I configure this in my mix.exs (lets say I want every 5 minutes)?

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.

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
rahultumpala
Hello, I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

We're in Beta

About us Mission Statement