SlideShare a Scribd company logo
MySQL-StatsD
MySQL Performance monitoring
using Statsd, Graphite and Grafana
Art van Scheppingen
Freelance DBA @ DBArt
Overview
• Who am I?
• What monitoring tools are out there?
• What are StatsD, Collectd and Graphite?
• How to use StatsD?
• MySQL+StatsD = MySQL-StatsD
• Graphing examples
• Grafana
• Challenges
• Questions?
Who am I?
• Freelance DBA
• Worked >10 years in the gaming industry
• Worked for several start ups
• HA and scaling specialist
What monitoring systems are out there?
Clarifying monitoring methods
• Pull
– Nagios (NRP)
– SNMP
• Push
– Shinken
– StatsD / CollectD
Monitoring storage systems
• File based
– RRD
– Carbon (single host)
• Database based
– zabbix
• Cluster based
– OpenTSDB
– InfluxDB
– Carbon (clustered)
Popular monitoring systems
• Cacti
– Pull + RRD
• Zabbix
– Pull + SQL
• Munin
– Pull + RRD
• Shinken
– Pull + Push + RRD
• Monyog
– Pull + proprietary storage
• MRTG
– Pull + RRD
Hosted solutions
• VividCortex
• Severalnines
• Percona cloud tools
• Cloudwatch (AWS)
• Google Cloud Monitoring (Google)
Statsd + Collectd + Graphite
What are they?
What is Graphite?
• Highly scalable real-time graphing system
• Collects numeric time-series
• Backend daemon Carbon
– Carbon-cache: receives data
– Carbon-aggregator: aggregates data
– Carbon-relay: replication and sharding
• RRD or Whisper database
10
Graphite’s capabilities
• Each metric is in its own bucket
– Periods make folders
– prod.syseng.mmm.<hostname>.admin_offline
• Metric types
– Counters
– Gauge
• Retention can be set using a regex
– [mysql]
– pattern = ^prod.syseng.mysql..*$
– retentions = 2s:1d,1m:3d,5m:7d,1h:5y
11
Graphite server
Graphite server
12
Client requesting graphs
Graphite (port 443)
Server-
1
Server-
2
Server-
n
Carbon (port 2003)
Graphite Rendering Carbon relay
Scaling a Graphite environment
13
Client requesting graphs
Graphite Rendering
Cluster
Carbon relay
Loadbalancer (port 443)
DEV TEST PRD DC1 PRD DC2
Server-
1
Server-
2
Server-
n
Loadbalancer (port 2003)
Skyline
24h retention
1 node
Graphite Storage Clusters
14
What is Collectd?
• Unix daemon that gathers system statistics
• Over 90 (input/output) plugins
• Plugin to send metrics to Graphite/Carbon
• Very useful for system metrics
Collectd
16
Collectd
Gather data plugins
CPU DISK LOAD ….
CarbonTCP
30 second interval
What is StatsD?
• Front-end proxy for Graphite/Carbon (by Etsy)
• NodeJS daemon (also other languages)
• Receives UDP (on localhost)
• Buffers metrics locally
• Flushes periodically to Graphite/Carbon (TCP)
• Client libraries available in many languages
• Send any metric you like!
17
StatsD functions
• StatsD functions
– update_stats (counter)
• Difference between previous and current value
• metric = <value> per second
– increment/decrement
• metric++ / metric--
– Set
• Counts the number of unique items (e.g. userids, email)
• metric = unique(value1, value2, value3, value4)
– gauge
• What is the current value (e.g. 240.87 volts) and persist
• metric = <value>
– timers
• How much time did it take in seconds?
• metric = <value> in seconds
18
StatsD
19
StatsD
Application Level
# OF LOGINS
CACHE
HIT/MISS
STATUS
INNODB
STATUS
CarbonTCP
2 second interval
MySQL_Statsd
localhost:8125
UDP
Using StatsD
StatsD Bash examples
echo ”some.metric:1|c" | nc -w 1 -u graphite.host 8125
echo ”some.metric:1|c" > /dev/udp/localhost/8125
bash-3.2# netstat -s | grep "listen"
26 times the listen queue of a socket overflowed
netstat -s | grep "listen" | awk '{print "hostname.listen.queue.overflowed:"$1"|c"}’ >
/dev/udp/localhost/8125
hostname.listen.queue.overflowed:26|c
echo "show global status" | mysql -u root | awk '{print
"hostname.mysql.status."$1":"$2"|c"}'
21
Other metrics
• Deployments
• User initiated actions
– Logins
– High scores
– Comments / ratings
– Images uploaded
– Payments
• Application metrics
– Error counts
– Cache statistics (cache hit/miss)
– Request timers
– Image sizes
22
Common mistakes 1
• Using an update instead of a gauge
– com_select vs select queries since last flush
prod.host.mysql.status.com_select:100000|c
---- flush (every 5 seconds)
prod.host.mysql.status.com_select:100010|c
prod.host.mysql.status.com_select:100015|c
---- flush (every 5 seconds)
Theory:
10 + 5 / 5 seconds = 3 queries per second
Reality:
100010 + 100015 / 5 seconds = 40005 per second
Common mistakes 2
• Misaligned flush interval with update (counter)
– StatsD flush interval 10 seconds
– Application interval 15 seconds
– Results in every second StatsD flush to be empty
– Change to gauge
---- flush (10 seconds)
prod.host.mysql.innodb.history_list:4|c
---- flush (10 seconds)
---- flush (10 seconds)
prod.host.mysql.innodb.history_list:8|c
---- flush (10 seconds)
---- flush (10 seconds)
prod.host.mysql.innodb.history_list:6|c
---- flush (10 seconds)
MySQL + StatsD = MySQL-StatsD
Why use StatsD over Collectd?
• MySQL plugin for Collectd
– Sends SHOW STATUS
– No INNODB STATUS
– Plugin not flexible
• DBI plugin for Collectd
– Metrics based on columns
• Different granularity needed
• Separate daemon (with persistent
connection)
• StatsD is easy as ABC
26
MySQL StatsD daemon
• Written in Python
• Rewritten and open sourced during a hackday
• Gathers data every 0.5 seconds
• Sends to StatsD (localhost) after every run
• Easy configuration (Unix type config)
• Persistent connection
• Baron Schwartz’ InnoDB status parser (cacti poller)
– Multi bufferpool support
• Other interesting metrics and counters
– Information Schema
– Performance Schema
– MariaDB specific
– Galera specific
– If you can query it, you can use it as a metric!
27
MySQL StatsD overview
28
StatsD
MySQL Thread
MySQL
MySQL StatsD daemon
StatsD thread
SHOW GLOBAL VARIABLES
SHOW GLOBAL STATUS
SHOW ENGINE INNODB STATUS
SHOW SLAVE STATUS
Preparsers
InnoDB
Columnar
Example configuration
[daemon]
logfile = /var/log/mysql_statsd/daemon.log
pidfile = /var/run/mysql_statsd.pid
[statsd]
host = localhost
port = 8125
prefix = prd.mysql
include_hostname = true
[mysql]
host = localhost
username = mysqlstatsd
password =ub3rs3cr3tp@ss!
stats_types = status,variables,innodb,commit
query_variables = SHOW GLOBAL VARIABLES
interval_variables = 10000
query_status = SHOW GLOBAL STATUS
interval_status = 500
query_innodb = SHOW ENGINE INNODB STATUS
interval_innodb = 10000
query_commit = COMMIT
interval_commit = 5000
sleep_interval = 500
[metrics]
variables.max_connections = g
status.max_used_connections = g
status.connections = c
innodb.spin_waits = c
29
Adding a custom query
[mysql]
host = localhost
username = mysqlstatsd
password =ub3rs3cr3tp@ss!
stats_types = status,variables,innodb,commit,myapp
query_variables = SHOW GLOBAL VARIABLES
interval_variables = 10000
query_status = SHOW GLOBAL STATUS
interval_status = 500
query_innodb = SHOW ENGINE INNODB STATUS
interval_innodb = 10000
query_commit = COMMIT
interval_commit = 5000
query_myapp = SELECT productname, sum(order_total) FROM myapp.orders 
WHERE orderdate >= DATESUB(NOW(), INTERVAL 300 second) GROUP BY productid
interval_myapp = 300000
sleep_interval = 500
[metrics]
myapp.product_a = c
myapp.product_b = c
variables.max_connections = g
status.max_used_connections = g
status.connections = c
innodb.spin_waits = c
30
Start graphing!
What is important for you?
– Identify your KPIs
– Don’t graph everything
• More graphs == less overview
– Combine metrics
– Stack clusters
32
Correlate!
– Include other metrics into your graphs
• Deployments
• Failover(s)
– Combine application metrics with your database
– Other influences
• Launch of a new game
33
Graphing
• Graphite Graphing Engine
– DIY
– Giraffe
• Readily available dashboards/tools
– Grafana (Kibana fork)
– Skyline (Etsy)
– Dashing (Shopify)
34
Graphite Graphing Engine
– URI based rendering API
– Support for wildcards
– stats.prod.syseng.mysql.*.status.com_select
– sumSeries (stats.prod.syseng.mysql.*.status.com_select)
– aliasByNode(stats.prod.syseng.mysql.*.status.com_select,
4)
• Many functions
– Nth percentile
– Holt-Winters Forecast
– Timeshift
35
Graphite Example URL
https://graphitehost/render/?width=722&height=357&_salt=1366550446.553&righ
tDashed=1&target=alias%28sumSeries%28stats.prod.services.profilar.request.t
otal.count.*%29%2C%22Number%20of%20profile%20requests%22%29&target=alias%28
secondYAxis%28sumSeries%28stats_counts.prod.syseng.mysql.<node1>.status.que
stions%2C%20stats_counts.prod.syseng.mysql.<node2).status.questions%29%29%2
C%22Number%20of%20queries%20profiles%20cluster%22%29&from=00%3A00_20130415&
until=23%3A59_20130421
36
Graphite Example URL
https://graphitehost/render/?width=722&height=357&_salt=1366550446.553&righ
tDashed=1&target=alias%28sumSeries%28stats.prod.services.profilar.request.t
otal.count.*%29%2C%22Number%20of%20profile%20requests%22%29&target=alias%28
secondYAxis%28sumSeries%28stats_counts.prod.syseng.mysql.<node1>.status.que
stions%2C%20stats_counts.prod.syseng.mysql.<node2>).status.questions%29%29%
2C%22Number%20of%20queries%20profiles%20cluster%22%29&from=00%3A00_20130415
&until=23%3A59_20130421
37
Graphing with Grafana
I know Kibana hence I know Grafana
What is Grafana?
• Fork of the Kibana interface
– Flexible and intuitive GUI
– Easy to create graphs
• Supports Graphite, InfluxDB and OpenTSDB
• Clientside JavaScript rendering (no gif/png)
• Templated dashboards
• Scripted dashboards
• Supports CMDB apis
Demonstration
Challenges
Sounds great, can I use it?
MySQL-Statsd repo
Current version: 1.4.0
https://github.com/db-art/mysql-statsd
MySQL-Statsd roadmap
– Most teething problems have been resolved
– Install via pip
• vitrual-env advised
– Support custom columnar queries
– Whitelisting of wildcard paths not supported yet
– Merge with Mongo-Collector?
43
What lessons have we learned?
– Persistent connections + repeatable read
• History list skyrocketed
– Requesting too many metrics slows down graphing
– Sending too many metrics can kill a host
• EstatsD for Erlang
44
Questions?
Practical links
– Graphite:
http://graphite.readthedocs.org/en/latest/
– Grafana:
http://grafana.org/
– Collectd:
https://collectd.org/
– StatsD on Github by Etsy:
https://github.com/etsy/statsd/wiki
– Etsy on StatsD:
http://codeascraft.etsy.com/2011/02/15/measure-
anything-measure-everything/
46
Thank you!
• Presentation can be found at:
http://goo.gl/AR3OCf
MySQL Statsd can be found at:
https://github.com/db-art/mysql-statsd
• If you wish to contact me:
art@dbart.net
47

