技术杂记-改造具有监控功能的数据库连接池阿里Druid,支持simple-jndi,kettle

  kettle内置的jndi管理是simple-jndi,功能确实比较简单,我需要监控kettle性能,druid确实是很不错的选择,但没有提供对应的支持,我改进了druid源码,实现了simple-jndi的接口,就可以在simple-jndi/jdbc.properties中配置druid数据源了,通过druid可以得到很多监控数据。

  具体druid的使用请参考官方教程:https://github.com/alibaba/druid/wiki/%E9%A6%96%E9%A1%B5,相当详细。

  具体代码如下:

/*
 * Copyright 1999-2101 Alibaba Group Holding Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.alibaba.druid.support.simplejndi;

import java.sql.SQLException;
import java.util.Properties;

import org.osjava.sj.loader.convert.Converter;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;
import com.alibaba.druid.support.logging.Log;
import com.alibaba.druid.support.logging.LogFactory;

/**
 * 支持simple-jndi
 * <h1>配置示例:</h1>
 * <pre>
pgDruidTest/converter=com.alibaba.druid.support.simplejndi.DruidDataSourceConverter
pgDruidTest/type=javax.sql.DataSource
pgDruidTest/driverClassName=org.postgresql.Driver
pgDruidTest/url=jdbc:postgresql://127.0.0.1:5432/kettleRep
pgDruidTest/username=postgres
pgDruidTest/password=postgres
pgDruidTest/maxActive=50
pgDruidTest/minIdle=10
pgDruidTest/initialSize=5
pgDruidTest/validationQuery=SELECT 1
pgDruidTest/maxWait=10000
pgDruidTest/removeabandoned=true
pgDruidTest/removeabandonedtimeout=60
pgDruidTest/logabandoned=false
pgDruidTest/filters=stat,config,log4j
pgDruidTest/connectionProperties=druid.log.stmt.executableSql=true
   </pre>
 * date: 2016年1月31日 下午12:54:10 
 * @author jinjuma@yeah.net
 */
public class DruidDataSourceConverter implements Converter {

    private final static Log LOG = LogFactory.getLog(DruidDataSourceConverter.class);
    /**
     * 
     * @see org.osjava.sj.loader.convert.Converter#convert(java.util.Properties, java.lang.String)
     */
    @Override
    public Object convert(Properties properties, String type) {
        try {
            DruidDataSource dataSource = new DruidDataSource();
            DruidDataSourceFactory.config(dataSource, properties);
            return dataSource;
        } catch (SQLException e) {
            LOG.error("properties:"+properties, e);
        }
        return null;
    }

}

  我已将以上改进pull requests到官方了,并已经合并,官方新版应该直接支持作为kettle的数据源配置了。

转载于:https://www.cnblogs.com/majinju/p/5173138.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值