$30 off During Our Annual Pro Sale. View Details »
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Monitoring Containerized Elixir
Search
さっちゃん
September 07, 2019
Programming
1
910
Monitoring Containerized Elixir
#ElixirConfJP #CastleConf
さっちゃん
September 07, 2019
Tweet
Share
More Decks by さっちゃん
See All by さっちゃん
みんなのオブザーバビリティプラットフォームを作ってるんだがパフォーマンスがやばい #mackerelio #srenext
ne_sachirou
0
1.2k
作ってよかったgraceful shutdownライブラリ #kyotogo
ne_sachirou
0
1.1k
path 依存型って何?
ne_sachirou
0
480
野生の onbording と onbording 設計 #kyototechtalk
ne_sachirou
0
570
メトリックはいかにして見え續ける樣になったか #devio2022
ne_sachirou
0
69
名實一致
ne_sachirou
0
610
まかれるあなとみあ ―Mackerel のしくみを理解する 30 分― @ Hatena Engineer Seminar #16
ne_sachirou
0
3k
tacit programming : Point-free, Concatenatives & J
ne_sachirou
0
830
Let's create stateful systems, by Elixir
ne_sachirou
1
890
Other Decks in Programming
See All in Programming
イマのCSSでできる インタラクション最前線 + CSS最新情報
clockmaker
5
3.6k
Creating a Free Video Ad Network on the Edge
mizoguchicoji
0
140
macOS なしで iOS アプリを開発する(※ただし xxx に限る)
mitsuharu
1
120
WebAssembly Unleashed: Powering Server-Side Applications
chrisft25
0
1.8k
EMになってからチームの成果を最大化するために取り組んだこと/ Maximize team performance as EM
nashiusagi
0
120
AI時代におけるSRE、 あるいはエンジニアの生存戦略
pyama86
6
1.3k
Java 23の概要とJava Web Frameworkの現状 / Java 23 and Java web framework
kishida
2
360
ペアーズにおけるAmazon Bedrockを⽤いた障害対応⽀援 ⽣成AIツールの導⼊事例 @ 20241115配信AWSウェビナー登壇
fukubaka0825
6
2.2k
AWS AppSyncを用いた GraphQL APIの開発について - NIFTY Tech Talk #22
niftycorp
PRO
0
100
「今のプロジェクトいろいろ大変なんですよ、app/services とかもあって……」/After Kaigi on Rails 2024 LT Night
junk0612
5
2.2k
subpath importsで始めるモック生活
10tera
0
380
romajip: 日本の住所CSVデータを活用した英語住所変換ライブラリを作った話
sangunkang
0
2.1k
Featured
See All Featured
Become a Pro
speakerdeck
PRO
25
5k
[RailsConf 2023] Rails as a piece of cake
palkan
52
5k
A designer walks into a library…
pauljervisheath
204
24k
Testing 201, or: Great Expectations
jmmastey
39
7.1k
Practical Orchestrator
shlominoach
186
10k
Agile that works and the tools we love
rasmusluckow
327
21k
Bash Introduction
62gerente
608
210k
Producing Creativity
orderedlist
PRO
341
39k
Imperfection Machines: The Place of Print at Facebook
scottboms
265
13k
A better future with KSS
kneath
238
17k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
31
2.7k
Fireside Chat
paigeccino
34
3k
Transcript
Monitoring Containerized Elixir
.。oO(さっちゃんですよヾ(〃l _ l)ノ゙☆) @ Mackerel.io / Hatena.ne.jp
Imagine, you have a great Elixir app.
Imagine, you have a great Elixir app. And will be
working it on Docker
Imagine, you have a great Elixir app. And will be
working it on Docker on Kubernetes.
Why container, Docker? Container is an abstract layer over infrastructure.
It runs everywhere. It easy to create, share, transfer & run.
Why Kubernetes? K8s is a common language. K8s can run
every types of applications.
Elixir on Containers https://speakerdeck.com/ne_sachirou/elixir-on- containers s/:distillery/Mix.Release/
When you've deployed the app on K8s. How to monitor
it?
Why Monitoring? Is your app works well? Know how your
app works. What caused when your app is broken. Keep your app observable.
Liveness check Is your app is living or not?
K8s has liveness probe. --- apiVersion: apps/v1 kind: Deployment spec:
template: spec: containers: - name: app livenessProbe: httpGet: path: /ops/heartbeat port: 4000
How to check your app is live or not?
KomachiHeartbeat https://hex.pm/packages/komachi_heartbeat Vital monitoring Elixir Web application.
KomachiHeartbeat The name is originate from a great Rubygems :
https://rubygems.org/gems/komachi_heartbeat
Add KomachiHeartbeat. defmodule Example.Router do use Plug.Router plug(:match) plug(:dispatch) forward("/ops",
to: KomachiHeartbeat) end defmodule ExampleWeb.Router do use ExampleWeb, :router forward("/ops", KomachiHeartbeat) end
Check it. % curl http://localhost/ops/heartbeat heartbeat:ok Also available from Zabbix,
ALB health check or Mackerel's "External Http monitor (外形監視)".
Error collection Listening canary song.
Sentry https://sentry.io/ Collect & sort errors. Show the error environments:
stacktrace, HTTP params, app host, release ver… Assign & resolve issue. Integrate with Sass: Slack, GitHub…
Add https://hex.pm/packages/sentry in your app. defmodule Example.Application do use Application
def start(_type, _args) do Logger.add_backend(Sentry.LoggerBackend) … end defmodule Example.Router do use Sentry.Plug … end & add many metadata, by yourself (・﹏・)
Metrics monitoring Know the app behaviour & detect anomary.
Prometheus + Grafana + deadtrickster/beam-dashboards Beautiful. But to keep Prometheus
servers have many toils.
Mackerel https://mackerel.io
Add mackerel-container-agent as a sidecar. --- apiVersion: apps/v1 kind: Deployment
spec: template: spec: containers: - name: app … - name: mackerel-container-agent image: mackerel/mackerel-container-agent:latest imagePullPolicy: Always resources: limits: {memory: 128Mi} env: - {name: MACKEREL_CONTAINER_PLATFORM, value: kubernetes} - name: MACKEREL_KUBERNETES_KUBELET_HOST valueFrom: fieldRef: fieldPath: status.hostIP - name: MACKEREL_KUBERNETES_NAMESPACE valueFrom: fieldRef: {fieldPath: metadata.namespace} - name: MACKEREL_KUBERNETES_POD_NAME valueFrom: fieldRef: {fieldPath: metadata.name} - {name: MACKEREL_ROLES, value: example:app} envFrom: - secretRef: {name: mackerel}
apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization … secretGenerator: - name: mackerel type:
Opaque files: [MACKEREL_APIKEY=secret/MACKEREL_APIKEY]
None
OK. I see container's metrics. How about BEAM metrics?
KomachiHeartbeat + mackerel- plugin-json https://hex.pm/packages/komachi_heartbeat Vital monitoring Elixir Web application.
https://github.com/mackerelio/mackerel-plugin-json Json custom metrics plugin for mackerel.io agent.
KomachiHeartbeat has /stats endpoint that returns app's stats in JSON.
mackerel-plugin-json posts any data gotten from JSON API as Mackerel custome metrics.
We have KomachiHeartbeat.BeamVital . https://github.com/ne- sachirou/ex_komachi_heartbeat/pull/29 (Sorry for under development.)
Add KomachiHeartbeat.BeamVital . defmodule TeijiBot.Router do use Plug.Router plug(:match) plug(:dispatch)
forward( "/ops", to: KomachiHeartbeat, init_opts: [vitals: [KomachiHeartbeat.BeamVital]] ) end
Configure mackerel-plugin-json. --- apiVersion: apps/v1 kind: Deployment spec: template: spec:
volumes: - name: mackerel-agent-config configMap: name: mackerel-agent-config containers: - name: app … - name: mackerel-container-agent image: mackerel/mackerel-container-agent:plugins … env: - {name: MACKEREL_AGENT_CONFIG, value: /etc/mackerel/mackerel.yaml} … volumeMounts: - name: mackerel-agent-config mountPath: /etc/mackerel readOnly: true
--- apiVersion: v1 kind: ConfigMap metadata: name: mackerel-agent-config data: mackerel.yaml:
| plugin: metrics: json: command: | mackerel-plugin-json \ -url="http://localhost:4000/ops/stats" \ -prefix='beam'
None
Current metrics : atom_count memory_ets_tables memory_system_bytes_total atom, binary, code, ets,
other port_count process_count (More, under development.)