SlideShare a Scribd company logo
MonitoringYour Elixir
Applicationwith
Prometheus
Eric Oestrich
SmartLogic
SmartLogic
We build web and mobile applications
Have a project? We can help.
smartlogic.io // contact@smartlogic.io
» Context
» Setup
» Metrics
» Instrument
» Prometheus
» Grafana
» Alerting
Prometheus
From metrics to insight
prometheus.io
Grafana
The open platform for beautiful analytics
and monitoring
grafana.com
Other Options
» NewRelic
» CloudWatch
» DataDog
» Scout
» statsd
» Graphite
» ...
Grapevine
Community site for text based games
grapevine.haus
https://github.com/oestrich/grapevine
Setup
mix.exs
[
{:prometheus_ex, "~> 3.0"},
{:prometheus_plugs, "~> 1.1"},
{:telemetry, "~> 0.3"},
]
DefineYour Metrics
Exporter
defmodule Metrics.PlugExporter do
use Prometheus.PlugExporter
end
Addto Endpoint
defmodule Web.Endpoint do
# ...
plug Metrics.PlugExporter
# ...
end
Metrics Setup
defmodule Metrics.Setup do
def setup do
Metrics.PlugExporter.setup()
end
end
Add SetuptoYour
Application
defmodule Grapevine.Application do
def start(_type, _args) do
# ...
Metrics.Setup.setup()
# ...
Supervisor.start_link(children, opts)
end
end
Metrics!
Available at
http://localhost:4100/metrics
# TYPE erlang_vm_atom_count gauge
# HELP erlang_vm_atom_count The number of atom ...
erlang_vm_atom_count 38398
# TYPE erlang_vm_atom_limit gauge
# HELP erlang_vm_atom_limit The maximum number ...
erlang_vm_atom_limit 1048576
# Many more
Custom
Instrumentation
Our firstInstrumenter
defmodule Metrics.AccountInstrumenter do
use Prometheus.Metric
def setup() do
events = [
[:create],
[:session, :login],
[:session, :logout],
]
Enum.each(events, &setup_event/1)
end
end
Our firstInstrumenter
defmodule Metrics.AccountInstrumenter do
defp setup_event(event) do
name = Enum.join(event, "_")
name = "grapevine_accounts_#{name}"
Counter.declare(
name: String.to_atom("#{name}_total"),
help: "Total of account event #{name}"
)
#...
end
end
Prometheus Naming
» Prefix with application name
» Use base units (seconds not
milliseconds)
» Suffix with unit
Prometheus Docs
Addto our Setupmodule
def setup do
Metrics.AccountInstrumenter.setup()
Metrics.PlugExporter.setup()
end
Metrics
# TYPE grapevine_accounts_session_login_total counter
# HELP grapevine_accounts_session_login_total Total count ...
grapevine_accounts_session_login_total 0
Triggering Events
0.3.0
:telemetry.execute([:grapevine, :accounts, :create], 1)
Triggering Events
0.4.0
:telemetry.execute([:grapevine, :accounts, :create],
%{value: 1})
RegisterTelemetry
Callbacks
defmodule Metrics.AccountInstrumenter do
defp setup_event(event) do
name = Enum.join(event, "_")
name = "grapevine_accounts_#{name}"
Counter.declare(
name: String.to_atom("#{name}_total"),
help: "Total of account event #{name}"
)
# [:grapevine, :accounts, :create]
event = [:grapevine, :accounts | event]
:telemetry.attach(name, event, &handle_event/4, nil)
end
end
attachvs
attach_many
Handling Events
def handle_event(event, count, metadata, config)
def handle_event([:grapevine, :accounts, :create], _, _, _) do
Logger.info("New account created!")
Counter.inc(name: :grapevine_accounts_create_total)
end
Concurrency
» :telemetry.execute runs in the process
that calls it
» Prometheus counters/gauges/etc are
tracked via public ETS tables
Viewing our Metrics
» /metrics
» Prometheus server
» Grafana
Basic Prometheus Setup
» Scrape configs
» Rules
Scrape Config
scrape_configs:
- job_name: 'grapevine'
static_configs:
- targets: ['localhost:4100']
Monitoring Your Elixir Application with Prometheus
Monitoring Your Elixir Application with Prometheus
Rules
alert: New User Registered
expr: increase(grapevine_account_create_total[5m]) > 0
annotations:
subject: "Grapevine - New user registered"
description: ""
Monitoring Your Elixir Application with Prometheus
Connecting
Grafana
Dashboards
Monitoring Your Elixir Application with Prometheus
Demo
Twitch
Live dev streams every Monday at 12PM
Eastern
twitch.tv/smartlogictv
SmartSoftware
podcast.smartlogic.io
Questions?
twitter.com/ericoestrich
github.com/oestrich
smartlogic.io

More Related Content

PDF
Insertion Sort Code
PDF
AugmentaP5 API
PDF
Business Dashboards using Bonobo ETL, Grafana and Apache Airflow
PDF
Augmenta Contribution guide
PDF
Ceilometer presentation ODS Grizzly.pdf
PDF
Quick 入門 | iOS RDD テストフレームワーク for Swift/Objective-C
PPTX
How to Introduce Telemetry Streaming (gNMI) in Your Network with SNMP with Te...
Insertion Sort Code
AugmentaP5 API
Business Dashboards using Bonobo ETL, Grafana and Apache Airflow
Augmenta Contribution guide
Ceilometer presentation ODS Grizzly.pdf
Quick 入門 | iOS RDD テストフレームワーク for Swift/Objective-C
How to Introduce Telemetry Streaming (gNMI) in Your Network with SNMP with Te...

