StatViewServlet是一個標準的javax.servlet.http.HttpServlet,須要配置在你web應用中的WEB-INF/web.xml中。html
<servlet> <servlet-name>DruidStatView</servlet-name> <servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>DruidStatView</servlet-name> <url-pattern>/druid/*</url-pattern> </servlet-mapping>
根據配置中的url-pattern來訪問內置監控頁面,若是是上面的配置,內置監控頁面的首頁是/druid/index.html
例如:
http://110.76.43.235:9000/druid/index.html
http://110.76.43.235:8080/mini-web/druid/index.htmljava
須要配置Servlet的 loginUsername 和 loginPassword這兩個初始參數。
<!-- 配置 Druid 監控信息顯示頁面 -->web
<servlet> <servlet-name>DruidStatView</servlet-name> <servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class> <init-param> <!-- 容許清空統計數據 --> <param-name>resetEnable</param-name> <param-value>true</param-value> </init-param> <init-param> <!-- 用戶名 --> <param-name>loginUsername</param-name> <param-value>druid</param-value> </init-param> <init-param> <!-- 密碼 --> <param-name>loginPassword</param-name> <param-value>druid</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>DruidStatView</servlet-name> <url-pattern>/druid/*</url-pattern> </servlet-mapping>
StatViewSerlvet展現出來的監控信息比較敏感,是系統運行的內部狀況,若是你須要作訪問控制,能夠配置allow和deny這兩個參數。好比:app
<servlet> <servlet-name>DruidStatView</servlet-name> <servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class> <init-param> <param-name>allow</param-name> <param-value>128.242.127.1/24,128.242.128.1</param-value> </init-param> <init-param> <param-name>deny</param-name> <param-value>128.242.127.4</param-value> </init-param> </servlet>