More Related Content

What's hot (20)

PDF
쿠키런 1년, 서버개발 분투기
Brian Hong
 
PDF
【Unite 2017 Tokyo】Unity最適化講座 ~スペシャリストが教えるメモリとCPU使用率の負担最小化テクニック~
Unity Technologies Japan K.K.
 
PDF
오딘: 발할라 라이징 MMORPG의 성능 최적화 사례 공유 [카카오게임즈 - 레벨 300] - 발표자: 김문권, 팀장, 라이온하트 스튜디오...
Amazon Web Services Korea
 
PPTX
Screen space reflection
Bongseok Cho
 
PDF
Compute shader
QooJuice
 
PDF
svn 능력자를 위한 git 개념 가이드
Insub Lee
 
PPTX
Android動態ui介面設計
艾鍗科技
 
PPTX
Siggraph 2011: Occlusion culling in Alan Wake
Umbra
 
PDF
[NDC18] 만들고 붓고 부수고 - 〈야생의 땅: 듀랑고〉 서버 관리 배포 이야기
Chanwoong Kim
 
PDF
마이크로서비스 기반 클라우드 아키텍처 구성 모범 사례 - 윤석찬 (AWS 테크에반젤리스트)
Amazon Web Services Korea
 
PDF
SonarQube와 함께하는 소프트웨어 품질 세미나 - SonarQube 소개
CURVC Corp
 