Similar to Monitoring Your Elixir Application with Prometheus (20)

PPT
Monitoring using Prometheus and Grafana
PDF
Monitoring at scale: Migrating to Prometheus at Fastly
PDF
Opencensus with prometheus and kubernetes
PDF
Create The Internet of Your Things example of a real system - Laurent Ellerbach
PPTX
Md2010 jl-wp7-sl-dev
PPTX
Azure IoT suite - A look behind the curtain (Sam Vanhoutte @AZUG Event)
PDF
OpenCensus with Prometheus and Kubernetes
PDF
2307 - DevBCN - Otel 101_compressed.pdf
PDF
How to Build a Telegraf Plugin by Noah Crowley
PDF
Building a Telegraf Plugin by Noah Crowly | Developer Advocate | InfluxData
PDF
OpenTelemetry Introduction
PDF
Metaverse and Digital Twins on Enterprise-Public.pdf
PDF
Using bluemix predictive analytics service in Node-RED
PDF
Self scaling Multi cloud nomad workloads
PDF
Giorgio Natilli - Blaze DS Connectivity Framework
PDF
ApacheCon2019 Talk: Improving the Observability of Cassandra, Kafka and Kuber...
PPTX
Fabric - Realtime stream processing framework
PDF
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
PPTX
Prometheus Training
PPTX
使用 Prometheus 監控 Kubernetes Cluster
Monitoring using Prometheus and Grafana
Monitoring at scale: Migrating to Prometheus at Fastly
Opencensus with prometheus and kubernetes
Create The Internet of Your Things example of a real system - Laurent Ellerbach
Md2010 jl-wp7-sl-dev
Azure IoT suite - A look behind the curtain (Sam Vanhoutte @AZUG Event)
OpenCensus with Prometheus and Kubernetes
2307 - DevBCN - Otel 101_compressed.pdf
How to Build a Telegraf Plugin by Noah Crowley
Building a Telegraf Plugin by Noah Crowly | Developer Advocate | InfluxData
OpenTelemetry Introduction
Metaverse and Digital Twins on Enterprise-Public.pdf
Using bluemix predictive analytics service in Node-RED
Self scaling Multi cloud nomad workloads
Giorgio Natilli - Blaze DS Connectivity Framework
ApacheCon2019 Talk: Improving the Observability of Cassandra, Kafka and Kuber...
Fabric - Realtime stream processing framework
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
Prometheus Training
使用 Prometheus 監控 Kubernetes Cluster
Ad

More from SmartLogic (20)

PDF
Writing Game Servers with Elixir
PDF
All Aboard The Stateful Train
PDF
DC |> Elixir Meetup - Going off the Rails into Elixir - Dan Ivovich
PDF
Going Multi-Node
PPTX
Kubernetes and docker
PDF
Serializing Value Objects-Ara Hacopian
PDF
Guide to food foraging by SmartLogic's Kei Ellerbrock
PDF
Introduction to Type Script by Sam Goldman, SmartLogic
PDF
How SmartLogic Uses Chef-Dan Ivovich
PPTX
A Few Interesting Things in Apple's Swift Programming Language
PDF
Effective ActiveRecord
PDF
An Introduction to Reactive Cocoa
PDF
iOS Development Methodology
PPT
CSS Preprocessors to the Rescue!
PDF
Deploying Rails Apps with Chef and Capistrano
PDF
From Slacker to Hacker, Practical Tips for Learning to Code
PDF
The Language of Abstraction in Software Development
PDF
Android Testing: An Overview
PPTX
Intro to DTCoreText: Moving Past UIWebView | iOS Development
PDF
Logstash: Get to know your logs
Writing Game Servers with Elixir
All Aboard The Stateful Train
DC |> Elixir Meetup - Going off the Rails into Elixir - Dan Ivovich
Going Multi-Node
Kubernetes and docker
Serializing Value Objects-Ara Hacopian
Guide to food foraging by SmartLogic's Kei Ellerbrock
Introduction to Type Script by Sam Goldman, SmartLogic
How SmartLogic Uses Chef-Dan Ivovich
A Few Interesting Things in Apple's Swift Programming Language
Effective ActiveRecord
An Introduction to Reactive Cocoa
iOS Development Methodology
CSS Preprocessors to the Rescue!
Deploying Rails Apps with Chef and Capistrano
From Slacker to Hacker, Practical Tips for Learning to Code
The Language of Abstraction in Software Development
Android Testing: An Overview
Intro to DTCoreText: Moving Past UIWebView | iOS Development
Logstash: Get to know your logs
Ad

Recently uploaded (20)

PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
cuic standard and advanced reporting.pdf
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Machine learning based COVID-19 study performance prediction
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPT
Teaching material agriculture food technology
PDF
Electronic commerce courselecture one. Pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Cloud computing and distributed systems.
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
KodekX | Application Modernization Development
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
NewMind AI Weekly Chronicles - August'25 Week I
cuic standard and advanced reporting.pdf
sap open course for s4hana steps from ECC to s4
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
MIND Revenue Release Quarter 2 2025 Press Release
Spectral efficient network and resource selection model in 5G networks
Machine learning based COVID-19 study performance prediction
Per capita expenditure prediction using model stacking based on satellite ima...
Teaching material agriculture food technology
Electronic commerce courselecture one. Pdf
Big Data Technologies - Introduction.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Encapsulation_ Review paper, used for researhc scholars
Cloud computing and distributed systems.
The Rise and Fall of 3GPP – Time for a Sabbatical?
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Digital-Transformation-Roadmap-for-Companies.pptx
KodekX | Application Modernization Development

Monitoring Your Elixir Application with Prometheus