Skip to content

Commit 26423e0

Browse files
committed
Code for step 1
0 parents  commit 26423e0

37 files changed

+1093
-0
lines changed

.formatter.exs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[
2+
import_deps: [:ecto, :phoenix],
3+
inputs: ["*.{ex,exs}", "priv/*/seeds.exs", "{config,lib,test}/**/*.{ex,exs}"],
4+
subdirectories: ["priv/*/migrations"]
5+
]

.gitignore

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# The directory Mix will write compiled artifacts to.
2+
/_build/
3+
4+
# If you run "mix test --cover", coverage assets end up here.
5+
/cover/
6+
7+
# The directory Mix downloads your dependencies sources to.
8+
/deps/
9+
10+
# Where 3rd-party dependencies like ExDoc output generated docs.
11+
/doc/
12+
13+
# Ignore .fetch files in case you like to edit your project deps locally.
14+
/.fetch
15+
16+
# If the VM crashes, it generates a dump, let's ignore it too.
17+
erl_crash.dump
18+
19+
# Also ignore archive artifacts (built via "mix archive.build").
20+
*.ez
21+
22+
# Ignore package tarball (built via "mix hex.build").
23+
elixir_monitoring_prom-*.tar
24+
25+
# Since we are building assets from assets/,
26+
# we ignore priv/static. You may want to comment
27+
# this depending on your deployment strategy.
28+
/priv/static/