PDF
도메인 주도 설계의 본질
Young-Ho Cho
 
PPTX
Master slave pattern
Heo Seungwook
 
PDF
Data-Oriented Design과 유니티 DOTS
Sukwoo Lee
 
PPT
게임 프레임워크의 아키텍쳐와 디자인 패턴
MinGeun Park
 
PDF
FlutterでのWidgetツリーへの状態伝播とアクセス制限の基本戦略
cch-robo
 
PPT
프레임레이트 향상을 위한 공간분할 및 오브젝트 컬링 기법
YEONG-CHEON YOU
 
PDF
LetSwift 2017 - 토스 iOS 앱의 개발/배포 환경
Mintak Son
 
PDF
Akka.NET 으로 만드는 온라인 게임 서버 (NDC2016)
Esun Kim
 
PPT
GCGC- CGCII 서버 엔진에 적용된 기술 (5) - Executor with Exception
상현 조
 
쿠키런 1년, 서버개발 분투기
Brian Hong
 
【Unite 2017 Tokyo】Unity最適化講座 ~スペシャリストが教えるメモリとCPU使用率の負担最小化テクニック~
Unity Technologies Japan K.K.
 
오딘: 발할라 라이징 MMORPG의 성능 최적화 사례 공유 [카카오게임즈 - 레벨 300] - 발표자: 김문권, 팀장, 라이온하트 스튜디오...
Amazon Web Services Korea
 
