In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you the types of database data source monitoring, the content is concise and easy to understand, it can definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
1.Druid monitoring
Question:
As we all know, alibaba druid provides relatively perfect database monitoring, but it also has obvious disadvantages (for example, the number of connections to the data source, etc., can only see the instantaneous value on the monitoring page, etc.), can not persist monitoring and integrate with the company's internal monitoring alarm.
Resolve:
Through internal druid monitoring method
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 (); / / maximum waiting time long waitThreadCount = statValue.getWaitThreadCount (); / / current number of threads waiting to acquire a connection long notEmptyWaitMillis = statValue.getNotEmptyWaitMillis (); / / cumulative waiting time when acquiring a connection long notEmptyWaitCount = statValue.getNotEmptyWaitCount () / / get the cumulative number of times to wait for a connection 'int maxActive = druidDataSource.getMaxActive (); / / maximum active number int poolingCount = statValue.getPoolingCount (); / / current connection pool int poolingPeak = statValue.getPoolingPeak (); / / connection pool peak int activeCount = statValue.getActiveCount () / / current active connections int activePeak = statValue.getActivePeak (); / / Peak active 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 Monitoring
Question:
There is no unified monitoring processing for Hikari data sources, but it provides JMX entry, similarly, persistence on monitoring services.
Resolve:
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@Builderprivate static class PoolStatBean {private int activeConnections; private int idleConnections; private int totalConnections; private int threadsAwaitingConnection; private int maximumPoolSize; private int minimumIdle;}
Note: the above only provides a solution
What are the types of database data source monitoring? have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.