Packages
prom_ex
0.1.5-alpha
1.12.0
1.11.0
1.10.0
1.9.0
1.8.0
1.7.1
1.7.0
retired
1.6.0
1.5.0
1.4.1
1.4.0
1.3.0
1.2.2
1.2.1
1.2.0
1.1.1
1.1.0
1.0.1
1.0.0
0.1.15-beta
0.1.14-beta
0.1.13-beta
0.1.12-beta
0.1.11-alpha
0.1.10-alpha
0.1.9-alpha
0.1.8-alpha
0.1.7-alpha
0.1.6-alpha
0.1.5-alpha
0.1.4-alpha
0.1.3-alpha
0.1.2-alpha
0.1.1-alpha
0.1.0-alpha
Prometheus metrics and Grafana dashboards for all of your favorite Elixir libraries
Current section
Files
Jump to
Current section
Files
lib/mix/tasks/prom_ex.gen.config.ex
defmodule Mix.Tasks.PromEx.Gen.Config do
@moduledoc """
This will generate a PromEx config
"""
use Mix.Task
alias Mix.Project
alias Mix.Shell.IO
@impl true
def run(_args) do
Mix.Task.run("compile")
app_priv_dir =
Project.config()
|> Keyword.get(:app)
|> :code.priv_dir()
|> :erlang.list_to_binary()
grafana_dashboards_dir = Path.join([app_priv_dir, "grafana_dashboards"])
unless File.exists?(grafana_dashboards_dir) do
IO.info("Creating Grafana dashboards directory")
File.mkdir(grafana_dashboards_dir)
end
prom_ex_config_file = Path.join([grafana_dashboards_dir, ".prom_ex.exs"])
create_file =
if File.exists?(prom_ex_config_file) do
IO.yes?("An existing PromEx config file already exists. Overwrite?")
else
true
end
if create_file do
create_config_file(prom_ex_config_file)
IO.info("Successfully Created .prom_ex.exs config file")
else
IO.info("Did not create .prom_ex.exs file")
end
end
defp create_config_file(path) do
path
|> File.write!("""
%{
# The ID of the Prometheus datasource in your Grafana instance
grafana_host: "",
grafana_auth_token: "",
grafana_datasource_id: "prometheus",
# Dashboard that will be uploaded when running dashboard uploads
dashboards: [
# PromEx built in dashboard definitions. Remove dashboards that you do not need
{:prom_ex, "/grafana_dashboards/application.json"},
{:prom_ex, "/grafana_dashboards/beam.json"},
{:prom_ex, "/grafana_dashboards/phoenix.json"}
# Add your dashboard definitions here
# {:my_app, "/grafana_dashboards/business_related_metrics.json"}
]
}
""")
end
end