成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

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

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

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

1.Druid監(jiān)控

問題:
眾所周知,alibaba druid提供了比較完善的數(shù)據(jù)庫監(jiān)控,但是也是有比較明顯的劣勢(比如:數(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<DruidDataSource> druidDataSources =
                            DruidDataSourceStatManager.getDruidDataSourceInstances();
                    Optional.ofNullable(druidDataSources).ifPresent(val -> val.forEach(druidDataSource -> {
                        DruidDataSourceStatValue statValue = druidDataSource.getStatValueAndReset();
                        long maxWaitMillis = druidDataSource.getMaxWait();//最大等待時間
                        long waitThreadCount = statValue.getWaitThreadCount();//當前等待獲取連接的線程數(shù)
                        long notEmptyWaitMillis = statValue.getNotEmptyWaitMillis();//獲取連接時累計等待多長時間
                        long notEmptyWaitCount = statValue.getNotEmptyWaitCount();//獲取連接時累計等待多少次'

                        int maxActive = druidDataSource.getMaxActive();//最大活躍數(shù)
                        int poolingCount = statValue.getPoolingCount();//當前連接池數(shù)
                        int poolingPeak = statValue.getPoolingPeak();//連接池峰值
                        int activeCount = statValue.getActiveCount();//當前活躍連接數(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)控

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

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)控的類型有哪些,你們學到知識或技能了嗎?如果還想學到更多技能或者豐富自己的知識儲備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

本文題目:數(shù)據(jù)庫數(shù)據(jù)源監(jiān)控的類型有哪些
本文地址:http://jinyejixie.com/article6/pochog.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供手機網(wǎng)站建設定制網(wǎng)站、網(wǎng)站內(nèi)鏈、關(guān)鍵詞優(yōu)化App設計、ChatGPT

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都app開發(fā)公司
宜兴市| 鱼台县| 阜宁县| 房山区| 武乡县| 宁陕县| 盐边县| 泗洪县| 丹凤县| 衢州市| 陇南市| 五大连池市| 揭西县| 榆树市| 永寿县| 建阳市| 姚安县| 定襄县| 林口县| 南召县| 湛江市| 札达县| 亚东县| 桑日县| 班玛县| 柳林县| 沈阳市| 晋城| 南宫市| 安徽省| 克东县| 塔河县| 齐齐哈尔市| 嘉祥县| 方山县| 晋中市| 巴南区| 镇赉县| 乌兰县| 沂源县| 沧源|