Project: HertzBeat (Observability and Analysis / Observability)
File: extend-jdbc.md

id: extend-jdbc title: JDBC Protocol Custom Monitoring sidebar_label: JDBC Protocol Custom Monitoring From , you are familiar with how to customize types, Metrics, protocols, etc. Here we will introduce in detail how to use JDBC(support mysql,mariadb,postgresql,sqlserver at present) to customize Metric monitoring. JDBC protocol custom monitoring allows us to easily monitor Metrics we want by writing SQL query statement. System directly connected to MYSQL->Run SQL query statement->parse reponse data: oneRow, multiRow, columns->Metric data extraction It can be seen from the process that we define a monitoring type of JDBC protocol. We need to configure SSH request parameters, configure which Metrics to obtain, and configure query SQL statements. We can obtain the corresponding Metric data through the data fields queried by SQL and the Metric mapping we need. At present, there are three mapping parsing methodsoneRow, multiRow, columns. Query a row of data, return the column name of the result set through query and map them to the queried field. eg queried Metric fieldsone two three four query SQLselect one, two, three, four from book limit 1; Here the Metric field and the response data can be mapped into a row of collected data one by one. Query multiple rows of data, return the column names of the result set and map them to the queried fields. eg queried Metric fieldsone two three four query SQLselect one, two, three, four from book; Here the Metric field and the response data can be mapped into multiple rows of collected data one by one. Collect a row of Metric data. By matching the two columns of queried data (key value), key and the queried field, value is the value of the query field. eg queried fieldsone two three four query SQLselect key, value from book; SQL response data | key | value | ||-| | one | 243 | | two | 435 | | three | 332 | | four | 643 | Here by mapping the Metric field with the key of the response data, we can obtain the corresponding value as collection and monitoring

HertzBeat Dashboard -> Monitoring Templates -> New Template -> Config Monitoring Template Yml -> Save and Apply -> Add A Monitoring with The New Monitoring Type Configuration usages of the monitoring templates yml are detailed below. We define all monitoring collection types (mysql,jvm,k8s) as yml monitoring templates, and users can import these templates to support corresponding types of monitoring. Monitoring template is used to define the name of monitoring type(international), request parameter mapping, index information, collection protocol configuration information, etc. egDefine a custom monitoring type `app` named `example_sql` which use the JDBC protocol to collect data. ```yaml category: db app: example_sql name: zh-CN: MYSQL en-US: MYSQL EXAMPLE APP params: field: host name: zh-CN: Host en-US: Host type: host required: true field: port name: zh-CN: en-US: Port type: number range: '[0,65535]' required: true defaultValue: 80 placeholder: 'Please enter the port' field: database name: zh-CN: en-US: Database type: text required: false field: username name: zh-CN: en-US: Username type: text limit: 20 required: false field: password name: zh-CN: en-US: Password type: password required: false field: url name: zh-CN: Url en-US: Url type: text required: false metrics: name: basic priority: 0 fields: field: version type: 1 label: true field: port type: 1 field: datadir type: 1 field: max_connections type: 0 aliasFields: version versioncompileos versioncompilemachine port datadir max_connections calculates: port=port datadir=datadir maxconnections=maxconnections version=version+""+versioncompileos+""+versioncompilemachine protocol: jdbc jdbc: host: ^^host^^ port: ^^port^^ platform: mysql username: ^^username^^ password: ^^password^^ database: ^^database^^ queryType: columns sql: show global variables where Variablename like 'version%' or Variablename = 'maxconnections' or Variablename = 'datadir' or Variable_name = 'port'; url: ^^url^^ name: status priority: 1 fields: field: threads_created type: 0 field: threads_connected type: 0 field: threads_cached type: 0 field: threads_running type: 0 aliasFields: threads_created threads_connected threads_cached threads_running calculates: threadscreated=threadscreated threadsconnected=threadsconnected threadscached=threadscached threadsrunning=threadsrunning protocol: jdbc jdbc: host: ^^host^^ port: ^^port^^ platform: mysql username: ^^username^^ password: ^^password^^ database: ^^database^^ queryType: columns sql: show global status where Variablename like 'thread%' or Variablename = 'comcommit' or Variablename = 'comrollback' or Variablename = 'questions' or Variable_name = 'uptime'; url: ^^url^^ name: innodb priority: 2 fields: field: innodbdatareads type: 0 unit: times field: innodbdatawrites type: 0 unit: times field: innodbdataread type: 0 unit: kb field: innodbdatawritten type: 0 unit: kb protocol: jdbc jdbc: host: ^^host^^ port: ^^port^^ platform: mysql username: ^^username^^ password: ^^password^^ database: ^^database^^ queryType: columns sql: show global status where Variable_name like 'innodb%'; url: ^^url^^ ```