mrclumsy

mrclumsy

I’ve just started learning elixir and phoenix and am exploring telemetry and all that it’s capable off. So far I’ve followed the phoenix docs and some blog posts. I’ve set up a simple application to mimic a book store. There’s one table called Books and it holds information about author, genre, title, price etc.

A lot of the reference material I’ve looked at talks about sending information like query execution time as metrics and that’s super useful. As a learning exercise I’m trying to also send something like the max, min and avg price per genre. I’d like to view this information in Live Dashboard if possible.

The majority of my progress so far was made by first taking the steps outlined in the docs, and then by following this blog post to customise even further.

Here is my setup so far. I hope I’ve provided enough details!

lib/books_api/metrics_generator.ex

  def handle_info(:work, state) do
    books = BooksApi.Store.list_books()

    :telemetry.execute([:books_api, :work],
      %{
        duration: Enum.random(0..10),
        books: books
      }
    )

    schedule_work()

    {:noreply, state}
  end

lib/books_api/store.ex

  def list_books do
    Repo.all(Book)
  end

lib/books_api/application.ex

  def start(_type, _args) do
    children = [
      # Start the Ecto repository
      BooksApi.Repo,
      # Start the Telemetry supervisor
      BooksApiWeb.Telemetry,
      # Start the PubSub system
      {Phoenix.PubSub, name: BooksApi.PubSub},
      # Start the Endpoint (http/https)
      BooksApiWeb.Endpoint,
      # Start a worker by calling: BooksApi.Worker.start_link(arg)
      # {BooksApi.Worker, arg}
      BooksApi.MetricsGenerator
    ]

    # See https://hexdocs.pm/elixir/Supervisor.html
    # for other strategies and supported options
    opts = [strategy: :one_for_one, name: BooksApi.Supervisor]
    Supervisor.start_link(children, opts)
  end

lib/books_api_web/telemetry.ex

  def metrics do
    [
 
      .....

      # Custom Metrics
      summary("books_api.work.books")
    ]
  end

When I visit http://localhost:4000/dashboard/metrics?nav=books_api I can see all the default metrics that come with phoenix but nothing for books_api.work.books

I think this is because summary/2 can’t parse the list returned by BooksApi.Store.list_books but I’m struggling to figure out how to format the data so that summary/2 can provide max, min and avg information price and also split that by genre.

Have I missed a step (or ten) or is what I’m attempting not within the scope of what telemetry metrics were intended for?

Showing Posts 1 to 4

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

I don’t think what you’re attempting is within the scope of telemetry metrics. Telemetry metrics is about reporting measurement information about the performance of your application, it isn’t about providing information about data in your database. That is to say, Telemetry exists to tell you how long your queries are taking, but not tell you how many rows are in the tables or what those rows contain.

What you’re looking for is more like a “Business Intelligence” (BI) tool that lets you explore data in your database and derive metrics, visualizations, and so forth about the data contained therein.

kartheek

kartheek

Telemetry events are sent to storage using a collector. All this data ends up in some sort of time series database. Once in time series databases, data can be queried and displayed in dashboards or tables, etc.

I have presented 10000ft view of what happens with telemetry pipeline. All this is spread across different systems and timelines.

https://docs.timescale.com/promscale/latest/about-promscale/#architecture will provide you with some more details.

Build a Weather Station with Elixir and Nerves uses phoenix for processing weather data collected using hardware. Section excerpt - Time-Series Sensor Hub in the book provides you with an overview of its architecture.

You can use https://contex-charts.org/ to display charts in dashboards in elixir.

Based on intent of your learning exercise - you can try out one of the below:

  • learning about telemetry pipeline in production - you can look at Telemetry/Opentelemetry, TimescaleDB, Graphana, etc.
  • books data has something relating to time series like sales, popularity, ratings, etc - you can look at TimescaleDB and tool like graphana to display data.
  • visualise books data in dashboard using phoenix - use charting library like contex, etc with sql queries.
  • or learn more about phoenix live dashboard.
mrclumsy

mrclumsy OP

Thanks for the feedback @benwilson512, I was starting to get the idea that that might be the case. I’ll take a look at other options as you mentioned.

mrclumsy

mrclumsy OP

Thank you for all the links and resources @kartheek, I’ll be sure to take the time to look through them all properly. And thank you for the advice on next steps. I think I might start with looking at libraries like contex since that fits the immediate my immediate aim and then move on the rest.

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews