<commit_before>defmodule CerebrateCollector do
  def start_link() do
    {:ok, [[listen_port]]} = Erlang.init.get_argument(:port)
    args = [Erlang.erlang.list_to_integer(listen_port)]
    pid = spawn CerebrateCollector, :start, args
    {:ok, pid}
  end

  def start(listen_port) do
    Erlang.dnssd.register "Cerebrate-#{listen_port}", "_cerebrate._udp", listen_port
    receive do
    match: {:dnssd, ref, {:register, :add, result}} 
      IO.puts "Registered #{inspect(result)}"
    match: {:dnssd, ref, {:register, :remove, result}}
      IO.puts "Unexpected remove result: #{inspect(result)}"
    end
    run Erlang.dict.store(:start_time, Erlang.now(), Erlang.dict.new())
  end

  def run(state) do
    IO.inspect CerebrateChecks.all()
    :ok = Erlang.timer.sleep 1000
    run state
  end
end


defmodule CerebrateChecks do
  def all() do
    loadavg()
  end
<commit_msg>let other processes query the collector for check data<commit_after>defmodule CerebrateCollector do
  def start_link() do
    {:ok, [[listen_port]]} = Erlang.init.get_argument(:port)
    args = [Erlang.erlang.list_to_integer(listen_port)]
    pid = spawn CerebrateCollector, :start, args
    Process.register :collector, pid
    {:ok, pid}
  end

  def start(listen_port) do
    Erlang.dnssd.register "Cerebrate-#{listen_port}", "_cerebrate._udp", listen_port
    receive do
    match: {:dnssd, ref, {:register, :add, result}} 
      IO.puts "Registered #{inspect(result)}"
    match: {:dnssd, ref, {:register, :remove, result}}
      IO.puts "Unexpected remove result: #{inspect(result)}"
    end
    run Erlang.dict.store(:start_time, Erlang.now(), Erlang.dict.new())
  end

  def run(state) do
    check_data = CerebrateChecks.all()
    IO.inspect check_data
    receive do
    match: {:query, caller}
      caller <- check_data
    after: 1000
      IO.puts "No calls after 1000ms"
    end
    run state
  end
end


defmodule CerebrateChecks do
  def all() do
    loadavg()
  end

{'fraction_non_alphanumeric': 0.12576374745417515, 'fraction_numerical': 0.006109979633401222, 'mean_word_length': 3.548611111111111, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '886683', 'n_tokens_mistral': 726, 'n_tokens_neox': 687, 'n_words': 173}