Screen space reflection
Bongseok Cho
 
Compute shader
QooJuice
 
svn 능력자를 위한 git 개념 가이드
Insub Lee
 
Android動態ui介面設計
艾鍗科技
 
Siggraph 2011: Occlusion culling in Alan Wake
Umbra
 
[NDC18] 만들고 붓고 부수고 - 〈야생의 땅: 듀랑고〉 서버 관리 배포 이야기
Chanwoong Kim
 
마이크로서비스 기반 클라우드 아키텍처 구성 모범 사례 - 윤석찬 (AWS 테크에반젤리스트)
Amazon Web Services Korea
 
SonarQube와 함께하는 소프트웨어 품질 세미나 - SonarQube 소개
CURVC Corp
 
도메인 주도 설계의 본질
Young-Ho Cho
 
Master slave pattern
Heo Seungwook
 
Data-Oriented Design과 유니티 DOTS
Sukwoo Lee
 
게임 프레임워크의 아키텍쳐와 디자인 패턴
MinGeun Park
 
FlutterでのWidgetツリーへの状態伝播とアクセス制限の基本戦略
cch-robo
 
프레임레이트 향상을 위한 공간분할 및 오브젝트 컬링 기법
YEONG-CHEON YOU
 
LetSwift 2017 - 토스 iOS 앱의 개발/배포 환경
Mintak Son
 
Akka.NET 으로 만드는 온라인 게임 서버 (NDC2016)
Esun Kim
 
GCGC- CGCII 서버 엔진에 적용된 기술 (5) - Executor with Exception
상현 조
 

Similar to MySQL performance monitoring using Statsd and Graphite (20)

