真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

數(shù)據(jù)庫數(shù)據(jù)源監(jiān)控的類型有哪些

本篇文章為大家展示了數(shù)據(jù)庫數(shù)據(jù)源監(jiān)控的類型有哪些,內(nèi)容簡明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過這篇文章的詳細(xì)介紹希望你能有所收獲。

創(chuàng)新互聯(lián)作為成都網(wǎng)站建設(shè)公司,專注成都網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì),有關(guān)成都企業(yè)網(wǎng)站建設(shè)方案、改版、費(fèi)用等問題,行業(yè)涉及成都發(fā)電機(jī)維修等多個(gè)領(lǐng)域,已為上千家企業(yè)服務(wù),得到了客戶的尊重與認(rèn)可。

1.Druid監(jiān)控

問題:
眾所周知,alibaba druid提供了比較完善的數(shù)據(jù)庫監(jiān)控,但是也是有比較明顯的劣勢(shì)(比如:數(shù)據(jù)源的連接數(shù)等在監(jiān)控頁面只能看到那瞬間的值等),不能持久化監(jiān)控以及和公司內(nèi)部監(jiān)控告警集成
解決:
通過內(nèi)部druid監(jiān)控方法

private class DruidStatsThread extends Thread {

    public DruidStatsThread(String name) {
        super(name);
        this.setDaemon(true);
    }

    @Override
    public void run() {
        long initialDelay = metricDruidProperties.getInitialDelay() * 1000;
        if (initialDelay > 0) {
            MwThreadUtil.sleep(initialDelay);
        }
        while (!this.isInterrupted()) {
            try {
                try {
                    Set druidDataSources =
                            DruidDataSourceStatManager.getDruidDataSourceInstances();
                    Optional.ofNullable(druidDataSources).ifPresent(val -> val.forEach(druidDataSource -> {
                        DruidDataSourceStatValue statValue = druidDataSource.getStatValueAndReset();
                        long maxWaitMillis = druidDataSource.getMaxWait();//最大等待時(shí)間
                        long waitThreadCount = statValue.getWaitThreadCount();//當(dāng)前等待獲取連接的線程數(shù)
                        long notEmptyWaitMillis = statValue.getNotEmptyWaitMillis();//獲取連接時(shí)累計(jì)等待多長時(shí)間
                        long notEmptyWaitCount = statValue.getNotEmptyWaitCount();//獲取連接時(shí)累計(jì)等待多少次'

                        int maxActive = druidDataSource.getMaxActive();//最大活躍數(shù)
                        int poolingCount = statValue.getPoolingCount();//當(dāng)前連接池?cái)?shù)
                        int poolingPeak = statValue.getPoolingPeak();//連接池峰值
                        int activeCount = statValue.getActiveCount();//當(dāng)前活躍連接數(shù)
                        int activePeak = statValue.getActivePeak();//活躍數(shù)峰值

                        if (Objects.nonNull(statsDClient)) {
                            URI jdbcUri = parseJdbcUrl(druidDataSource.getUrl());
                            Optional.ofNullable(jdbcUri).ifPresent(val2 -> {
                                String host = StringUtils.replaceChars(val2.getHost(), '.', '_');
                                String prefix = METRIC_DRUID_PREFIX + host + '.' + val2.getPort() + '.';
                                statsDClient.recordExecutionTime(prefix + "maxWaitMillis", maxWaitMillis);
                                statsDClient.recordExecutionTime(prefix + "waitThreadCount", waitThreadCount);
                                statsDClient.recordExecutionTime(prefix + "notEmptyWaitMillis", notEmptyWaitMillis);
                                statsDClient.recordExecutionTime(prefix + "notEmptyWaitCount", notEmptyWaitCount);
                                statsDClient.recordExecutionTime(prefix + "maxActive", maxActive);
                                statsDClient.recordExecutionTime(prefix + "poolingCount", poolingCount);
                                statsDClient.recordExecutionTime(prefix + "poolingPeak", poolingPeak);
                                statsDClient.recordExecutionTime(prefix + "activeCount", activeCount);
                                statsDClient.recordExecutionTime(prefix + "activePeak", activePeak);
                            });
                        } else {
                            druidDataSource.logStats();
                        }
                    }));
                } catch (Exception e) {
                    logger.error("druid stats exception", e);
                }
                TimeUnit.SECONDS.sleep(metricDruidProperties.getStatsInterval());
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                logger.info("metric druid interrupt exit...");
            } catch (Exception e) {
                logger.error("metric druid exception...", e);
            }
        }
    }
}

private URI parseJdbcUrl(String url) {
    if (StringUtils.isBlank(url) || !StringUtils.startsWith(url, "jdbc:")) {
        return null;
    }
    String cleanURI = url.substring(5);
    return URI.create(cleanURI);
}
2.Hikari監(jiān)控

問題:
針對(duì)Hikari數(shù)據(jù)源,沒有統(tǒng)一的監(jiān)控處理,但是,提供了JMX入口,同理,持久化在監(jiān)控服務(wù)上
解決:

