{"id":31136069,"url":"https://github.com/clivern/oak","last_synced_at":"2026-01-20T17:27:32.252Z","repository":{"id":310899659,"uuid":"825773253","full_name":"Clivern/Oak","owner":"Clivern","description":"🐺 Elixir Prometheus Exporter","archived":false,"fork":false,"pushed_at":"2025-08-22T11:57:24.000Z","size":66,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-18T18:12:15.440Z","etag":null,"topics":["elixir","elixir-lang","prometheus"],"latest_commit_sha":null,"homepage":"https://hex.pm/packages/oak","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Clivern.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":null,"custom":"clivern.com/sponsor/"}},"created_at":"2024-07-08T13:19:20.000Z","updated_at":"2025-08-22T11:57:28.000Z","dependencies_parsed_at":"2025-08-20T23:30:13.094Z","dependency_job_id":null,"html_url":"https://github.com/Clivern/Oak","commit_stats":null,"previous_names":["clivern/oak"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/Clivern/Oak","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clivern%2FOak","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clivern%2FOak/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clivern%2FOak/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clivern%2FOak/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Clivern","download_url":"https://codeload.github.com/Clivern/Oak/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clivern%2FOak/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278708074,"owners_count":26031932,"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","status":"online","status_checked_at":"2025-10-06T02:00:05.630Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","elixir-lang","prometheus"],"created_at":"2025-09-18T07:55:30.064Z","updated_at":"2025-10-07T01:37:39.587Z","avatar_url":"https://github.com/Clivern.png","language":"Elixir","funding_links":["clivern.com/sponsor/"],"categories":[],"sub_categories":[],"readme":"# Oak\n\nElixir Prometheus Exporter\n\n## Installation\n\nThe package can be installed by adding `oak` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:oak, \"~\u003e 0.2\"}\n  ]\nend\n```\n\n## Quick Start\n\n### Basic Usage\n\n```elixir\n# Start the metrics store\n{:ok, store} = Oak.MetricsStore.start_link()\n\n# Create and push metrics\ncounter = Oak.Metric.Counter.new(\"http_requests_total\", \"Total HTTP requests\", %{method: \"GET\"})\ngauge = Oak.Metric.Gauge.new(\"memory_usage\", \"Memory usage in bytes\", %{instance: \"web\"})\n\n# Push metrics to store\nGenServer.call(store, {:push, counter})\nGenServer.call(store, {:push, gauge})\n\n# Get all metrics\nall_metrics = GenServer.call(store, {:get_all})\n\n# Get specific metric\nmetric = GenServer.call(store, {:get, Oak.Metric.Counter.id(counter)})\n```\n\n### Using the Prometheus Module\n\n```elixir\n# Start metrics store\n{:ok, store} = Oak.MetricsStore.start_link()\n\n# Push metrics using the Prometheus module\ncounter = Oak.Metric.Counter.new(\"http_requests\", \"HTTP requests\", %{method: \"GET\"})\n\nOak.Prometheus.push_metric(store, counter)\n\n# Get Counter ID and get it from Prometheus\ncounter_id = Oak.Prometheus.get_counter_id(counter)\ncounter = Oak.Prometheus.get_metric(store, counter_id) |\u003e Oak.Metric.Counter.inc(1)\n\nOak.Prometheus.push_metric(store, counter)\n\n# Collect runtime metrics\nOak.Prometheus.collect_runtime_metrics(store)\n\n# Output in Prometheus format\nprometheus_output = Oak.Prometheus.output_metrics(store)\n\nIO.puts(prometheus_output)\n```\n\n## Metric Types\n\n### Counter\n\nCounters are monotonically increasing metrics, typically used for counting requests, errors, etc.\n\n```elixir\n# Create a counter\ncounter = Oak.Metric.Counter.new(\"requests_total\", \"Total requests\", %{endpoint: \"/api\"})\n\n# Increment the counter\ncounter = Oak.Metric.Counter.inc(counter, 1)\n\n# Set a specific value\ncounter = Oak.Metric.Counter.set(counter, 100)\n\n# Get current value\nvalue = Oak.Metric.Counter.value(counter)\n\n# Reset to zero\ncounter = Oak.Metric.Counter.reset(counter)\n```\n\n### Gauge\n\nGauges represent a single numerical value that can arbitrarily go up and down.\n\n```elixir\n# Create a gauge\ngauge = Oak.Metric.Gauge.new(\"memory_usage\", \"Memory usage in bytes\", %{instance: \"web\"})\n\n# Set the gauge value\ngauge = Oak.Metric.Gauge.set(gauge, 1024)\n\n# Increment the gauge\ngauge = Oak.Metric.Gauge.inc(gauge, 100)\n\n# Decrement the gauge\ngauge = Oak.Metric.Gauge.dec(gauge, 50)\n\n# Get current value\nvalue = Oak.Metric.Gauge.value(gauge)\n```\n\n### Histogram\n\nHistograms track the size and number of events in buckets, allowing you to measure the distribution of values.\n\n```elixir\n# Create a histogram with custom buckets\nhistogram = Oak.Metric.Histogram.new(\"request_duration\", \"Request duration\", [0.1, 0.5, 1.0], %{endpoint: \"/api\"})\n\n# Observe a value\nhistogram = Oak.Metric.Histogram.observe(histogram, 0.3)\n\n# Get statistics\nsum = Oak.Metric.Histogram.sum(histogram)\ncount = Oak.Metric.Histogram.count(histogram)\nbucket_counts = Oak.Metric.Histogram.bucket_counts(histogram)\n```\n\n### Summary\n\nSummaries track the size and number of events, providing quantiles over sliding time windows.\n\n```elixir\n# Create a summary with custom quantiles\nsummary = Oak.Metric.Summary.new(\"response_size\", \"Response size in bytes\", [0.5, 0.9, 0.95], %{service: \"auth\"})\n\n# Observe a value\nsummary = Oak.Metric.Summary.observe(summary, 1024)\n\n# Get statistics\nsum = Oak.Metric.Summary.sum(summary)\ncount = Oak.Metric.Summary.count(summary)\nobservations = Oak.Metric.Summary.observations(summary)\n\n# Calculate quantiles\nmedian = Oak.Metric.Summary.quantile(summary, 0.5)\n\np90 = Oak.Metric.Summary.quantile(summary, 0.9)\n```\n\n## Metrics Store\n\nThe `Oak.MetricsStore` provides a centralized GenServer-based storage for all metrics.\n\n```elixir\n# Start the store\n{:ok, store} = Oak.MetricsStore.start_link()\n{:ok, store} = Oak.MetricsStore.start_link(%{initial: \"metrics\"})\n\n# Push a metric\nGenServer.call(store, {:push, metric})\n\n# Get a specific metric\nmetric = GenServer.call(store, {:get, metric_id})\n\n# Get all metrics\nall_metrics = GenServer.call(store, {:get_all})\n\n# Stop the store\nOak.MetricsStore.stop(store)\n```\n\n## Prometheus Integration\n\nThe `Oak.Prometheus` module provides high-level functions for working with the metrics store and generating Prometheus-compatible output.\n\n```elixir\n# Get all metrics from store\nmetrics = Oak.Prometheus.get_metrics(store)\n\n# Push a single metric\nOak.Prometheus.push_metric(store, metric)\n\n# Push multiple metrics\nOak.Prometheus.push_metrics(store, [metric1, metric2, metric3])\n\n# Collect runtime metrics (Erlang/OTP stats)\nOak.Prometheus.collect_runtime_metrics(store)\n\n# Output metrics in Prometheus format\nprometheus_output = Oak.Prometheus.output_metrics(store)\n\n# Format a list of metrics\nformatted = Oak.Prometheus.format_metrics([metric1, metric2])\n```\n\n### Prometheus Output Format\n\nThe library generates standard Prometheus exposition format:\n\n```\n# HELP http_requests_total Total HTTP requests\n# TYPE http_requests_total counter\nhttp_requests_total{method=\"GET\"} 42\n\n# HELP memory_usage Memory usage in bytes\n# TYPE memory_usage gauge\nmemory_usage{instance=\"web\"} 1024\n```\n\n### Development Setup\n\n```bash\n# Clone the repository\ngit clone https://github.com/clivern/oak.git\ncd oak\n\n# Install dependencies\nmake deps\n\n# Run tests\nmake ci\n\n# Run formatting\nmake fmt\n```\n\n## Contributing\n\nWe are an open source, community-driven project so please feel free to join us. See the [contributing guidelines](CONTRIBUTING.md) for more details.\n\n## Versioning\n\nFor transparency into our release cycle and in striving to maintain backward compatibility, Oak is maintained under the [Semantic Versioning guidelines](https://semver.org/) and release process is predictable and business-friendly.\n\nSee the [Releases section of our GitHub project](https://github.com/clivern/oak/releases) for changelogs for each release version of Oak. It contains summaries of the most noteworthy changes made in each release.\n\n## Bug Tracker\n\nIf you have any suggestions, bug reports, or annoyances please report them to our issue tracker at https://github.com/clivern/oak/issues\n\n## Security Issues\n\nIf you discover a security vulnerability within Oak, please send an email to [hello@clivern.com](mailto:hello@clivern.com)\n\n## License\n\n© 2024, Clivern. Released under [MIT License](https://opensource.org/licenses/mit-license.php).\n\n**Oak** is authored and maintained by [@clivern](http://github.com/clivern).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclivern%2Foak","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclivern%2Foak","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclivern%2Foak/lists"}