{"id":3078,"date":"2019-02-27T18:12:39","date_gmt":"2019-02-27T16:12:39","guid":{"rendered":"http:\/\/supportex.net\/blog\/?p=3078"},"modified":"2019-05-09T11:14:29","modified_gmt":"2019-05-09T09:14:29","slug":"google-cloud-sql-mysql-how-to-convert-json-to-slowlog","status":"publish","type":"post","link":"https:\/\/supportex.net\/blog\/2019\/02\/google-cloud-sql-mysql-how-to-convert-json-to-slowlog\/","title":{"rendered":"Google Cloud SQL MySQL: how to convert JSON to slowlog"},"content":{"rendered":"<p>Nowadays data volumes are growing very quickly. Today Hundreds of gigabytes database is not even being considered as a huge one. Naturally cloud services like Amazon Relational Database Service (RDS) or Google Cloud SQL services can be successfully used for such cases. This is very handy, you don&#8217;t even need to spend your time tuning server side settings, but when with volumes growth the performance usually start to degrade. At this point one needs to start optimizing databases and techniques of working with it.<\/p>\n<p>We&#8217;ve been using Google Cloud SQL for MySQL quite a lot recently and indeed it&#8217;s a powerful MySQL solution. One of the most common ways to start analyzing is a slow queries log. The thing is Google uses JSON with timestamps to store them. And JSON is convenient for robots, not for humans. This is why we wrote a simple Python3 script to parse JSON files.<\/p>\n<p>You just need to grab the logs to some Linux box:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">gsutil  cp gs:\/\/slow_log\/cloudsql.googleapis.com\/mysql-slow.log\/2019\/02\/11\/* .<\/code><\/p>\n<p>And concatenate all files into on big log:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">cat *.json &gt;&gt; json_log<\/code><\/p>\n<p>To get classic and familiar format run:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">#!\/usr\/bin\/env python3\nimport json\n\nsql = \"\"\ntimestamp = \"\"\npretimestamp = \"\"\nwith open(\"json_log\") as infile:\n        for line in infile:\n            if line.strip()[0] != \"{\":\n               continue\n            k = json.loads(line)\n            sql = k['textPayload']\n            print(sql)\n            pretimestamp = k['timestamp'].strip()<\/pre>\n<p>And run<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">python js_sl.py &gt;&gt; slowlog<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Nowadays data volumes are growing very quickly. Today Hundreds of gigabytes database is not even being considered as a huge one. Naturally cloud services like Amazon Relational Database Service (RDS) or Google Cloud SQL services can be successfully used for such cases. This is very handy, you don&#8217;t even need to spend your time tuning&hellip; <\/p>\n<div class=\"readmore-wrapper\"><a href=\"https:\/\/supportex.net\/blog\/2019\/02\/google-cloud-sql-mysql-how-to-convert-json-to-slowlog\/\" class=\"more-link\">Read <\/a><\/div>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[278],"tags":[199,277],"class_list":["post-3078","post","type-post","status-publish","format-standard","hentry","category-mysql","tag-mysql-en","tag-slowlog"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Google Cloud SQL MySQL: how to convert JSON to slowlog &#8211; Supportex.NET blog<\/title>\n<meta name=\"description\" content=\"How to convert JSON to slowlog Google Cloud SQL MySQL and get slowlog analyze.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/supportex.net\/blog\/2019\/02\/google-cloud-sql-mysql-how-to-convert-json-to-slowlog\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Google Cloud SQL MySQL: how to convert JSON to slowlog &#8211; Supportex.NET blog\" \/>\n<meta property=\"og:description\" content=\"How to convert JSON to slowlog Google Cloud SQL MySQL and get slowlog analyze.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/supportex.net\/blog\/2019\/02\/google-cloud-sql-mysql-how-to-convert-json-to-slowlog\/\" \/>\n<meta property=\"og:site_name\" content=\"Supportex.NET blog\" \/>\n<meta property=\"article:published_time\" content=\"2019-02-27T16:12:39+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-05-09T09:14:29+00:00\" \/>\n<meta name=\"author\" content=\"bob\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"bob\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/supportex.net\/blog\/2019\/02\/google-cloud-sql-mysql-how-to-convert-json-to-slowlog\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/supportex.net\/blog\/2019\/02\/google-cloud-sql-mysql-how-to-convert-json-to-slowlog\/\"},\"author\":{\"name\":\"bob\",\"@id\":\"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/2425bc5aba0a9c1db43884a9f19f676d\"},\"headline\":\"Google Cloud SQL MySQL: how to convert JSON to slowlog\",\"datePublished\":\"2019-02-27T16:12:39+00:00\",\"dateModified\":\"2019-05-09T09:14:29+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/supportex.net\/blog\/2019\/02\/google-cloud-sql-mysql-how-to-convert-json-to-slowlog\/\"},\"wordCount\":191,\"commentCount\":0,\"keywords\":[\"mysql\",\"slowlog\"],\"articleSection\":[\"mysql\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/supportex.net\/blog\/2019\/02\/google-cloud-sql-mysql-how-to-convert-json-to-slowlog\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/supportex.net\/blog\/2019\/02\/google-cloud-sql-mysql-how-to-convert-json-to-slowlog\/\",\"url\":\"https:\/\/supportex.net\/blog\/2019\/02\/google-cloud-sql-mysql-how-to-convert-json-to-slowlog\/\",\"name\":\"Google Cloud SQL MySQL: how to convert JSON to slowlog &#8211; Supportex.NET blog\",\"isPartOf\":{\"@id\":\"https:\/\/supportex.net\/blog\/en\/#website\"},\"datePublished\":\"2019-02-27T16:12:39+00:00\",\"dateModified\":\"2019-05-09T09:14:29+00:00\",\"author\":{\"@id\":\"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/2425bc5aba0a9c1db43884a9f19f676d\"},\"description\":\"How to convert JSON to slowlog Google Cloud SQL MySQL and get slowlog analyze.\",\"breadcrumb\":{\"@id\":\"https:\/\/supportex.net\/blog\/2019\/02\/google-cloud-sql-mysql-how-to-convert-json-to-slowlog\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/supportex.net\/blog\/2019\/02\/google-cloud-sql-mysql-how-to-convert-json-to-slowlog\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/supportex.net\/blog\/2019\/02\/google-cloud-sql-mysql-how-to-convert-json-to-slowlog\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/supportex.net\/blog\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Google Cloud SQL MySQL: how to convert JSON to slowlog\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/supportex.net\/blog\/en\/#website\",\"url\":\"https:\/\/supportex.net\/blog\/en\/\",\"name\":\"Supportex.NET blog\",\"description\":\"Server and network management company\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/supportex.net\/blog\/en\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/2425bc5aba0a9c1db43884a9f19f676d\",\"name\":\"bob\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/affe5289af0481ab0f1461e54d1bb31b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/affe5289af0481ab0f1461e54d1bb31b?s=96&d=mm&r=g\",\"caption\":\"bob\"},\"url\":\"https:\/\/supportex.net\/blog\/author\/bob\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Google Cloud SQL MySQL: how to convert JSON to slowlog &#8211; Supportex.NET blog","description":"How to convert JSON to slowlog Google Cloud SQL MySQL and get slowlog analyze.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/supportex.net\/blog\/2019\/02\/google-cloud-sql-mysql-how-to-convert-json-to-slowlog\/","og_locale":"en_US","og_type":"article","og_title":"Google Cloud SQL MySQL: how to convert JSON to slowlog &#8211; Supportex.NET blog","og_description":"How to convert JSON to slowlog Google Cloud SQL MySQL and get slowlog analyze.","og_url":"https:\/\/supportex.net\/blog\/2019\/02\/google-cloud-sql-mysql-how-to-convert-json-to-slowlog\/","og_site_name":"Supportex.NET blog","article_published_time":"2019-02-27T16:12:39+00:00","article_modified_time":"2019-05-09T09:14:29+00:00","author":"bob","twitter_misc":{"Written by":"bob","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/supportex.net\/blog\/2019\/02\/google-cloud-sql-mysql-how-to-convert-json-to-slowlog\/#article","isPartOf":{"@id":"https:\/\/supportex.net\/blog\/2019\/02\/google-cloud-sql-mysql-how-to-convert-json-to-slowlog\/"},"author":{"name":"bob","@id":"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/2425bc5aba0a9c1db43884a9f19f676d"},"headline":"Google Cloud SQL MySQL: how to convert JSON to slowlog","datePublished":"2019-02-27T16:12:39+00:00","dateModified":"2019-05-09T09:14:29+00:00","mainEntityOfPage":{"@id":"https:\/\/supportex.net\/blog\/2019\/02\/google-cloud-sql-mysql-how-to-convert-json-to-slowlog\/"},"wordCount":191,"commentCount":0,"keywords":["mysql","slowlog"],"articleSection":["mysql"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/supportex.net\/blog\/2019\/02\/google-cloud-sql-mysql-how-to-convert-json-to-slowlog\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/supportex.net\/blog\/2019\/02\/google-cloud-sql-mysql-how-to-convert-json-to-slowlog\/","url":"https:\/\/supportex.net\/blog\/2019\/02\/google-cloud-sql-mysql-how-to-convert-json-to-slowlog\/","name":"Google Cloud SQL MySQL: how to convert JSON to slowlog &#8211; Supportex.NET blog","isPartOf":{"@id":"https:\/\/supportex.net\/blog\/en\/#website"},"datePublished":"2019-02-27T16:12:39+00:00","dateModified":"2019-05-09T09:14:29+00:00","author":{"@id":"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/2425bc5aba0a9c1db43884a9f19f676d"},"description":"How to convert JSON to slowlog Google Cloud SQL MySQL and get slowlog analyze.","breadcrumb":{"@id":"https:\/\/supportex.net\/blog\/2019\/02\/google-cloud-sql-mysql-how-to-convert-json-to-slowlog\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/supportex.net\/blog\/2019\/02\/google-cloud-sql-mysql-how-to-convert-json-to-slowlog\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/supportex.net\/blog\/2019\/02\/google-cloud-sql-mysql-how-to-convert-json-to-slowlog\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/supportex.net\/blog\/en\/"},{"@type":"ListItem","position":2,"name":"Google Cloud SQL MySQL: how to convert JSON to slowlog"}]},{"@type":"WebSite","@id":"https:\/\/supportex.net\/blog\/en\/#website","url":"https:\/\/supportex.net\/blog\/en\/","name":"Supportex.NET blog","description":"Server and network management company","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/supportex.net\/blog\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/2425bc5aba0a9c1db43884a9f19f676d","name":"bob","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/affe5289af0481ab0f1461e54d1bb31b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/affe5289af0481ab0f1461e54d1bb31b?s=96&d=mm&r=g","caption":"bob"},"url":"https:\/\/supportex.net\/blog\/author\/bob\/"}]}},"_links":{"self":[{"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/posts\/3078","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/comments?post=3078"}],"version-history":[{"count":8,"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/posts\/3078\/revisions"}],"predecessor-version":[{"id":3106,"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/posts\/3078\/revisions\/3106"}],"wp:attachment":[{"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/media?parent=3078"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/categories?post=3078"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/tags?post=3078"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}