private class HikariStatsThread extends Thread {

    public HikariStatsThread(String name) {
        super(name);
        this.setDaemon(true);
    }

    @Override
    public void run() {
        long initialDelay = metricHikariProperties.getInitialDelay() * 1000;
        if (initialDelay > 0) {
            MwThreadUtil.sleep(initialDelay);
        }
        while (!this.isInterrupted()) {
            try {
                Optional.ofNullable(hikariDataSources).ifPresent(val -> val.forEach(hikariDataSource -> {
                    URI jdbcUri = parseJdbcUrl(hikariDataSource.getJdbcUrl());
                    Optional.ofNullable(jdbcUri).ifPresent(val2 -> {
                        String host = StringUtils.replaceChars(val2.getHost(), '.', '_');
                        String prefix = METRIC_HIKARI_PREFIX + host + '.' + val2.getPort() + '.';

                        PoolStatBean poolStatBean = PoolStatBean.builder().build();
                        HikariPoolMXBean hikariPoolMXBean = hikariDataSource.getHikariPoolMXBean();
                        Optional.ofNullable(hikariPoolMXBean).ifPresent(val3 -> {
                            int activeConnections = val3.getActiveConnections();
                            int idleConnections = val3.getIdleConnections();
                            int totalConnections = val3.getTotalConnections();
                            int threadsAwaitingConnection = val3.getThreadsAwaitingConnection();
                            poolStatBean.setActiveConnections(activeConnections);
                            poolStatBean.setIdleConnections(idleConnections);
                            poolStatBean.setTotalConnections(totalConnections);
                            poolStatBean.setThreadsAwaitingConnection(threadsAwaitingConnection);
                        });
                        HikariConfigMXBean hikariConfigMXBean = hikariDataSource.getHikariConfigMXBean();
                        Optional.ofNullable(hikariConfigMXBean).ifPresent(val3 -> {
                            int maximumPoolSize = val3.getMaximumPoolSize();
                            int minimumIdle = val3.getMinimumIdle();
                            poolStatBean.setMaximumPoolSize(maximumPoolSize);
                            poolStatBean.setMinimumIdle(minimumIdle);
                        });
                        statsPool(prefix, poolStatBean);
                    });
                }));
                TimeUnit.SECONDS.sleep(metricHikariProperties.getStatsInterval());
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                logger.info("metric hikari interrupt exit...");
            } catch (Exception e) {
                logger.error("metric hikari exception...", e);
            }
        }
    }
}

private void statsPool(String prefix, PoolStatBean poolStatBean) {
    if (Objects.nonNull(statsDClient)) {
        statsDClient.recordExecutionTime(prefix + "activeConnections", poolStatBean.getActiveConnections());
        statsDClient.recordExecutionTime(prefix + "idleConnections", poolStatBean.getIdleConnections());
        statsDClient.recordExecutionTime(prefix + "totalConnections", poolStatBean.getTotalConnections());
        statsDClient.recordExecutionTime(prefix + "threadsAwaitingConnection",
                poolStatBean.getThreadsAwaitingConnection());
        statsDClient.recordExecutionTime(prefix + "maximumPoolSize", poolStatBean.getMaximumPoolSize());
        statsDClient.recordExecutionTime(prefix + "minimumIdle", poolStatBean.getMinimumIdle());
        return;
    }
    StringBuilder sBuilder = new StringBuilder(16);
    sBuilder.append(prefix + "activeConnections => [" + poolStatBean.getActiveConnections() + "],");
    sBuilder.append(prefix + "idleConnections => [" + poolStatBean.getIdleConnections() + "],");
    sBuilder.append(prefix + "totalConnections => [" + poolStatBean.getTotalConnections() + "],");
    sBuilder.append(prefix + "threadsAwaitingConnection => [" + poolStatBean.getThreadsAwaitingConnection() + "],");
    sBuilder.append(prefix + "maximumPoolSize => [" + poolStatBean.getMaximumPoolSize() + "],");
    sBuilder.append(prefix + "minimumIdle => [" + poolStatBean.getMinimumIdle() + "]");
    logger.info(sBuilder.toString());
}

private URI parseJdbcUrl(String url) {
    if (StringUtils.isBlank(url) || !StringUtils.startsWith(url, "jdbc:")) {
        return null;
    }
    String cleanURI = url.substring(5);
    return URI.create(cleanURI);
}

@Data
@Builder
private static class PoolStatBean {
    private int activeConnections;
    private int idleConnections;
    private int totalConnections;
    private int threadsAwaitingConnection;
    private int maximumPoolSize;
    private int minimumIdle;
}

注:以上只是提供一種解決方案

上述內(nèi)容就是數(shù)據(jù)庫數(shù)據(jù)源監(jiān)控的類型有哪些,你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。


當(dāng)前題目:數(shù)據(jù)庫數(shù)據(jù)源監(jiān)控的類型有哪些
本文地址:http://weahome.cn/article/pochog.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部