This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MyAws.Metadata | |
# AWS InstanceMetaData URL | |
@meta_path_region "http://169.254.169.254/latest/meta-data/placement/availability-zone" | |
@region_regexp ~r/(?<continent>eu|us)-(?<zone>[^-]+)-(?<number>[\d]+)/i | |
@doc """ | |
Get aws region. | |
First, it tries with :some_app, :aws_region variable stablished in config (hopefuly using env vars), and if no | |
it assumes the code is running in an ec2 instance, so it tries to get the region from instance metadata. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule XmlEventHandler do | |
@moduledoc """ | |
Module to parse xml with lists of items based on events | |
""" | |
@behaviour Saxy.Handler | |
@type element :: %{ | |
name: binary, | |
attributes: [{binary, binary}], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule XmlStreamer do | |
defp to_elements_stream(xml_stream) do | |
{:ok, partial} = Saxy.Partial.new(XmlEventHandler) | |
Stream.chunk_while(xml_stream, partial, &maybe_items/2, &finalize/1) | |
end | |
defp maybe_items(chunk, partial) do | |
with {:cont, partial} <- Saxy.Partial.parse(partial, chunk), | |
{:ok, partial, items} <- fetch_items(partial) do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MemoryMonitor do | |
@moduledoc """ | |
This module implements a GenServer that monitors the memory usage of a process. | |
It periodically checks the memory consumption. | |
""" | |
use GenServer | |
@time_to_check :timer.seconds(10) |