1 Monitoring connection performance
You can use the following code to setup a JDBC connection test to measure time in millis to acquire a connection to an specific database server. It can be useful for automatic diagnostics to check JDBC connection can be stablished from JDBC client and measure it's performance.
import java.sql.*; /** * Simple connection test. * Logs to stdout milliseconds to establish connection * * javac InformixConnectionTest.java * java -cp common/lib/jdbc_ifxjdbc.jar InformixConnectionTest * */ public class InformixConnectionTest { static { try { Class.forName("com.informix.jdbc.IfxDriver"); } catch (Exception ex) { System.err.println("Unable to load JDBC driver"); ex.printStackTrace(); System.exit(1); } } public static void main(String[] args) throws SQLException { String username = null; String password = null; String hostname = null; String servername = null; String port = "9088"; int i = 0; String arg; while (i < args.length && args[i].startsWith("-")) { arg = args[i++]; if (i < args.length) { switch (arg) { case "-username": username = args[i++]; break; case "-password": password = args[i++]; break; case "-hostname": hostname = args[i++]; break; case "-servername": servername = args[i++]; break; case "-port": port = args[i++]; break; default: usage("Unkown parameter " + arg); } } } if (args.length < 8) { usage("Not enougth arguments"); } String url = String.format("jdbc:informix-sqli://%s:%s/sysmaster:INFORMIXSERVER=%s", hostname, port, servername); //System.out.println("-- Connecting to " + url); long start = System.currentTimeMillis(); Connection connection = DriverManager.getConnection(url, username, password); if (false) { PreparedStatement st = connection.prepareStatement("SELECT * FROM systables WHERE tabname = ?"); st.setString(1, "systables"); ResultSet rs = st.executeQuery(); rs.next(); rs.close(); st.close(); } long stop = System.currentTimeMillis(); System.out.println(stop - start); } private static void usage(String msg) { System.err.println("Usage: InformixConnectionTest -username username -password password -hostname hostname -servername ol_servername"); System.err.println(msg); } }
Download Informix JDBC Driver from IBM website and get ifxjdbc.jar file.
Compile the class code for this test:
javac InformixConnectionTest.java
And finaly execute it to test your JDBC Connection:
java -cp .:ifxjdbc.jar InformixConnectionTest -username informix -password ******* -hostname dbsrv1 -servername ol_dbsrv1 -port 9088
148
1.1 Configure Zabbix to monitor connections
In order to monitor connection times from a host to an Informix Server, you need to execute some configuration steps to set up Zabbix agent.
Create a /etc/zabbix/jdbc folder and copy class and jar files generated in previous section into this folder
mkdir /etc/zabbix/jdbc cp /tmp/test_jdbc/* /etc/zabbix/jdbc
Copy next shell into /etc/zabbix folder:
#!/bin/bash if [ "$1" == "listservers" ]; then echo "{\"data\":[" echo "{\"{#JDBCID}\":\"dbsrv1\"}," echo "{\"{#JDBCID}\":\"dbsrv2\"}," echo "{\"{#JDBCID}\":\"dbsrv3\"}" echo "]}" elif [ "$1" == "connection" ]; then if [ "$2" == "dbsrv1" ]; then cd /etc/zabbix/jdbc; java -cp .:ifxjdbc.jar InformixConnectionTest -username informix -password xxxxx hostname dbsrv1 -servername ol_dbsrv1 -port 9088 elif [ "$2" == "dbsrv2" ]; then cd /etc/zabbix/jdbc; java -cp .:ifxjdbc.jar InformixConnectionTest -username informix -password xxxxx -hostname dbsrv2 -servername ol_dbsrv2 -port 9088 elif [ "$2" == "dbsrv3" ]; then cd /etc/zabbix/jdbc; java -cp .:ifxjdbc.jar InformixConnectionTest -username informix -password xxxxx -hostname dbsrv3 -servername ol_dbsrv3 -port 9088 else echo "99999"; fi else echo "Parameter incorrect" fi
Edit your shell to setup list of jdbc identifiers to monitor and associate each identifier with command to get connection time
Create a userparameter files name /etc/zabbix/zabbix_agentd.d/useragent_jdbc.conf to configure zabbix agent and copy next content:
UserParameter=deister.jdbc.servers,/etc/zabbix/jdbc_connection.sh listservers UserParameter=deister.jdbc.connection[*],/etc/zabbix/jdbc_connection.sh connection $1
Import next template into your Zabbix Server and apply it to the host where agent has been configured with previous steps:
<?xml version="1.0" encoding="UTF-8"?> <zabbix_export> <version>4.0</version> <date>2019-10-14T11:58:16Z</date> <groups> <group> <name>Templates</name> </group> </groups> <templates> <template> <template>Template JDBC Connection</template> <name>Template JDBC Connection</name> <description/> <groups> <group> <name>Templates</name> </group> </groups> <applications> <application> <name>JDBC Connections</name> </application> </applications> <items/> <discovery_rules> <discovery_rule> <name>JDBC Connection Servers</name> <type>0</type> <snmp_community/> <snmp_oid/> <key>deister.jdbc.servers</key> <delay>1h</delay> <status>0</status> <allowed_hosts/> <snmpv3_contextname/> <snmpv3_securityname/> <snmpv3_securitylevel>0</snmpv3_securitylevel> <snmpv3_authprotocol>0</snmpv3_authprotocol> <snmpv3_authpassphrase/> <snmpv3_privprotocol>0</snmpv3_privprotocol> <snmpv3_privpassphrase/> <params/> <ipmi_sensor/> <authtype>0</authtype> <username/> <password/> <publickey/> <privatekey/> <port/> <filter> <evaltype>0</evaltype> <formula/> <conditions/> </filter> <lifetime>7d</lifetime> <description/> <item_prototypes> <item_prototype> <name>JDBC Server {#JDBCID}: Connection Time</name> <type>0</type> <snmp_community/> <snmp_oid/> <key>deister.jdbc.connection[{#JDBCID}]</key> <delay>1m</delay> <history>90d</history> <trends>365d</trends> <status>0</status> <value_type>3</value_type> <allowed_hosts/> <units>ms</units> <snmpv3_contextname/> <snmpv3_securityname/> <snmpv3_securitylevel>0</snmpv3_securitylevel> <snmpv3_authprotocol>0</snmpv3_authprotocol> <snmpv3_authpassphrase/> <snmpv3_privprotocol>0</snmpv3_privprotocol> <snmpv3_privpassphrase/> <params/> <ipmi_sensor/> <authtype>0</authtype> <username/> <password/> <publickey/> <privatekey/> <port/> <description/> <inventory_link>0</inventory_link> <applications> <application> <name>JDBC Connections</name> </application> </applications> <valuemap/> <logtimefmt/> <preprocessing/> <jmx_endpoint/> <timeout>3s</timeout> <url/> <query_fields/> <posts/> <status_codes>200</status_codes> <follow_redirects>1</follow_redirects> <post_type>0</post_type> <http_proxy/> <headers/> <retrieve_mode>0</retrieve_mode> <request_method>0</request_method> <output_format>0</output_format> <allow_traps>0</allow_traps> <ssl_cert_file/> <ssl_key_file/> <ssl_key_password/> <verify_peer>0</verify_peer> <verify_host>0</verify_host> <application_prototypes/> <master_item/> </item_prototype> </item_prototypes> <trigger_prototypes> <trigger_prototype> <expression>{Template JDBC Connection:deister.jdbc.connection[{#JDBCID}].last()}>10000</expression> <recovery_mode>0</recovery_mode> <recovery_expression/> <name>JDBC Connection to {#JDBCID} timeout</name> <correlation_mode>0</correlation_mode> <correlation_tag/> <url/> <status>0</status> <priority>3</priority> <description>JDBC Connection to Informix Server is greater than 10 seconds.</description> <type>0</type> <manual_close>0</manual_close> <dependencies/> <tags/> </trigger_prototype> <trigger_prototype> <expression>{Template JDBC Connection:deister.jdbc.connection[{#JDBCID}].last()}>2000</expression> <recovery_mode>0</recovery_mode> <recovery_expression/> <name>JDBC Connection to {#JDBCID} too slow</name> <correlation_mode>0</correlation_mode> <correlation_tag/> <url/> <status>0</status> <priority>2</priority> <description>JDBC Connection to Informix Server is greater than 2 seconds. This is a very slow rate and it's unacceptable</description> <type>0</type> <manual_close>0</manual_close> <dependencies/> <tags/> </trigger_prototype> </trigger_prototypes> <graph_prototypes/> <host_prototypes/> <jmx_endpoint/> <timeout>3s</timeout> <url/> <query_fields/> <posts/> <status_codes>200</status_codes> <follow_redirects>1</follow_redirects> <post_type>0</post_type> <http_proxy/> <headers/> <retrieve_mode>0</retrieve_mode> <request_method>0</request_method> <allow_traps>0</allow_traps> <ssl_cert_file/> <ssl_key_file/> <ssl_key_password/> <verify_peer>0</verify_peer> <verify_host>0</verify_host> </discovery_rule> </discovery_rules> <httptests/> <macros/> <templates/> <screens/> </template> </templates> </zabbix_export>