PPTX
MySQL performance monitoring using Statsd and Graphite (PLUK2013)
spil-engineering
 
PDF
MySQL Performance Monitoring
spil-engineering
 
PDF
Monitoring as Software Validation
BioDec
 
PPTX
StasD & Graphite - Measure anything, Measure Everything
Avi Revivo
 
PDF
Statsd introduction
Rick Chang
 
PDF
app/server monitoring
Jaemok Jeong
 
PDF
OSDC 2014: Devdas Bhagat - Graphite: Graphs for the modern age
NETWAYS
 
PDF
StatsD DevOps Boulder 7/20/15
Mark Morris
 
PDF
Monitoring pg with_graphite_grafana
Jan Wieck
 
PPTX
Eko10 Workshop Opensource Database Auditing
Juan Berner
 
PPTX
Eko10 workshop - OPEN SOURCE DATABASE MONITORING
Pablo Garbossa
 
PDF
Measure All the Things! - Austin Data Day 2014
gdusbabek
 
PDF
How to measure everything - a million metrics per second with minimal develop...
Jos Boumans
 
KEY
Trending with Purpose
Jason Dixon
 
PDF
Application Monitoring using Open Source - VictoriaMetrics & Altinity ClickHo...
Altinity Ltd
 
PDF
Application Monitoring using Open Source: VictoriaMetrics - ClickHouse
VictoriaMetrics
 
PDF
Timeseries - data visualization in Grafana
OCoderFest
 
PDF
Python and trending_data_ops
chase pettet
 
PDF
Infrastructure Monitoring with Postgres
Steven Simpson
 
PDF
FOSDEM 2019: M3, Prometheus and Graphite with metrics and monitoring in an in...
Rob Skillington
 
MySQL performance monitoring using Statsd and Graphite (PLUK2013)
spil-engineering
 
MySQL Performance Monitoring
spil-engineering
 
Monitoring as Software Validation
BioDec
 
StasD & Graphite - Measure anything, Measure Everything
Avi Revivo
 
Statsd introduction
Rick Chang
 
app/server monitoring
Jaemok Jeong
 
OSDC 2014: Devdas Bhagat - Graphite: Graphs for the modern age
NETWAYS
 
StatsD DevOps Boulder 7/20/15
Mark Morris
 
Monitoring pg with_graphite_grafana
Jan Wieck
 
Eko10 Workshop Opensource Database Auditing
Juan Berner
 
Eko10 workshop - OPEN SOURCE DATABASE MONITORING
Pablo Garbossa
 
Measure All the Things! - Austin Data Day 2014
gdusbabek
 
How to measure everything - a million metrics per second with minimal develop...
Jos Boumans
 
Trending with Purpose
Jason Dixon
 
Application Monitoring using Open Source - VictoriaMetrics & Altinity ClickHo...
Altinity Ltd
 
Application Monitoring using Open Source: VictoriaMetrics - ClickHouse
VictoriaMetrics
 
Timeseries - data visualization in Grafana
OCoderFest
 
Python and trending_data_ops
chase pettet
 
Infrastructure Monitoring with Postgres
Steven Simpson
 
FOSDEM 2019: M3, Prometheus and Graphite with metrics and monitoring in an in...
Rob Skillington
 
Ad

Recently uploaded (20)

PDF
Jotform Presentation Agents: Features and Benefits
Jotform
 
PDF
Committee-Skills-Handbook---MUNprep.org.pdf
SatvikAgarwal9
 
PPTX
STURGEON BAY WI AG PPT JULY 6 2025.pptx
FamilyWorshipCenterD
 
