Springに統合されたJavaパフォーマンス監視チューニングツール-Javamelody



Spring Integrated Java Performance Monitoring Tuning Tool Javamelody



JavaMelodyは実行環境で監視できます Java または Java EE アプリケーション・サーバー。そしてチャートの形で表示されます:Javaメモリと Java CPU使用率、ユーザーセッション番号、JDBC接続番号、およびhttp要求、SQL要求、jspページ、およびビジネスインターフェイスメソッド(EJB3、 、Guice)実行数、平均実行時間、エラー率など。グラフは、日、週、月、年、またはカスタム期間ごとに表示できます。

https://github.com/javamelody/javamelody



方法1:

新しいクラス:



JavamelodyConfiguration.java


コードは次のとおりです。

import net.bull.javamelody.MonitoringFilter import net.bull.javamelody.SessionListener import org.springframework.boot.web.servlet.FilterRegistrationBean import org.springframework.boot.web.servlet.ServletListenerRegistrationBean import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration /** * @Author: TEST * @Date: 2018/6/10 22:11 * @Description: JAVAMELODY monitoring configuration */ @Configuration public class JavamelodyConfiguration { @Bean public FilterRegistrationBean monitorFilter(){ FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(new MonitoringFilter()) filterRegistrationBean.addUrlPatterns('/*') return filterRegistrationBean } @Bean public ServletListenerRegistrationBean sessionListener(){ ServletListenerRegistrationBean servletListenerRegistrationBean = new ServletListenerRegistrationBean() servletListenerRegistrationBean.setListener(new SessionListener()) return servletListenerRegistrationBean } }

または:

import org.springframework.boot.web.servlet.FilterRegistrationBean import org.springframework.boot.web.servlet.ServletListenerRegistrationBean import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration import org.springframework.core.annotation.Order import net.bull.javamelody.MonitoringFilter import net.bull.javamelody.SessionListener @Configuration public class FilterConfig { /** * Configure javamelody monitoring * spring boot will filter according to the order value, from small to large. */ @Bean @Order(Integer.MAX_VALUE-1) public FilterRegistrationBean monitoringFilter() { FilterRegistrationBean registration = new FilterRegistrationBean() registration.setFilter(new MonitoringFilter()) registration.addUrlPatterns('/*') registration.setName('monitoring') return registration } /** * Configure javamelody listener sessionListener */ @Bean public ServletListenerRegistrationBean servletListenerRegistrationBean() { ServletListenerRegistrationBean slrBean = new ServletListenerRegistrationBean() slrBean.setListener(new SessionListener()) return slrBean } }


POM.xmlを導入



net.bull.javamelody javamelody-core 1.73.1 com.lowagie itext 2.1.7


アプリケーションを起動し、http:// localhost / b / monitoringにアクセスします。

方法2:

Spring Bootプロジェクトは、監視にJavaMelodyを使用し、spring-boot-starterを使用してすばやく統合できます。

まず、mavenを使用してspring-boot-starterを導入します。

net.bull.javamelody javamelody-spring-boot-starter 1.72.0


このようにして、URL http:// localhost:8080 / monitoringのJavaMelodyモニタリングレポートにアクセスできます。

レポートをPDF形式にエクスポートする場合は、プロジェクトにiText2.1.7の依存関係を導入できます。

com.lowagie itext 2.1.7 bcmail-jdk14 bouncycastle bcprov-jdk14 bouncycastle bctsp-jdk14 bouncycastle


プロジェクト内のいくつかのクラスまたはメソッドを監視する場合は、アノテーション@MonitoredWithSpringを使用して、このアノテーションをクラスまたはメソッドに追加できます。

その他のリファレンス構成は、公式のGitHubにあります。

https://github.com/javamelody/javamelody/wiki/SpringBootStarter

その他の構成:

構成

必要に応じて、接頭辞javamelodyが付いた構成プロパティを使用して他の設定を構成できます。あなたのapplication.ymlまたはapplication.properties

application.ymlの例:

javamelody: # Enable JavaMelody auto-configuration (optional, default: true) enabled: true # Data source names to exclude from monitoring (optional, comma-separated) excluded-datasources: secretSource,topSecretSource # Enable monitoring of Spring services and controllers (optional, default: true) spring-monitoring-enabled: true # Initialization parameters for JavaMelody (optional) # See: https://github.com/javamelody/javamelody/wiki/UserGuide#6-optional-parameters init-parameters: # log http requests: log: true # to exclude images, css, fonts and js urls from the monitoring: #url-exclude-pattern: (/webjars/.*|/css/.*|/images/.*|/fonts/.*|/js/.*) # to aggregate digits in http requests: #http-transform-pattern: d+ # to add basic auth: #authorized-users: admin:pwd # to change the default storage directory: #storage-directory: /tmp/javamelody # to change the default '/monitoring' path: #monitoring-path: /admin/performance

application.propertiesの例:

# Enable JavaMelody auto-configuration (optional, default: true) javamelody.enabled=true # Data source names to exclude from monitoring (optional, comma-separated) javamelody.excluded-datasources=secretSource,topSecretSource # Enable monitoring of Spring services and controllers (optional, default: true) javamelody.spring-monitoring-enabled=true # Initialization parameters for JavaMelody (optional) # See: https://github.com/javamelody/javamelody/wiki/UserGuide#6-optional-parameters # log http requests: javamelody.init-parameters.log=true # to exclude images, css, fonts and js urls from the monitoring: # javamelody.init-parameters.url-exclude-pattern=(/webjars/.*|/css/.*|/images/.*|/fonts/.*|/js/.*) # to aggregate digits in http requests: # javamelody.init-parameters.http-transform-pattern: d+ # to add basic auth: # javamelody.init-parameters.authorized-users=admin:pwd # to change the default storage directory: # javamelody.init-parameters.storage-directory=/tmp/javamelody # to change the default '/monitoring' path: # javamelody.init-parameters.monitoring-path=/admin/performance

アノテーションが付けられたメソッドの監視を有効にするには @Scheduled または @スケジュール

  1. application.ymlに以下を追加します。
javamelody: advisor-auto-proxy-creator-enabled: false scheduled-monitoring-enabled: true add a dependency on aop in your pom.xml: org.springframework.boot spring-boot-starter-aop

構成方法:
1.ダウンロードアドレス: http://code.google.com/p/javamelody/downloads/list
これまでのところ、最新バージョンは1.47.0です。ダウンロードアドレス: http://code.google.com/p/javamelody/downloads/detail?name=javamelody-1.47.0.zip&can=2&q=
2.ダウンロード後、javamelody-1.47.0.jarおよびjrobin-1.5.9.1.jarを抽出して、プロジェクトを参照できます。

3.web.xmlでフィルターを構成します。

monitoring net.bull.javamelody.MonitoringFilter log true monitoring /* net.bull.javamelody.SessionListener

4.プロジェクトを再起動します。次のリンクを開きます:http://:/ projectname / monitoring
例:http://127.0.0.1:8080 / myproj / monitoring

この時点で、基本構成が完了し、簡単なパフォーマンス監視を実行できます。次の構成は、javamelodyとstruts2およびspring3の統合構成です。

5.javamelodyとstruts2の統合構成:

/pub_error.jsp

以下に示すように、他のstruts構成ファイルはベースを継承します。

contextConfigLocation Classpath:applicationContext*.xml Classpath:net/bull/javamelody/monitoring-spring.xml


6.javamelodyはSpringと統合されています:
Spring構成ファイルで構成されています。

Method 1, add the following configuration to web.xml: contextConfigLocation Classpath:applicationContext*.xml Classpath:net/bull/javamelody/monitoring-spring-aspectj.xml

次に、以下を構成します。
方法1、次の構成をweb.xmlに追加します。

private Class entityClass = (Class) ((ParameterizedType) getClass() .getGenericSuperclass()).getActualTypeArguments()[0]



方法2、spring.xmlに次の構成を追加します。

private Class entityClass = (Class) getSuperClassGenricType(this .getClass(), 0) public static Class getSuperClassGenricType(Class clazz, int index) throws IndexOutOfBoundsException { Type genType = clazz.getGenericSuperclass() if (!(genType instanceof ParameterizedType)) { return Object.class } Type[] params = ((ParameterizedType) genType).getActualTypeArguments() if (index >= params.length || index <0) { return Object.class } if (!(params[index] instanceof Class)) { return Object.class } return (Class) params[index] }

7.すべてのSpring管理Beanがインターフェースを実装している場合は、ステップ6の構成を使用してすべてをOKにしますが、一部のBeanがインターフェースを実装していない場合、ステップ6の構成は間違っています。
手順6で構成を変更します(cglibプロキシが使用されるようにします)。
Spring構成ファイルで構成されています。

...




方法2、spring.xmlに次の構成を追加します。

monitoring net.bull.javamelody.MonitoringFilter log true

8.プロジェクトで次のようなジェネリッククラスを頻繁に取得します。

|_+_|

手順7で構成したcglibプロキシを使用した後、上記のコードは間違っています。ジェネリッククラスは次のように変更できます。

|_+_|


9. Javamelodyキャッシュファイルのクリーンアップ:デフォルトのパスは通常、tomcat_home / temp / javamelodyにあります。

10.結果をpdfにエクスポートする必要がある場合は、プロジェクトでiText.jarを参照するだけで、pdfをエクスポートするためのリンクが自動的に追加されます。

11.javamelodyとQuartzの統合には、構成が必要です。

|_+_|

12.javamelodyでオプションのパラメーターを構成します。
web.xmlで構成されます。例としてロギングを取り上げます。次の構成では、情報レベルでのロギングが有効になります。

|_+_|

その他のオプションのパラメータ:
system-actions-enabled:デフォルトはtrueで、コントロールはシステムアクションのガベージコレクター、httpセッション、ヒープダンプ、メモリヒストグラム、プロセスリスト、jndiツリー、開いているjdbc接続、データベースを開始または停止します。

url-exclude-pattern:一部のURLを除く、構成可能な正規表現は監視されません。

http-transform-pattern、sql-transform-pattern、ejb-transform-pattern、spring-transform-pattern、guice-transform-pattern、error-transform-pattern、log-transform- Pattern、job-transform-pattern、jsf- transform-pattern、struts-transform-pattern、およびjsp-transform-pattern:javamelody統計をマージするための構成可能な正規表現。

storage-directory:デフォルトはjavamelody、tomcat、デフォルトのストレージパスはTOMCAT_HOME / temp / javamelody

監視パス:デフォルトは/ monitoringです。これは別のアドレスに変更できます。たとえば、/ moに変更すると、監視アドレスは次のように変更されます。http://:/ Projectname / mo

データベースなし:デフォルトはfalse、trueに設定すると、データ関連の動作は監視されません。

無効:デフォルトはfalse、trueに設定されている場合は監視されなくなります。

詳細については、http://code.google.com/p/javamelody/wiki/UserGuideを参照してください。

効果チャート: