Code Monkey home page Code Monkey logo

datadog-mysql-profiler-metrics's Introduction

datadog-mysql-profiler-metrics

MySQL Table Level Metrics for Datadog in Python

About

Datadog does not provide MySQL Table Level metrics out of the box, so I used Python and Datadog's API to achieve getting table statistics into Datadog as a custom metric.

Requirements

You will need a datadog account, api/app keys, mysql server and the python packages

Datadog Keys:

Create API and APP keys:

Check out the API Documentation:

Python Packages:

$ pip install mysqlclient
$ pip install datadog

MySQL Sys Schema:

The sys schema objects can be used for typical tuning and diagnosis use cases:

mysql> select * from sys.`x$schema_table_statistics` where total_latency > 0\G
*************************** 1. row ***************************
     table_schema: foo
       table_name: bar
    total_latency: 3730128452604
     rows_fetched: 3929224
    fetch_latency: 1998830290976
    rows_inserted: 19967
   insert_latency: 1731298161628
     rows_updated: 0
   update_latency: 0
     rows_deleted: 0
   delete_latency: 0
 io_read_requests: 14
          io_read: 972
  io_read_latency: 51442220
io_write_requests: 43
         io_write: 414182
 io_write_latency: 1079346324
 io_misc_requests: 76
  io_misc_latency: 92505469736

Datadog Timeseries API

The metrics end-point allows you to post time-series data that can be graphed on Datadog’s dashboards:

# Submit multiple metrics
api.Metric.send([{
    'metric': 'my.series',
    'points': 15
}, {
    'metric': 'my1.series',
    'points': 16
}])

Map MySQL to JSON

Map the returned data to json:

mysql_querydata = cursor.fetchall()

json_data=[]

for row_data in mysql_querydata:
    json_data.append(dict(zip(row_headers, row_data)))

Preview the data:

>>> print(json_data)
[{'rows_inserted': 19967, }, {'rows_updated': 0}]

Map JSON to Datadog Metrics:

metrics = []
for each in payload:
    table_name = each['table_name']
    for k in each.keys():
        if type(each[k]) == str:
            pass
        else:
            metrics.append({
                'metric': 'mysql.custom_metric.{}.{}'.format(table_name, k),
                'points': each[k],
                'host': hostname,
                'tags': tags
            })

preview data:

>>> print(metrics)
[{'metric': 'mysql.custom_metric.foo.io_misc_requests', 'points': Decimal('93'), 'host': 'datadog-mysql', 'tags': ['mysql:performance_data']},..]

Screenshots:

Metrics:

image

Dashboard:

image

datadog-mysql-profiler-metrics's People

Contributors

ruanbekker avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.