{"id":18352769,"url":"https://github.com/membraneframework/membrane_telemetry_metrics","last_synced_at":"2025-04-06T11:33:05.161Z","repository":{"id":39588128,"uuid":"477638512","full_name":"membraneframework/membrane_telemetry_metrics","owner":"membraneframework","description":"Membrane tool for generating metrics","archived":false,"fork":false,"pushed_at":"2024-10-22T10:09:00.000Z","size":40,"stargazers_count":1,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-21T22:33:45.296Z","etag":null,"topics":["elixir","metrics","statistics","telemetry"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/membraneframework.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-04-04T09:48:16.000Z","updated_at":"2024-10-22T10:08:10.000Z","dependencies_parsed_at":"2024-10-22T20:38:24.260Z","dependency_job_id":null,"html_url":"https://github.com/membraneframework/membrane_telemetry_metrics","commit_stats":{"total_commits":27,"total_committers":5,"mean_commits":5.4,"dds":"0.18518518518518523","last_synced_commit":"2dba471bacbcc7628c5a398dc4190c6ffaa859a0"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":"membraneframework/membrane_template_plugin","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/membraneframework%2Fmembrane_telemetry_metrics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/membraneframework%2Fmembrane_telemetry_metrics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/membraneframework%2Fmembrane_telemetry_metrics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/membraneframework%2Fmembrane_telemetry_metrics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/membraneframework","download_url":"https://codeload.github.com/membraneframework/membrane_telemetry_metrics/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247478152,"owners_count":20945258,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["elixir","metrics","statistics","telemetry"],"created_at":"2024-11-05T21:37:16.430Z","updated_at":"2025-04-06T11:33:04.568Z","avatar_url":"https://github.com/membraneframework.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Membrane Telmetry Metrics\n\n[![Hex.pm](https://img.shields.io/hexpm/v/membrane_telemetry_metrics.svg)](https://hex.pm/packages/membrane_telemetry_metrics)\n[![API Docs](https://img.shields.io/badge/api-docs-yellow.svg?style=flat)](https://hexdocs.pm/membrane_telemetry_metrics)\n[![CircleCI](https://circleci.com/gh/membraneframework/membrane_telemetry_metrics.svg?style=svg)](https://circleci.com/gh/membraneframework/membrane_telemetry_metrics)\n\nThis repository contains a tool for generating metrics.\n\nIt is part of [Membrane Multimedia Framework](https://membraneframework.org).\n\n## Installation\n\nThe package can be installed by adding `membrane_telemetry_metrics` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:membrane_telemetry_metrics, \"~\u003e 0.1.0\"}\n  ]\nend\n```\n\n## Usage\n\nThe usage example below illustrates, how you can use this tool to aggregate metrics and generate reports containing their values. In this case, we have a scenario, where a couple of people are doing their shopping, and we want to have access to the reports with some metrics about them, without calling each of these people directly.\n\nTo benefit from of full functionality offered by this tool, you have to use both `Membrane.TelemetryMetrics` and `Mebrane.TelemetryMetrics.Reporter`. \n\nFirst, put \n```elixir\nconfig :membrane_telemetry_metrics, enabled: true\n```\nin your `config.exs`. You can also pass list of events, that will be enabled in `:events` option (in this case, it would be `[[:shopping]]`). If you don't specify that option, all events will be enabled.\n\nLet's assume, that you want to track three metrics: \n * `cash_spent`\n * `number_of_payments`\n * `last_visited_shop`\nSo, the definition of our list of metrics will look like \n```elixir \nmetrics = \n  [\n    Telemetry.Metrics.sum(\n      \"cash_spent\",\n      event_name: [:shopping],\n      measurement: :payment\n    ),\n    Telemetry.Metrics.counter(\n      \"number_of_payments\",\n      event_name: [:shopping]\n    ),\n    Telemetry.Metrics.last_value(\n      \"last_visited_shop\",\n      event_name: [:shopping],\n      measurement: :shop\n    )\n  ]\n```\n\nThen, you have to start `Mebrane.TelemetryMetrics.Reporter`. It can be made by calling \n```elixir\nMembrane.TelemetryMetrics.Reporter.start_link(metrics, name: ShoppingReporter)\n```\nbut the suggested way is to do it under `Supervisor` tree, in `Application` module.\n\nNow, `ShoppingReporter` is ready to aggregate metrics from emitted events. But before that, we have to register our event in every process, that will emit it. Let's assume, that we want to aggregate data about three people: `James Smith`, `Mary Smith` and `Patricia Johnson`. Events with data about each of these people will be emitted in a different process.\n\nIn `John Smith`'s process we will execute code\n```elixir\nrequire Membrane.TelemetryMetrics\n\nMembrane.TelemetryMetrics.register([:shopping], [name: \"James\", surname: \"Smith\"])\n\nMembrane.TelemetryMetrics.execute(\n  [:shopping],\n  %{shop: \"Grocery\", payment: 10},\n  %{},\n  [name: \"James\", surname: \"Smith\"]\n)\n\nMembrane.TelemetryMetrics.execute(\n  [:shopping],\n  %{shop: \"Bakery\", payment: 5},\n  %{},\n  [name: \"James\", surname: \"Smith\"]\n)\n\nMembrane.TelemetryMetrics.execute(\n  [:shopping],\n  %{shop: \"Jeweller\", payment: 100},\n  %{},\n  [name: \"James\", surname: \"Smith\"]\n)\n```\n\nIn `Mary Smith`'s process we will execute code \n```elixir\nrequire Membrane.TelemetryMetrics\n\nMembrane.TelemetryMetrics.register([:shopping], [name: \"Mary\", surname: \"Smith\"])\n\nMembrane.TelemetryMetrics.execute(\n  [:shopping],\n  %{shop: \"Bookshop\", payment: 25},\n  %{},\n  [name: \"Mary\", surname: \"Smith\"]\n)\n\nMembrane.TelemetryMetrics.execute(\n  [:shopping],\n  %{shop: \"Butcher\", payment: 15},\n  %{},\n  [name: \"Mary\", surname: \"Smith\"]\n)\n```\n\nIn `Patricia Johnson`'s process we will execute code \n```elixir\nrequire Membrane.TelemetryMetrics\n\nMembrane.TelemetryMetrics.register(\n  [:shopping],\n  [name: \"Patricia\", surname: \"Johnson\"]\n)\n\nMembrane.TelemetryMetrics.execute(\n  [:shopping],\n  %{shop: \"Newsagent\", payment: 5},\n  %{},\n  [name: \"Patricia\", surname: \"Johnson\"]\n)\n```\n\nThen, calling \n```elixir\nMembrane.TelemetryMetrics.Reporter.scrape(ShoppingReporter)\n```\nfrom anywhere on this same node, as noticed processes, will cause getting the following result:\n```elixir \n%{\n  {:surname, \"Johnson\"} =\u003e %{\n    {:name, \"Patricia\"} =\u003e %{\n      \"cash_spent\" =\u003e 5,\n      \"last_visited_shop\" =\u003e \"Newsagent\",\n      \"number_of_payments\" =\u003e 1\n    }\n  },\n  {:surname, \"Smith\"} =\u003e %{\n    {:name, \"James\"} =\u003e %{\n      \"cash_spent\" =\u003e 115,\n      \"last_visited_shop\" =\u003e \"Jeweller\",\n      \"number_of_payments\" =\u003e 3\n    },\n    {:name, \"Mary\"} =\u003e %{\n      \"cash_spent\" =\u003e 40,\n      \"last_visited_shop\" =\u003e \"Butcher\",\n      \"number_of_payments\" =\u003e 2\n    }\n  }\n}\n```\n\nThen, for example, if `Mary Smith`'s process exits, you will get a report like\n```elixir \n%{\n  {:surname, \"Johnson\"} =\u003e %{\n    {:name, \"Patricia\"} =\u003e %{\n      \"cash_spent\" =\u003e 5,\n      \"last_visited_shop\" =\u003e \"Newsagent\",\n      \"number_of_payments\" =\u003e 1\n    }\n  },\n  {:surname, \"Smith\"} =\u003e %{\n    {:name, \"James\"} =\u003e %{\n      \"cash_spent\" =\u003e 115,\n      \"last_visited_shop\" =\u003e \"Jeweller\",\n      \"number_of_payments\" =\u003e 3\n    }\n  }\n}\n```\n\nIf a process registers an event by calling\n```elixir\nMembrane.TelemetryMetrics.register(event_name, label)\n```\nand exits after it, every metric that aggregated measurements from an event with `event_name` will drop its values held for a specific value of `label`, as in the example above `Mary Smith` has disappeared from the report, after the end of her's process.\n\n\n## Copyright and License\n\nCopyright 2022, [Software Mansion](https://swmansion.com/?utm_source=git\u0026utm_medium=readme\u0026utm_campaign=membrane_template_plugin)\n\n[![Software Mansion](https://logo.swmansion.com/logo?color=white\u0026variant=desktop\u0026width=200\u0026tag=membrane-github)](https://swmansion.com/?utm_source=git\u0026utm_medium=readme\u0026utm_campaign=membrane_template_plugin)\n\nLicensed under the [Apache License, Version 2.0](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmembraneframework%2Fmembrane_telemetry_metrics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmembraneframework%2Fmembrane_telemetry_metrics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmembraneframework%2Fmembrane_telemetry_metrics/lists"}