PDF
Buy Verified Payoneer Accounts — The Ultimate Guide for 2025 (Rank #1 on Goog...
Buy Verified Cash App Accounts
 
PPTX
Unit 1, 2 & 3 - Pharmacognosy - Defn_history_scope.pptx
bagewadivarsha2024
 
PPTX
Melbourne_Keynote_June_19_2013_without_photos.pptx
BryInfanteRayos
 
PDF
Buy Verified Coinbase Accounts — The Ultimate Guide for 2025 (Rank #1 on Goog...
Buy Verified Cash App Accounts
 
PDF
From Draft to DSN - How to Get your Paper In [DSN 2025 Doctoral Forum Keynote]
vschiavoni
 
PDF
The Impact of Game Live Streaming on In-Game Purchases of Chinese Young Game ...
Shibaura Institute of Technology
 
PDF
Planning the parliament of the future in greece – considerations for a data-d...
Dr. Fotios Fitsilis
 
PDF
The Origin - A Simple Presentation on any project
RishabhDwivedi43
 
DOCX
How Digital Marketplaces are Empowering Emerging MedTech Brands
Ram Gopal Varma
 
PDF
The Family Secret (essence of loveliness)
Favour Biodun
 
PDF
Jotform Presentation Agents: Use Cases and Examples
Jotform
 
PPTX
presentation on legal and regulatory action
raoharsh4122001
 
PDF
Model Project Report_36DR_G&P.pdf for investors understanding
MeetAgrawal23
 
PPTX
Lesson 1-3(Learners' copy).pptxucspctopi
KrizeAnneCorneja
 
PPTX
INTRO-TO-EMPOWERMENT-TECHNOLGY grade 11 lesson
ReyAcosta8
 
DOC
STABILITY INDICATING METHOD DEVELOPMENT AND VALIDATION FOR SIMULTANEOUS ESTIM...
jmkeans624
 
PPTX
Great-Books. Powerpoint presentation. files
tamayocrisgie
 
Jotform Presentation Agents: Features and Benefits
Jotform
 
Committee-Skills-Handbook---MUNprep.org.pdf
SatvikAgarwal9
 
STURGEON BAY WI AG PPT JULY 6 2025.pptx
FamilyWorshipCenterD
 
Buy Verified Payoneer Accounts — The Ultimate Guide for 2025 (Rank #1 on Goog...
Buy Verified Cash App Accounts
 
Unit 1, 2 & 3 - Pharmacognosy - Defn_history_scope.pptx
bagewadivarsha2024
 
Melbourne_Keynote_June_19_2013_without_photos.pptx
BryInfanteRayos
 
Buy Verified Coinbase Accounts — The Ultimate Guide for 2025 (Rank #1 on Goog...
Buy Verified Cash App Accounts
 
From Draft to DSN - How to Get your Paper In [DSN 2025 Doctoral Forum Keynote]
vschiavoni
 
The Impact of Game Live Streaming on In-Game Purchases of Chinese Young Game ...
Shibaura Institute of Technology
 
Planning the parliament of the future in greece – considerations for a data-d...
Dr. Fotios Fitsilis
 
The Origin - A Simple Presentation on any project
RishabhDwivedi43
 
How Digital Marketplaces are Empowering Emerging MedTech Brands
Ram Gopal Varma
 
The Family Secret (essence of loveliness)
Favour Biodun
 
Jotform Presentation Agents: Use Cases and Examples
Jotform
 
presentation on legal and regulatory action
raoharsh4122001
 
Model Project Report_36DR_G&P.pdf for investors understanding
MeetAgrawal23
 
Lesson 1-3(Learners' copy).pptxucspctopi
KrizeAnneCorneja
 
INTRO-TO-EMPOWERMENT-TECHNOLGY grade 11 lesson
ReyAcosta8
 
STABILITY INDICATING METHOD DEVELOPMENT AND VALIDATION FOR SIMULTANEOUS ESTIM...
jmkeans624
 
Great-Books. Powerpoint presentation. files
tamayocrisgie
 
Ad

MySQL performance monitoring using Statsd and Graphite

Editor's Notes

  • #46: ----- Meeting Notes (30-11-12 12:00) ----- Abbreviations (try to pronounce) Theory too long, second part too brief. High Availability -> HA What do we do? Games! 180M+ Query numbers on DBs Some examples of portal names SSP is abstraction layer SSP query example Explain why horizontal instead of vertical Functional sharding slide! Explain why sattelite DC Introduction to sattelite data centers (moving data to caching) but explain they do not own the data Instead of example of migrating users, example of adding a new DC Slide 23: leave out slide Why we chose erlang: remove pattern matching. Adds productivity: simpler Add another example for buckets with a different backend Slide 22: partition on users, bucket and GIDs. It is not a mess in LAMP stack: the backend is just not scalables