README.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# ElixirMonitoringProm
2+
3+
To start your Phoenix server:
4+
5+
* Install dependencies with `mix deps.get`
6+
* Create and migrate your database with `mix ecto.setup`
7+
* Start Phoenix endpoint with `mix phx.server`
8+
9+
Now you can visit [`localhost:4000`](http://localhost:4000) from your browser.
10+
11+
Ready to run in production? Please [check our deployment guides](https://hexdocs.pm/phoenix/deployment.html).
12+
13+
## Learn more
14+
15+
* Official website: http://www.phoenixframework.org/
16+
* Guides: https://hexdocs.pm/phoenix/overview.html
17+
* Docs: https://hexdocs.pm/phoenix
18+
* Mailing list: http://groups.google.com/group/phoenix-talk
19+
* Source: https://github.com/phoenixframework/phoenix

config/config.exs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# This file is responsible for configuring your application
2+
# and its dependencies with the aid of the Mix.Config module.
3+
#
4+
# This configuration file is loaded before any dependency and
5+
# is restricted to this project.
6+
7+
# General application configuration
8+
use Mix.Config
9+
10+
config :elixir_monitoring_prom,
11+
ecto_repos: [ElixirMonitoringProm.Repo]
12+
13+
# Configures the endpoint
14+
config :elixir_monitoring_prom, ElixirMonitoringPromWeb.Endpoint,
15+
url: [host: "localhost"],
16+
secret_key_base: "nFSyXdlKCXuXTXWhnmEeVnA9VLzzbpuqX3UvpdaPo8uqpgjxd+cZorH+0GobASx8",
17+
render_errors: [view: ElixirMonitoringPromWeb.ErrorView, accepts: ~w(html json)],
18+
pubsub: [name: ElixirMonitoringProm.PubSub, adapter: Phoenix.PubSub.PG2]
19+
20+
# Configures Elixir's Logger
21+
config :logger, :console,
22+
format: "$time $metadata[$level] $message\n",
23+
metadata: [:request_id]
24+
25+
# Use Jason for JSON parsing in Phoenix
26+
config :phoenix, :json_library, Jason
27+
28+
# Import environment specific config. This must remain at the bottom
29+
# of this file so it overrides the configuration defined above.
30+
import_config "#{Mix.env()}.exs"

config/dev.exs

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
use Mix.Config
2+
3+
# Configure your database
4+
config :elixir_monitoring_prom, ElixirMonitoringProm.Repo,
5+
username: "postgres",
6+
password: "postgres",
7+
database: "elixir_monitoring_prom_dev",
8+
hostname: "localhost",
9+
show_sensitive_data_on_connection_error: true,
10+
pool_size: 10
11+
12+
# For development, we disable any cache and enable
13+
# debugging and code reloading.
14+
#
15+
# The watchers configuration can be used to run external
16+
# watchers to your application. For example, we use it
17+
# with webpack to recompile .js and .css sources.
18+
config :elixir_monitoring_prom, ElixirMonitoringPromWeb.Endpoint,
19+
http: [port: 4000],
20+
debug_errors: true,
21+
code_reloader: true,
22+
check_origin: false,
23+
watchers: []
24+
25+
# ## SSL Support
26+
#
27+
# In order to use HTTPS in development, a self-signed
28+
# certificate can be generated by running the following
29+
# Mix task:
30+
#
31+
# mix phx.gen.cert
32+
#
33+
# Note that this task requires Erlang/OTP 20 or later.
34+
# Run `mix help phx.gen.cert` for more information.
35+
#
36+
# The `http:` config above can be replaced with:
37+
#
38+
# https: [
39+
# port: 4001,
40+
# cipher_suite: :strong,
41+
# keyfile: "priv/cert/selfsigned_key.pem",
42+
# certfile: "priv/cert/selfsigned.pem"
43+
# ],
44+
#
45+
# If desired, both `http:` and `https:` keys can be
46+
# configured to run both http and https servers on
47+
# different ports.
48+
49+
# Watch static and templates for browser reloading.
50+
config :elixir_monitoring_prom, ElixirMonitoringPromWeb.Endpoint,
51+
live_reload: [
52+
patterns: [
53+
~r"priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$",
54+
~r"priv/gettext/.*(po)$",
55+
~r"lib/elixir_monitoring_prom_web/{live,views}/.*(ex)$",
56+
~r"lib/elixir_monitoring_prom_web/templates/.*(eex)$"
57+
]
58+
]
59+
60+
# Do not include metadata nor timestamps in development logs
61+
config :logger, :console, format: "[$level] $message\n"
62+
63+
# Set a higher stacktrace during development. Avoid configuring such
64+
# in production as building large stacktraces may be expensive.
65+
config :phoenix, :stacktrace_depth, 20
66+
67+
# Initialize plugs at runtime for faster development compilation
68+
config :phoenix, :plug_init_mode, :runtime

config/prod.exs

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
use Mix.Config
2+
3+
# For production, don't forget to configure the url host
4+
# to something meaningful, Phoenix uses this information
5+
# when generating URLs.
6+
#
7+
# Note we also include the path to a cache manifest
8+
# containing the digested version of static files. This
9+
# manifest is generated by the `mix phx.digest` task,
10+
# which you should run after static files are built and
11+
# before starting your production server.
12+
config :elixir_monitoring_prom, ElixirMonitoringPromWeb.Endpoint,
13+
url: [host: "example.com", port: 80],
14+
cache_static_manifest: "priv/static/cache_manifest.json"
15+
16+
# Do not print debug messages in production
17+
config :logger, level: :info
18+
19+
# ## SSL Support
20+
#
21+
# To get SSL working, you will need to add the `https` key
22+
# to the previous section and set your `:url` port to 443:
23+
#
24+
# config :elixir_monitoring_prom, ElixirMonitoringPromWeb.Endpoint,
25+
# ...
26+
# url: [host: "example.com", port: 443],
27+
# https: [
28+
# :inet6,
29+
# port: 443,
30+
# cipher_suite: :strong,
31+
# keyfile: System.get_env("SOME_APP_SSL_KEY_PATH"),
32+
# certfile: System.get_env("SOME_APP_SSL_CERT_PATH")
33+
# ]
34+
#
35+
# The `cipher_suite` is set to `:strong` to support only the
36+
# latest and more secure SSL ciphers. This means old browsers
37+
# and clients may not be supported. You can set it to
38+
# `:compatible` for wider support.
39+
#
40+
# `:keyfile` and `:certfile` expect an absolute path to the key
41+
# and cert in disk or a relative path inside priv, for example
42+
# "priv/ssl/server.key". For all supported SSL configuration
43+
# options, see https://hexdocs.pm/plug/Plug.SSL.html#configure/1
44+
#
45+
# We also recommend setting `force_ssl` in your endpoint, ensuring
46+
# no data is ever sent via http, always redirecting to https:
47+
#
48+
# config :elixir_monitoring_prom, ElixirMonitoringPromWeb.Endpoint,
49+
# force_ssl: [hsts: true]
50+
#
51+
# Check `Plug.SSL` for all available options in `force_ssl`.
52+
53+
# Finally import the config/prod.secret.exs which loads secrets
54+
# and configuration from environment variables.
55+
import_config "prod.secret.exs"

config/prod.secret.exs

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# In this file, we load production configuration and secrets
2+
# from environment variables. You can also hardcode secrets,
3+
# although such is generally not recommended and you have to
4+
# remember to add this file to your .gitignore.
5+
use Mix.Config
6+
7+
database_url =
8+
System.get_env("DATABASE_URL") ||
9+
raise """
10+
environment variable DATABASE_URL is missing.
11+
For example: ecto://USER:PASS@HOST/DATABASE
12+
"""
13+
14+
config :elixir_monitoring_prom, ElixirMonitoringProm.Repo,
15+
# ssl: true,
16+
url: database_url,
17+
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10")
18+
19+
secret_key_base =
20+
System.get_env("SECRET_KEY_BASE") ||
21+
raise """
22+
environment variable SECRET_KEY_BASE is missing.
23+
You can generate one by calling: mix phx.gen.secret
24+
"""
25+
26+
config :elixir_monitoring_prom, ElixirMonitoringPromWeb.Endpoint,
27+
http: [:inet6, port: String.to_integer(System.get_env("PORT") || "4000")],
28+
secret_key_base: secret_key_base
29+
30+
# ## Using releases (Elixir v1.9+)
31+
#
32+
# If you are doing OTP releases, you need to instruct Phoenix
33+
# to start each relevant endpoint:
34+
#
35+
# config :elixir_monitoring_prom, ElixirMonitoringPromWeb.Endpoint, server: true
36+
#
37+
# Then you can assemble a release by calling `mix release`.
38+
# See `mix help release` for more information.

config/test.exs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use Mix.Config
2+
3+
# Configure your database
4+
config :elixir_monitoring_prom, ElixirMonitoringProm.Repo,
5+
username: "postgres",
6+
password: "postgres",
7+
database: "elixir_monitoring_prom_test",
8+
hostname: "localhost",
9+
pool: Ecto.Adapters.SQL.Sandbox
10+
11+
# We don't run a server during test. If one is required,
12+
# you can enable the server option below.
13+
config :elixir_monitoring_prom, ElixirMonitoringPromWeb.Endpoint,
14+
http: [port: 4002],
15+
server: false
16+
17+
# Print only warnings and errors during test
18+
config :logger, level: :warn

lib/elixir_monitoring_prom.ex

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
defmodule ElixirMonitoringProm do
2+
@moduledoc """
3+
ElixirMonitoringProm keeps the contexts that define your domain
4+
and business logic.
5+
6+
Contexts are also responsible for managing your data, regardless
7+
if it comes from the database, an external API or others.
8+
"""
9+
end
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
defmodule ElixirMonitoringProm.Application do
2+
# See https://hexdocs.pm/elixir/Application.html
3+
# for more information on OTP Applications
4+
@moduledoc false
5+
6+
use Application
7+
8+
def start(_type, _args) do
9+
# List all child processes to be supervised
10+
children = [
11+
# Start the Ecto repository
12+
ElixirMonitoringProm.Repo,
13+
# Start the endpoint when the application starts
14+
ElixirMonitoringPromWeb.Endpoint
15+
# Starts a worker by calling: ElixirMonitoringProm.Worker.start_link(arg)
16+
# {ElixirMonitoringProm.Worker, arg},
17+
]
18+
19+
# See https://hexdocs.pm/elixir/Supervisor.html
20+
# for other strategies and supported options
21+
opts = [strategy: :one_for_one, name: ElixirMonitoringProm.Supervisor]
22+
Supervisor.start_link(children, opts)
23+
end
24+
25+
# Tell Phoenix to update the endpoint configuration
26+
# whenever the application is updated.
27+
def config_change(changed, _new, removed) do
28+
ElixirMonitoringPromWeb.Endpoint.config_change(changed, removed)
29+
:ok
30+
end
31+
end

lib/elixir_monitoring_prom/repo.ex

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
defmodule ElixirMonitoringProm.Repo do
2+
use Ecto.Repo,
3+
otp_app: :elixir_monitoring_prom,
4+
adapter: Ecto.Adapters.Postgres
5+
end

lib/elixir_monitoring_prom_web.ex

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
defmodule ElixirMonitoringPromWeb do
2+
@moduledoc """
3+
The entrypoint for defining your web interface, such
4+
as controllers, views, channels and so on.
5+
6+
This can be used in your application as:
7+
8+
use ElixirMonitoringPromWeb, :controller
9+
use ElixirMonitoringPromWeb, :view
10+
11+
The definitions below will be executed for every view,
12+
controller, etc, so keep them short and clean, focused
13+
on imports, uses and aliases.
14+
15+
Do NOT define functions inside the quoted expressions
16+
below. Instead, define any helper function in modules
17+
and import those modules here.
18+
"""
19+
20+
def controller do
21+
quote do
22+
use Phoenix.Controller, namespace: ElixirMonitoringPromWeb
23+
24+
import Plug.Conn
25+
import ElixirMonitoringPromWeb.Gettext
26+
alias ElixirMonitoringPromWeb.Router.Helpers, as: Routes
27+
end
28+
end
29+
30+
def view do
31+
quote do
32+
use Phoenix.View,
33+
root: "lib/elixir_monitoring_prom_web/templates",
34+
namespace: ElixirMonitoringPromWeb
35+
36+
# Import convenience functions from controllers
37+
import Phoenix.Controller, only: [get_flash: 1, get_flash: 2, view_module: 1]
38+
39+
# Use all HTML functionality (forms, tags, etc)
40+
use Phoenix.HTML
41+
42+
import ElixirMonitoringPromWeb.ErrorHelpers
43+
import ElixirMonitoringPromWeb.Gettext
44+
alias ElixirMonitoringPromWeb.Router.Helpers, as: Routes
45+
end
46+
end
47+
48+
def router do
49+
quote do
50+
use Phoenix.Router
51+
import Plug.Conn
52+
import Phoenix.Controller
53+
end
54+
end
55+
56+
def channel do
57+
quote do
58+
use Phoenix.Channel
59+
import ElixirMonitoringPromWeb.Gettext
60+
end
61+
end
62+
63+
@doc """
64+
When used, dispatch to the appropriate controller/view/etc.
65+
"""
66+
defmacro __using__(which) when is_atom(which) do
67+
apply(__MODULE__, which, [])
68+
end
69+
end

0 commit comments

Comments
 (0)