1"use strict";(self.webpackChunkmy_website=self.webpackChunkmy_website||[]).push([[7916],{3905:(e,t,a)=>{a.d(t,{Zo:()=>u,kt:()=>m});var n=a(67294);function o(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function r(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,n)}return a}function l(e){for(var t=1;t<arguments.length;t++){var a=null!=arguments[t]?arguments[t]:{};t%2?r(Object(a),!0).forEach((function(t){o(e,t,a[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):r(Object(a)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(a,t))}))}return e}function i(e,t){if(null==e)return{};var a,n,o=function(e,t){if(null==e)return{};var a,n,o={},r=Object.keys(e);for(n=0;n<r.length;n++)a=r[n],t.indexOf(a)>=0||(o[a]=e[a]);return o}(e,t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);for(n=0;n<r.length;n++)a=r[n],t.indexOf(a)>=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(o[a]=e[a])}return o}var s=n.createContext({}),p=function(e){var t=n.useContext(s),a=t;return e&&(a="function"==typeof e?e(t):l(l({},t),e)),a},u=function(e){var t=p(e.components);return n.createElement(s.Provider,{value:t},e.children)},g="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},c=n.forwardRef((function(e,t){var a=e.components,o=e.mdxType,r=e.originalType,s=e.parentName,u=i(e,["components","mdxType","originalType","parentName"]),g=p(a),c=o,m=g["".concat(s,".").concat(c)]||g[c]||d[c]||r;return a?n.createElement(m,l(l({ref:t},u),{},{components:a})):n.createElement(m,l({ref:t},u))}));function m(e,t){var a=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var r=a.length,l=new Array(r);l[0]=c;var i={};for(var s in t)hasOwnProperty.call(t,s)&&(i[s]=t[s]);i.originalType=e,i[g]="string"==typeof e?e:o,l[1]=i;for(var p=2;p<r;p++)l[p]=a[p];return n.createElement.apply(null,l)}return n.createElement.apply(null,a)}c.displayName="MDXCreateElement"},11698:(e,t,a)=>{a.r(t),a.d(t,{assets:()=>s,contentTitle:()=>l,default:()=>d,frontMatter:()=>r,metadata:()=>i,toc:()=>p});var n=a(87462),o=(a(67294),a(3905));const r={id:"MySQL",title:"MySQL",overview:"MySQL is an open-source relational database management system. Filebeat is often the easiest way to get logs from your system to Logz.io. Logz.io has a dedicated configuration wizard to make it simple to configure Filebeat. If you already have Filebeat and you want to add new sources, check out our other shipping instructions to copy&paste just the relevant changes from our code examples.",product:["metrics"],os:["windows","linux"],filters:["Database"],recommendedFor:["Software Engineer"],logo:"https://logzbucket.s3.eu-west-1.amazonaws.com/logz-docs/shipper-logos/mysql.svg",logs_dashboards:[],logs_alerts:[],logs2metrics:[],metrics_dashboards:["2zMVEOdWnIMgOPATDLByX7"],metrics_alerts:[],drop_filter:[]},l=void 0,i={unversionedId:"shipping/Database/MySQL",id:"shipping/Database/MySQL",title:"MySQL",description:"Logs",source:"@site/docs/shipping/Database/mysql.md",sourceDirName:"shipping/Database",slug:"/shipping/Database/MySQL",permalink:"/docs/shipping/Database/MySQL",draft:!1,editUrl:"https://github.com/logzio/documentation/tree/master/docs/shipping/Database/mysql.md",tags:[],version:"current",frontMatter:{id:"MySQL",title:"MySQL",overview:"MySQL is an open-source relational database management system. Filebeat is often the easiest way to get logs from your system to Logz.io. Logz.io has a dedicated configuration wizard to make it simple to configure Filebeat. If you already have Filebeat and you want to add new sources, check out our other shipping instructions to copy&paste just the relevant changes from our code examples.",product:["metrics"],os:["windows","linux"],filters:["Database"],recommendedFor:["Software Engineer"],logo:"https://logzbucket.s3.eu-west-1.amazonaws.com/logz-docs/shipper-logos/mysql.svg",logs_dashboards:[],logs_alerts:[],logs2metrics:[],metrics_dashboards:["2zMVEOdWnIMgOPATDLByX7"],metrics_alerts:[],drop_filter:[]},sidebar:"tutorialSidebar",previous:{title:"Microsoft SQL Server",permalink:"/docs/shipping/Database/Microsoft-SQL-Server"},next:{title:"PgBouncer",permalink:"/docs/shipping/Database/PgBouncer"}},s={},p=[{value:"Logs",id:"logs",level:2},{value:"Default configuration",id:"default-configuration",level:3},{value:"Configure MySQL to write general query logs",id:"configure-mysql-to-write-general-query-logs",level:4},{value:"Download the Logz.io public certificate",id:"download-the-logzio-public-certificate",level:3},{value:"Add MySQL as an input in your Filebeat configuration",id:"add-mysql-as-an-input-in-your-filebeat-configuration",level:4},{value:"Preconfigured log types",id:"preconfigured-log-types",level:5},{value:"Set Logz.io as the output",id:"set-logzio-as-the-output",level:4},{value:"Start Filebeat",id:"start-filebeat",level:4},{value:"Check Logz.io for your logs",id:"check-logzio-for-your-logs",level:4},{value:"Set up a Docker sidecar for MySQL",id:"set-up-a-docker-sidecar-for-mysql",level:3},{value:"Pull the Docker image",id:"pull-the-docker-image",level:4},{value:"Run the Docker image",id:"run-the-docker-image",level:4},{value:"Parameters",id:"parameters",level:5},{value:"Check Logz.io for your logs",id:"check-logzio-for-your-logs-1",level:4},{value:"Metrics",id:"metrics",level:2},{value:"Configure Telegraf to send your metrics data to Logz.io",id:"configure-telegraf-to-send-your-metrics-data-to-logzio",level:3},{value:"Set up Telegraf v1.17 or higher",id:"set-up-telegraf-v117-or-higher",level:4},{value:"Add the inputs.mysql plug-in",id:"add-the-inputsmysql-plug-in",level:4},{value:"Add the outputs.http plug-in",id:"add-the-outputshttp-plug-in",level:4},{value:"Start Telegraf",id:"start-telegraf",level:3},{value:"On Windows:",id:"on-windows",level:6},{value:"On MacOS:",id:"on-macos",level:6},{value:"On Linux:",id:"on-linux",level:6},{value:"Check Logz.io for your metrics",id:"check-logzio-for-your-metrics",level:3}],u={toc:p},g="wrapper";
1function d(e){let{components:t,...a}=e;return(0,o.kt)(g,(0,n.Z)({},u,a,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("h2",{id:"logs"},"Logs"),(0,o.kt)("admonition",{type:"note"},(0,o.kt)("p",{parentName:"admonition"},(0,o.kt)("a",{parentName:"p",href:"https://github.com/logzio/logzio-mysql-logs/"},"Project's GitHub repo"))),(0,o.kt)("h3",{id:"default-configuration"},"Default configuration"),(0,o.kt)("p",null,(0,o.kt)("strong",{parentName:"p"},"Before you begin, you'll need"),":"),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},(0,o.kt)("a",{parentName:"li",href:"https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-installation.html"},"Filebeat")," installed"),(0,o.kt)("li",{parentName:"ul"},"Port 5015 open")),(0,o.kt)("h4",{id:"configure-mysql-to-write-general-query-logs"},"Configure MySQL to write general query logs"),(0,o.kt)("p",null,"In the MySQL configuration file (/etc/mysql/my.cnf),\npaste these lines:"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre"},"general_log_file = /var/log/mysql/mysql.log\ngeneral_log= 1\nlog_slow_queries = /var/log/mysql/mysql-slow.log\nlong_query_time = 1\nlog-queries-not-using-indexes = 1\n")),(0,o.kt)("p",null,"Restart MySQL:"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-shell"},"sudo /etc/init.d/mysql restart\n")),(0,o.kt)("h3",{id:"download-the-logzio-public-certificate"},"Download the Logz.io public certificate"),(0,o.kt)("p",null,"For HTTPS shipping, download the Logz.io public certificate to your certificate authority folder."),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-shell"},"sudo curl https://raw.githubusercontent.com/logzio/public-certificates/master/AAACertificateServices.crt --create-dirs -o /etc/pki/tls/certs/AAACertificateServices.crt\n")),(0,o.kt)("h4",{id:"add-mysql-as-an-input-in-your-filebeat-configuration"},"Add MySQL as an input in your Filebeat configuration"),(0,o.kt)("p",null,"In the Filebeat configuration file (/etc/filebeat/filebeat.yml), add MySQL to the filebeat.inputs section."),(0,o.kt)("p",null,"Replace ",(0,o.kt)("inlineCode",{parentName:"p"},"<<LOG-SHIPPING-TOKEN>>")," with the token of the account you want to ship to."),(0,o.kt)("admonition",{type:"note"},(0,o.kt)("p",{parentName:"admonition"},"Filebeat requires a file extension specified for the log input.")),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-yaml"},"# ...\nfilebeat.inputs:\n- type: filestream\n paths:\n - /var/log/mysql/mysql.log\n\n fields:\n logzio_codec: plain\n\n # You can manage your tokens at\n # https://app.logz.io/#/dashboard/settings/manage-tokens/log-shipping\n token: <<LOG-SHIPPING-TOKEN>>\n type: mysql\n fields_under_root: true\n encoding: utf-8\n ignore_older: 3h\n\n- type: filestream\n paths:\n - /var/log/mysql/mysql-slow.log\n\n fields:\n logzio_codec: plain\n\n # You can manage your tokens at\n # https://app.logz.io/#/dashboard/settings/manage-tokens/log-shipping\n token: <<LOG-SHIPPING-TOKEN>>\n type: mysql_slow_query\n fields_under_root: true\n encoding: utf-8\n ignore_older: 3h\n multiline:\n pattern: '^# Time:'\n negate: true\n match: after\n\n- type: filestream\n paths:\n - /var/log/mysql/error.log\n\n fields:\n logzio_codec: plain\n\n # You can manage your tokens at\n # https://app.logz.io/#/dashboard/settings/manage-tokens/log-shipping\n token: <<LOG-SHIPPING-TOKEN>>\n type: mysql_error\n fields_under_root: true\n encoding: utf-8\n ignore_older: 3h\n")),(0,o.kt)("p",null,"If you're running Filebeat 7 to 8.1, paste the code block below instead:"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-yaml"},"# ...\nfilebeat.inputs:\n- type: log\n paths:\n - /var/log/mysql/mysql.log\n\n fields:\n logzio_codec: plain\n\n # You can manage your tokens at\n # https://app.logz.io/#/dashboard/settings/manage-tokens/log-shipping\n token: <<LOG-SHIPPING-TOKEN>>\n type: mysql\n fields_under_root: true\n encoding: utf-8\n ignore_older: 3h\n\n- type: log\n paths:\n - /var/log/mysql/mysql-slow.log\n\n fields:\n logzio_codec: plain\n\n # You can manage your tokens at\n # https://app.logz.io/#/dashboard/settings/manage-tokens/log-shipping\n token: <<LOG-SHIPPING-TOKEN>>\n type: mysql_slow_query\n fields_under_root: true\n encoding: utf-8\n ignore_older: 3h\n multiline:\n pattern: '^# Time:'\n negate: true\n match: after\n\n- type: log\n paths:\n - /var/log/mysql/error.log\n\n fields:\n logzio_codec: plain\n\n # You can manage your tokens at\n # https://app.logz.io/#/dashboard/settings/manage-tokens/log-shipping\n token: <<LOG-SHIPPING-TOKEN>>\n type: mysql_error\n fields_under_root: true\n encoding: utf-8\n ignore_older: 3h\n")),(0,o.kt)("h5",{id:"preconfigured-log-types"},"Preconfigured log types"),(0,o.kt)("table",null,(0,o.kt)("thead",{parentName:"table"},(0,o.kt)("tr",{parentName:"thead"},(0,o.kt)("th",{parentName:"tr",align:null},"Parameter"),(0,o.kt)("th",{parentName:"tr",align:null},"Log Type"),(0,o.kt)("th",{parentName:"tr",align:null},"Default log location"))),(0,o.kt)("tbody",{parentName:"table"},(0,o.kt)("tr",{parentName:"tbody"},(0,o.kt)("td",{parentName:"tr",align:null},"General query log"),(0,o.kt)("td",{parentName:"tr",align:null},(0,o.kt)("inlineCode",{parentName:"td"},"mysql")),(0,o.kt)("td",{parentName:"tr",align:null},(0,o.kt)("inlineCode",{parentName:"td"},"/var/log/mysql/mysql.log"))),(0,o.kt)("tr",{parentName:"tbody"},(0,o.kt)("td",{parentName:"tr",align:null},"Slow query log"),(0,o.kt)("td",{parentName:"tr",align:null},(0,o.kt)("inlineCode",{parentName:"td"},"mysql_slow_query")),(0,o.kt)("td",{parentName:"tr",align:null},(0,o.kt)("inlineCode",{parentName:"td"},"/var/log/mysql/mysql-slow.log"))),(0,o.kt)("tr",{parentName:"tbody"},(0,o.kt)("td",{parentName:"tr",align:null},"Error log"),(0,o.kt)("td",{parentName:"tr",align:null},(0,o.kt)("inlineCode",{parentName:"td"},"mysql_error")),(0,o.kt)("td",{parentName:"tr",align:null},(0,o.kt)("inlineCode",{parentName:"td"},"/var/log/mysql/error.log"))))),(0,o.kt)("p",null,"The log type is used to apply the appropriate Logz.io preconfigured parsing pipeline so that your logs will be automatically parsed."),(0,o.kt)("h4",{id:"set-logzio-as-the-output"},"Set Logz.io as the output"),(0,o.kt)("p",null,"If Logz.io is not an output, add it now.\nRemove all other outputs."),(0,o.kt)("p",null,"Replace ",(0,o.kt)("inlineCode",{parentName:"p"},"<<LISTENER-HOST>>")," with the host ",(0,o.kt)("a",{parentName:"p",href:"https://docs.logz.io/docs/user-guide/admin/hosting-regions/account-region/#available-regions"},"for your region"),". "),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-yaml"},"# ...\noutput.logstash:\n hosts: [\"<<LISTENER-HOST>>:5015\"]\n ssl:\n certificate_authorities: ['/etc/pki/tls/certs/AAACertificateServices.crt']\n")),(0,o.kt)("h4",{id:"start-filebeat"},"Start Filebeat"),(0,o.kt)("p",null,(0,o.kt)("a",{parentName:"p",href:"https://www.elastic.co/guide/en/beats/filebeat/master/filebeat-starting.html"},"Start or restart Filebeat")," for the changes to take effect."),(0,o.kt)("h4",{id:"check-logzio-for-your-logs"},"Check Logz.io for your logs"),(0,o.kt)("p",null,"Give your logs some time to get from your system to ours, and then open ",(0,o.kt)("a",{parentName:"p",href:"https://app.logz.io/#/dashboard/osd"},"Open Search Dashboards"),"."),(0,o.kt)("p",null,"If you still don't see your logs, see ",(0,o.kt)("a",{parentName:"p",href:"https://docs.logz.io/docs/user-guide/log-management/troubleshooting/troubleshooting-filebeat/"},"Filebeat troubleshooting"),"."),(0,o.kt)("h3",{id:"set-up-a-docker-sidecar-for-mysql"},"Set up a Docker sidecar for MySQL"),(0,o.kt)("p",null,"MySQL is an open-source relational database management system. Docker sidecar is a container that runs on the same Pod as the application container. This integration allows you to send your MySQL logs to your Logz.io account using a Docker sidecar. "),(0,o.kt)("h4",{id:"pull-the-docker-image"},"Pull the Docker image"),(0,o.kt)("p",null,"Download the logzio/mysql-logs image:"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-shell"},"docker pull logzio/mysql-logs\n")),(0,o.kt)("h4",{id:"run-the-docker-image"},"Run the Docker image"),(0,o.kt)("p",null,"For a complete list of options, see the parameters below the code block.\ud83d\udc47"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-shell"},'docker run -d --name logzio-mysql-logs \\\n-e LOGZIO_TOKEN="<<LOG-SHIPPING-TOKEN>>" \\\n-e LOGZIO_LISTENER_HOST="<<LISTENER-HOST>>" \\\n-v /var/log/logzio:/var/log/logzio \\\n-v /var/log/mysql:/var/log/mysql \\\nlogzio/mysql-logs:latest\n')),(0,o.kt)("h5",{id:"parameters"},"Parameters"),(0,o.kt)("table",null,(0,o.kt)("thead",{parentName:"table"},(0,o.kt)("tr",{parentName:"thead"},(0,o.kt)("th",{parentName:"tr",align:null},"Parameter"),(0,o.kt)("th",{parentName:"tr",align:null},"Description"),(0,o.kt)("th",{parentName:"tr",align:null},"Required/Default"))),(0,o.kt)("tbody",{parentName:"table"},(0,o.kt)("tr",{parentName:"tbody"},(0,o.kt)("td",{parentName:"tr",align:null},"LOGZIO_TOKEN"),(0,o.kt)("td",{parentName:"tr",align:null},"Your Logz.io log shipping token directs the data securely to your Logz.io Log Management account. The default token is auto-populated in the examples when you're logged into the Logz.io app as an ",(0,o.kt)("strong",{parentName:"td"},"Admin"),". ",(0,o.kt)("a",{parentName:"td",href:"https://app.logz.io/#/dashboard/settings/manage-tokens/data-shipping"},"Manage your tokens"),"."),(0,o.kt)("td",{parentName:"tr",align:null},"Required")),(0,o.kt)("tr",{parentName:"tbody"},(0,o.kt)("td",{parentName:"tr",align:null},"LOGZIO_LISTENER"),(0,o.kt)("td",{parentName:"tr",align:null},"Listener URL. Replace ",(0,o.kt)("inlineCode",{parentName:"td"},"<<LISTENER-HOST>>")," with the host ",(0,o.kt)("a",{parentName:"td",href:"https://docs.logz.io/docs/user-guide/admin/hosting-regions/account-region/#available-regions"},"for your region"),". The required port depends whether HTTP or HTTPS is used: HTTP = 8070, HTTPS = 8071."),(0,o.kt)("td",{parentName:"tr",align:null},(0,o.kt)("inlineCode",{parentName:"td"},"listener.logz.io"))),(0,o.kt)("tr",{parentName:"tbody"},(0,o.kt)("td",{parentName:"tr",align:null},"MYSQL_ERROR_LOG_FILE"),(0,o.kt)("td",{parentName:"tr",align:null},"The path to MySQL error log."),(0,o.kt)("td",{parentName:"tr",align:null},"Optional. ",(0,o.kt)("inlineCode",{parentName:"td"},"/var/log/mysql/error.log"))),(0,o.kt)("tr",{parentName:"tbody"},(0,o.kt)("td",{parentName:"tr",align:null},"MYSQL_SLOW_LOG_FILE"),(0,o.kt)("td",{parentName:"tr",align:null},"The path to MySQL slow query log."),(0,o.kt)("td",{parentName:"tr",align:null},"Optional. ",(0,o.kt)("inlineCode",{parentName:"td"},"/var/log/mysql/mysql-slow.log"))),(0,o.kt)("tr",{parentName:"tbody"},(0,o.kt)("td",{parentName:"tr",align:null},"MYSQL_LOG_FILE"),(0,o.kt)("td",{parentName:"tr",align:null},"The path to MySQL general log."),(0,o.kt)("td",{parentName:"tr",align:null},"Optional. ",(0,o.kt)("inlineCode",{parentName:"td"},"/var/log/mysql/mysql.log"))))),(0,o.kt)("p",null,"Below is an example configuration for running the Docker
1container:"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-bash"},'docker run -d \\\n --name logzio-mysql-logs \\\n -e LOGZIO_TOKEN="<<LOG-SHIPPING-TOKEN>>" \\\n -v /path/to/directory/logzio:/var/log/logzio \\\n -v /path/to/directory/mysql:/var/log/mysql \\\n --restart=always \\\n logzio/mysql-logs:latest\n')),(0,o.kt)("h4",{id:"check-logzio-for-your-logs-1"},"Check Logz.io for your logs"),(0,o.kt)("p",null,"Give your logs some time to get from your system to ours, and then open ",(0,o.kt)("a",{parentName:"p",href:"https://app.logz.io/#/dashboard/osd"},"Open Search Dashboards"),"."),(0,o.kt)("p",null,"If you still don't see your logs, see ",(0,o.kt)("a",{parentName:"p",href:"https://docs.logz.io/docs/user-guide/log-management/troubleshooting/troubleshooting-filebeat/"},"Filebeat troubleshooting"),"."),(0,o.kt)("h2",{id:"metrics"},"Metrics"),(0,o.kt)("p",null,"To send your Prometheus-format MySQL metrics to Logz.io, you need to add the ",(0,o.kt)("strong",{parentName:"p"},"inputs.mysql")," and ",(0,o.kt)("strong",{parentName:"p"},"outputs.http")," plug-ins to your Telegraf configuration file."),(0,o.kt)("h3",{id:"configure-telegraf-to-send-your-metrics-data-to-logzio"},"Configure Telegraf to send your metrics data to Logz.io"),(0,o.kt)("h4",{id:"set-up-telegraf-v117-or-higher"},"Set up Telegraf v1.17 or higher"),(0,o.kt)("p",null,(0,o.kt)("strong",{parentName:"p"},"For Windows")),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-shell"},"wget https://dl.influxdata.com/telegraf/releases/telegraf-1.27.3_windows_amd64.zip\n")),(0,o.kt)("p",null,"After downloading the archive, extract its content into ",(0,o.kt)("inlineCode",{parentName:"p"},"C:\\Program Files\\Logzio\\telegraf\\"),"."),(0,o.kt)("p",null,"The configuration file is located at ",(0,o.kt)("inlineCode",{parentName:"p"},"C:\\Program Files\\Logzio\\telegraf\\"),"."),(0,o.kt)("p",null,(0,o.kt)("strong",{parentName:"p"},"For MacOS")),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-shell"},"brew install telegraf\n")),(0,o.kt)("p",null,"The configuration file is located at ",(0,o.kt)("inlineCode",{parentName:"p"},"/usr/local/etc/telegraf.conf"),"."),(0,o.kt)("p",null,(0,o.kt)("strong",{parentName:"p"},"For Linux")),(0,o.kt)("p",null,(0,o.kt)("em",{parentName:"p"},"Ubuntu & Debian")),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-shell"},"sudo apt-get update && sudo apt-get install telegraf\n")),(0,o.kt)("p",null,"The configuration file is located at ",(0,o.kt)("inlineCode",{parentName:"p"},"/etc/telegraf/telegraf.conf"),"."),(0,o.kt)("p",null,(0,o.kt)("em",{parentName:"p"},"RedHat and CentOS")),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-shell"},"sudo yum install telegraf\n")),(0,o.kt)("p",null,"The configuration file is located at ",(0,o.kt)("inlineCode",{parentName:"p"},"/etc/telegraf/telegraf.conf"),"."),(0,o.kt)("p",null,(0,o.kt)("em",{parentName:"p"},"SLES & openSUSE")),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-shell"},"# add go repository\nzypper ar -f obs://devel:languages:go/ go\n# install latest telegraf\nzypper in telegraf\n")),(0,o.kt)("p",null,"The configuration file is located at ",(0,o.kt)("inlineCode",{parentName:"p"},"/etc/telegraf/telegraf.conf"),"."),(0,o.kt)("p",null,(0,o.kt)("em",{parentName:"p"},"FreeBSD/PC-BSD")),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-shell"},"sudo pkg install telegraf\n")),(0,o.kt)("p",null,"The configuration file is located at ",(0,o.kt)("inlineCode",{parentName:"p"},"/etc/telegraf/telegraf.conf"),"."),(0,o.kt)("h4",{id:"add-the-inputsmysql-plug-in"},"Add the inputs.mysql plug-in"),(0,o.kt)("p",null,"First you need to configure the input plug-in to enable Telegraf to scrape the MySQL data from your hosts. To do this, add the following code to the configuration file:"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-ini"},'[[inputs.mysql]]\n servers = ["<<USER-NAME>>:<<PASSWORD>>@<<PROTOCOL>>(<<ADDRESS>>)/?tls=false"]\n ## e.g.\n ## servers = ["user:passwd@tcp(127.0.0.1:3306)/?tls=false"]\n ## servers = ["user@tcp(127.0.0.1:3306)/?tls=false"]\n metric_version = 2\n # gather metrics from INFORMATION_SCHEMA.TABLES for databases provided above list\n gather_table_schema = true\n\n # gather thread state counts from INFORMATION_SCHEMA.PROCESSLIST\n gather_process_list = true\n\n # gather user statistics from INFORMATION_SCHEMA.USER_STATISTICS\n gather_user_statistics = true\n\n # gather auto_increment columns and max values from information schema\n gather_info_schema_auto_inc = true\n\n # gather metrics from INFORMATION_SCHEMA.INNODB_METRICS\n gather_innodb_metrics = true\n\n # gather metrics from SHOW SLAVE STATUS command output\n gather_slave_status = true\n\n # gather metrics from SHOW BINARY LOGS command output\n gather_binary_logs = true\n\n # gather metrics from SHOW GLOBAL VARIABLES command output\n gather_global_variables = true\n\n # gather metrics from PERFORMANCE_SC
1HEMA.TABLE_IO_WAITS_SUMMARY_BY_TABLE\n gather_table_io_waits = true\n\n # gather metrics from PERFORMANCE_SCHEMA.TABLE_LOCK_WAITS\n gather_table_lock_waits = true\n\n # gather metrics from PERFORMANCE_SCHEMA.TABLE_IO_WAITS_SUMMARY_BY_INDEX_USAGE\n gather_index_io_waits = true\n\n # gather metrics from PERFORMANCE_SCHEMA.EVENT_WAITS\n gather_event_waits = true\n\n # gather metrics from PERFORMANCE_SCHEMA.FILE_SUMMARY_BY_EVENT_NAME\n gather_file_events_stats = true\n\n # gather metrics from PERFORMANCE_SCHEMA.EVENTS_STATEMENTS_SUMMARY_BY_DIGEST\n gather_perf_events_statements = true\n\n # gather metrics from PERFORMANCE_SCHEMA.EVENTS_STATEMENTS_SUMMARY_BY_ACCOUNT_BY_EVENT_NAME\n gather_perf_sum_per_acc_per_event = true\n')),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},"Replace ",(0,o.kt)("inlineCode",{parentName:"li"},"<<USER-NAME>>")," with the user name for your MySQL database."),(0,o.kt)("li",{parentName:"ul"},"Replace ",(0,o.kt)("inlineCode",{parentName:"li"},"<<PASSWORD>>")," with the password for your MySQL database."),(0,o.kt)("li",{parentName:"ul"},"Replace ",(0,o.kt)("inlineCode",{parentName:"li"},"<<PROTOCOL>>")," with the name of your shipping protocol (tcp protocol recommended)."),(0,o.kt)("li",{parentName:"ul"},"Replace ",(0,o.kt)("inlineCode",{parentName:"li"},"<<ADDRESS>>")," with the address of your MySQL database host. This is ",(0,o.kt)("inlineCode",{parentName:"li"},"localhost")," if installed locally.")),(0,o.kt)("admonition",{type:"note"},(0,o.kt)("p",{parentName:"admonition"},"The full list of data scraping and configuring options can be found ",(0,o.kt)("a",{parentName:"p",href:"https://github.com/influxdata/telegraf/blob/release-1.18/plugins/inputs/mysql/README.md"},"here"))),(0,o.kt)("h4",{id:"add-the-outputshttp-plug-in"},"Add the outputs.http plug-in"),(0,o.kt)("p",null,"After you create the configuration file, configure the output plug-in to enable Telegraf to send your data to Logz.io in Prometheus-format. To do this, add the following code to the configuration file:"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-ini"},'[[outputs.http]]\n url = "https://<<LISTENER-HOST>>:8053"\n data_format = "prometheusremotewrite"\n [outputs.http.headers]\n Content-Type = "application/x-protobuf"\n Content-Encoding = "snappy"\n X-Prometheus-Remote-Write-Version = "0.1.0"\n Authorization = "Bearer <<PROMETHEUS-METRICS-SHIPPING-TOKEN>>"\n')),(0,o.kt)("p",null,"Replace the placeholders to match your specifics. (They are indicated by the double angle brackets ",(0,o.kt)("inlineCode",{parentName:"p"},"<< >>"),"):"),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},"Replace ",(0,o.kt)("inlineCode",{parentName:"li"},"<<LISTENER-HOST>>")," with the Logz.io Listener URL ",(0,o.kt)("a",{parentName:"li",href:"https://docs.logz.io/docs/user-guide/admin/hosting-regions/account-region/#available-regions"},"for your region"),", configured to use port ",(0,o.kt)("strong",{parentName:"li"},"8052")," for http traffic, or port ",(0,o.kt)("strong",{parentName:"li"},"8053")," for https traffic."),(0,o.kt)("li",{parentName:"ul"},"Replace ",(0,o.kt)("inlineCode",{parentName:"li"},"<<PROMETHEUS-METRICS-SHIPPING-TOKEN>>")," with a ",(0,o.kt)("a",{parentName:"li",href:"https://app.logz.io/#/dashboard/settings/manage-accounts"},"token")," for the Metrics account you want to ship to. ",(0,o.kt)("a",{parentName:"li",href:"https://docs.logz.io/docs/user-guide/admin/authentication-tokens/finding-your-metrics-account-token/"},"Look up your Metrics token."))),(0,o.kt)("h3",{id:"start-telegraf"},"Start Telegraf"),(0,o.kt)("h6",{id:"on-windows"},"On Windows:"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-shell"},"telegraf.exe --service start\n")),(0,o.kt)("h6",{id:"on-macos"},"On MacOS:"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-shell"},"telegraf --config telegraf.conf\n")),(0,o.kt)("h6",{id:"on-linux"},"On Linux:"),(0,o.kt)("p",null,(0,o.kt)("strong",{parentName:"p"},"Linux (sysvinit and upstart installations)")),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-shell"},"sudo service telegraf start\n")),(0,o.kt)("p",null,(0,o.kt)("strong",{parentName:"p"},"Linux (systemd installations)")),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-shell"},"systemctl start telegraf\n")),(0,o.kt)("h3",{id:"check-logzio-for-your-metrics"},"Check Logz.io for your metrics"),(0,o.kt)("p",null,"Install the pre-built dashboard to enhance the observability of your metrics."),(0,o.kt)("p",null,"To view the metrics on the main dashboard, log in to your Logz.io Metrics account, and open ",(0,o.kt)("a",{parentName:"p",href:"https://app.logz.io/#/dashboard/metrics/"},"the Logz.io Metrics tab"),"."))}d.isMDXComponent=!0}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.