i need help on implementing metric-dashboard for distribution metrics,
checked live_dashboard but live_dashboard not supporting distribution at the movement
i’m a new joinee to my team and fairly new to Elixir
i tasked to develop distribution metric-dashboard
data coming from TelemetryMetricsPrometheus.Core at /metrics
endpoint
i’m thinking to parse metrics data into maps or list and use some UI library to represent
- what is the best UI library to represent distribution metrics?
- what type of data structure these libraries need? if i wanted to parse data into some structure(maps, list, keyword-list)
- are there any examples to take references?
currently i’m trying this to parse data its half baked code though
i’m doing this on livebbok
defmodule P do
def data_within_curl(labels) do
labels
|> remove_string(~r/"/)
|> String.split(",")
|> Enum.reduce(%{}, fn match, acc ->
[key, val] = String.split(match, "=")
Map.put(acc, key, val)
end)
end
def remove_string(str, regex, replacement \\ "") do
Regex.replace(regex, str, replacement)
end
def check_for_help?(content), do: String.match?(content, ~r/HELP/)
def check_for_type?(content), do: String.match?(content, ~r/TYPE/)
def check_for_curly?(content), do: String.match?(content, ~r/{|}/)
def check_for_no_curly?(content), do: !String.match?(content, ~r/{|}/)
end
"""
# HELP app_name_self_repair_duration
# TYPE app_name_self_repair_duration gauge
app_name_self_repair_duration 0.15916584
# HELP app_name_db_duration
# TYPE app_name_db_duration histogram
app_name_db_duration_bucket{query="get_transaction",le="0.01"} 179807
app_name_db_duration_bucket{query="get_transaction",le="0.025"} 180397
app_name_db_duration_bucket{query="get_transaction",le="0.05"} 183557
app_name_db_duration_bucket{query="get_transaction",le="0.1"} 188560
app_name_db_duration_bucket{query="get_transaction",le="0.3"} 188692
app_name_db_duration_bucket{query="get_transaction",le="0.5"} 188695
app_name_db_duration_bucket{query="get_transaction",le="0.8"} 188695
app_name_db_duration_bucket{query="get_transaction",le="1"} 188695
app_name_db_duration_bucket{query="get_transaction",le="1.5"} 188695
app_name_db_duration_bucket{query="get_transaction",le="+Inf"} 188695
app_name_db_duration_sum{query="get_transaction"} 555.663747302
app_name_db_duration_count{query="get_transaction"} 188695
"""
|> String.split("\n")
|> Enum.reduce(%{}, fn line, acc ->
IO.puts(line)
IO.inspect(acc, label: "acc-map")
cond do
P.check_for_help?(line) ->
acc
P.check_for_type?(line) ->
[_, _, metric_name, type] = Regex.run(~r/(.*\s)(.*\s)(.*)/, line)
trim_trailing = String.trim_trailing(metric_name)
new_metric = Enum.join([trim_trailing, type], "_")
IO.puts(new_metric)
Map.update(acc, new_metric, [], fn val -> IO.puts(val) end)
P.check_for_curly?(line) ->
[_, metric_name, labels, value] = Regex.run(~r/(.*){(.*)}(.*)/, line)
labels_data = P.data_within_curl(labels)
IO.inspect(labels_data, label: "labels_data")
bucket_map = Map.merge(labels_data, %{"value" => value})
IO.inspect(bucket_map, label: "with curly")
Map.put_new(acc, metric_name, bucket_map)
P.check_for_no_curly?(line) ->
[_, metric_name, value] = Regex.run(~r/(.*\s)(.*)/, line)
Map.put_new(acc, metric_name, %{"value" => value})
IO.inspect(value, label: "no curly")
end
end)
any help or suggestions are greatly appreciated
thank you