ITPub博客

首页 > 应用开发 > IT综合 > Netdata Tomcat运行情况监控插件

Netdata Tomcat运行情况监控插件

原创 IT综合 作者:百联达 时间:2016-05-06 15:58:33 0 删除 编辑
一: 背景
1.服务器 阿里云 CentOS
2.Tomcat 8.0.24
3.该插件通过tomcat的http://localhost:8080/manager/status?XML=true 进行监控
二:Tomcat配置

1.tomcat-users.xml配置

点击(此处)折叠或打开

  1. <?xml version='1.0' encoding='utf-8'?>
  2. <!--
  3.   Licensed to the Apache Software Foundation (ASF) under one or more
  4.   contributor license agreements. See the NOTICE file distributed with
  5.   this work for additional information regarding copyright ownership.
  6.   The ASF licenses this file to You under the Apache License, Version 2.0
  7.   (the "License"); you may not use this file except in compliance with
  8.   the License. You may obtain a copy of the License at

  9.       http://www.apache.org/licenses/LICENSE-2.0

  10.   Unless required by applicable law or agreed to in writing, software
  11.   distributed under the License is distributed on an "AS IS" BASIS,
  12.   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13.   See the License for the specific language governing permissions and
  14.   limitations under the License.
  15. -->
  16. <tomcat-users xmlns="http://tomcat.apache.org/xml"
  17.               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  18.               xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd"
  19.               version="1.0">
  20. <!--
  21.   NOTE: By default, no user is included in the "manager-gui" role required
  22.   to operate the "/manager/html" web application. If you wish to use this app,
  23.   you must define such a user - the username and password are arbitrary.
  24. -->
  25. <!--
  26.   NOTE: The sample user and role entries below are wrapped in a comment
  27.   and thus are ignored when reading this file. Do not forget to remove
  28.   <!.. ..> that surrounds them.
  29. -->
  30. <!--
  31.   <role rolename="tomcat"/>
  32.   <role rolename="role1"/>
  33.   <user username="tomcat" password="tomcat" roles="tomcat"/>
  34.   <user username="both" password="tomcat" roles="tomcat,role1"/>
  35.   <user username="role1" password="tomcat" roles="role1"/>
  36. -->
  37. <role rolename="admin-gui"/>
  38. <role rolename="admin-script"/>
  39. <role rolename="manager-gui"/>
  40. <role rolename="manager-script"/>
  41. <role rolename="manager-jmx"/>
  42. <role rolename="manager-status"/>
  43. <user username="tomcat" password="tomcat1" roles="manager-gui,manager-script,manager-jmx,manager-status,admin-script,admin-gui"/>
  44. </tomcat-users>

2.开启tomcat manager应用



三: 安装插件xmlstarlet

yum install xmlstarlet

四:tomcat监控插件脚本 tomcat.chart.sh

1.脚本存放路径 /usr/local/netdata/usr/libexec/netdata/charts.d

2.脚本下载路径 https://github.com/firehol/netdata/blob/master/charts.d/tomcat.chart.sh

3.绿色背景标示的地方,是需要根据自己的tomcat进行调整

点击(此处)折叠或打开

  1. #!/bin/bash

  2. # Description: Tomcat netdata charts.d plugin
  3. # Author: Jorge Romero

  4. # the URL to download tomcat status info
  5. tomcat_url="http://localhost:8080/manager/status?XML=true"

  6. # _update_every is a special variable - it holds the number of seconds
  7. # between the calls of the _update() function
  8. tomcat_update_every=1

  9. tomcat_priority=60000

  10. # convert tomcat floating point values
  11. # to integer using this multiplier
  12. # this only affects precision - the values
  13. # will be in the proper units
  14. tomcat_decimal_detail=1000000

  15. # used by volume chart to convert bytes to KB
  16. tomcat_decimal_KB_detail=1000

  17. tomcat_check() {

  18.     require_cmd xmlstarlet || return 1

  19.     tomcat_get
  20.     if [ $? -ne 0 ]
  21.         then
  22.         echo >&2 "tomcat: cannot find stub_status on URL '${tomcat_url}'. Please set tomcat_url='http://tomcat:$Brilliantstar2016@localhost:8080/manager/status?XML=true'"
  23.         return 1
  24.     fi

  25.     # this should return:
  26.     # - 0 to enable the chart
  27.     # - 1 to disable the chart

  28.     return 0
  29. }

  30. tomcat_get() {
  31.     # Collect tomcat values
  32.     mapfile -t lines < <(curl -u tomcatUser:tomcatPassword  -Ss "$tomcat_url" |\
  33.         xmlstarlet sel \
  34.             -t -m "/status/jvm/memory" -v @free \
  35.             -n -m "/status/connector[@name='\"http-nio-8080\"']/threadInfo" -v @currentThreadCount \
  36.             -n -v @currentThreadsBusy \
  37.             -n -m "/status/connector[@name='\"http-nio-8080\"']/requestInfo" -v @requestCount \
  38.             -n -v @bytesSent -n -)

  39.     tomcat_jvm_freememory="${lines[0]}"
  40.     tomcat_threads="${lines[1]}"
  41.     tomcat_threads_busy="${lines[2]}"
  42.     tomcat_accesses="${lines[3]}"
  43.     tomcat_volume="${lines[4]}"

  44.     return 0
  45. }

  46. # _create is called once, to create the charts
  47. tomcat_create() {
  48.     cat <<EOF
  49. CHART tomcat.accesses '' "tomcat requests" "requests/s" statistics tomcat.accesses area $((tomcat_priority + 8)) $tomcat_update_every
  50. DIMENSION accesses '' incremental
  51. CHART tomcat.volume '' "tomcat volume" "KB/s" volume tomcat.volume area $((tomcat_priority + 5)) $tomcat_update_every
  52. DIMENSION volume '' incremental divisor ${tomcat_decimal_KB_detail}
  53. CHART tomcat.threads '' "tomcat threads" "current threads" statistics tomcat.threads line $((tomcat_priority + 6)) $tomcat_update_every
  54. DIMENSION current '' absolute 1
  55. DIMENSION busy '' absolute 1
  56. CHART tomcat.jvm '' "JVM Free Memory" "MB" statistics tomcat.jvm area $((tomcat_priority + 8)) $tomcat_update_every
  57. DIMENSION jvm '' absolute 1 ${tomcat_decimal_detail}
  58. EOF
  59.     return 0
  60. }

  61. # _update is called continiously, to collect the values
  62. tomcat_update() {
  63.     local reqs net
  64.     # the first argument to this function is the microseconds since last update
  65.     # pass this parameter to the BEGIN statement (see bellow).

  66.     # do all the work to collect / calculate the values
  67.     # for each dimension
  68.     # remember: KEEP IT SIMPLE AND SHORT

  69.     tomcat_get || return 1

  70.     # write the result of the work.
  71.     cat <<VALUESEOF
  72. BEGIN tomcat.accesses $1
  73. SET accesses = $((tomcat_accesses))
  74. END
  75. BEGIN tomcat.volume $1
  76. SET volume = $((tomcat_volume))
  77. END
  78. BEGIN tomcat.threads $1
  79. SET current = $((tomcat_threads))
  80. SET busy = $((tomcat_threads_busy))
  81. END
  82. BEGIN tomcat.jvm $1
  83. SET jvm = $((tomcat_jvm_freememory))
  84. END
  85. VALUESEOF

  86.     return 0
  87. }
五:tomcat监控截图

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/28624388/viewspace-2094935/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: fireHOL and fireQOS
请登录后发表评论 登录
全部评论
15年以上互联网经验,先后从事过制造业,证券业,物业行业和物流行业信息系统和互联网产品的设计落地实施,8年系统架构经验。最近关注企业数字化转型、财务数字化服务共享、大语言模型、Kubernetes微服务架构和Istio微服务治理框架。

注册时间:2013-02-05

  • 博文量
    332
  • 访问量
    1265622