可参考链接,需找开发商量jmx端口暴露方式

https://www.jianshu.com/p/8a5e681b18ce 或者 http://www.mamicode.com/info-detail-2323750.html

上图两个链接为不同的jmx暴露方式,实则大同小异,需跟开发商量,以免程序启动不了

下载jmx_exporter的jar包

https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/0.3.1/jmx_prometheus_javaagent-0.3.1.jar

创建配置文件namenode.yaml(datanode.yaml)放在任意位置,内容为你想要的metrics

参考配置:

---
startDelaySeconds: 0
hostPort: master:1234 #master为本机IP(一般可设置为localhost);1234为想设置的jmx端口(可设置为未被占用的端口)
#jmxUrl: service:jmx:rmi:///jndi/rmi://127.0.0.1:1234/jmxrmi
ssl: false
lowercaseOutputName: false
lowercaseOutputLabelNames: false

其他参数参考:

Name Description
startDelaySeconds start delay before serving requests. Any requests within the delay period will result in an empty metrics set.
hostPort The host and port to connect to via remote JMX. If neither this nor jmxUrl is specified, will talk to the local JVM.
username The username to be used in remote JMX password authentication.
password The password to be used in remote JMX password authentication.
jmxUrl A full JMX URL to connect to. Should not be specified if hostPort is.
ssl Whether JMX connection should be done over SSL. To configure certificates you have to set following system properties:
-Djavax.net.ssl.keyStore=/home/user/.keystore
-Djavax.net.ssl.keyStorePassword=changeit
-Djavax.net.ssl.trustStore=/home/user/.truststore
-Djavax.net.ssl.trustStorePassword=changeit
lowercaseOutputName Lowercase the output metric name. Applies to default format and name. Defaults to false.
lowercaseOutputLabelNames Lowercase the output metric label names. Applies to default format and labels. Defaults to false.
whitelistObjectNames A list of ObjectNames to query. Defaults to all mBeans.
blacklistObjectNames A list of ObjectNames to not query. Takes precedence over whitelistObjectNames. Defaults to none.
rules A list of rules to apply in order, processing stops at the first matching rule. Attributes that aren‘t matched aren‘t collected. If not specified, defaults to collecting everything in the default format.
pattern Regex pattern to match against each bean attribute. The pattern is not anchored. Capture groups can be used in other options. Defaults to matching everything.
attrNameSnakeCase Converts the attribute name to snake case. This is seen in the names matched by the pattern and the default format. For example, anAttrName to an_attr_name. Defaults to false.
name The metric name to set. Capture groups from the pattern can be used. If not specified, the default format will be used. If it evaluates to empty, processing of this attribute stops with no output.
value Value for the metric. Static values and capture groups from the pattern can be used. If not specified the scraped mBean value will be used.
valueFactor Optional number that value (or the scraped mBean value if value is not specified) is multiplied by, mainly used to convert mBean values from milliseconds to seconds.
labels A map of label name to label value pairs. Capture groups from pattern can be used in each. name must be set to use this. Empty names and values are ignored. If not specified and the default format is not being used, no labels are set.
help Help text for the metric. Capture groups from pattern can be used. name must be set to use this. Defaults to the mBean attribute decription and the full name of the attribute.
type The type of the metric, can be GAUGECOUNTER or UNTYPEDname must be set to use this. Defaults to UNTYPED.

前提:

1.java程序的目录结构展示(因断网环境所以没办法用树状图命令tree来展示,只能截图)

如上图所示,一个服务器有一个java程序,其中子程序包括manager(管理端), server,client,PRM, Utilities,关联关系是agent和server要从manager管理端获取各种参数,server再向agent发包,这样程序就算跑起来了。

这里主要监控server和client

下图为manager和server以及其中一个client的目录结构

各conf目录下都有一个namenode.conf,内容如下

startDelaySeconds: 10
jmxUrl: service:jmx:rmi:///jndi/rmi://127.0.0.1:${JMX_PORT}/${APP_NAME}
ssl: false
lowercaseOutputName: false
lowercaseOutputLabelNames: false

各conf目录下都有一个namenode.yaml,内容如下(此为manager下conf中的)

各个子程序bin目录下都有关于程序的启动脚本,先执行1脚本启动,然后2脚本是让程序开启一个prometheus jmx端口,以便jmx exporter探针找到这个端口,收集到java程序的metrics信息,达到监控的目的

下图是npds-manager.sh脚本中实现开启jmx端口的脚本信息,完整脚本信息在最下面

这样启动java程序后,访问ip加自定义的端口9210就能访问到manager的mertrics信息了,达到监控的目的

然后找开发要他们想要监控的参数,以我为例要的参数如下图:

再以此一个个配置,就能实现监控了

vim npds-manager.sh

#!/bin/bash
then
    echo "=================================================================="
    echo "ERROR: Please set the JAVA_HOME variable in your environment!"
    echo "=================================================================="
    exit 20
fi

cd=$(pwd)

if [ ${cd:0-3} != "bin" ]
then
    echo "=================================================================="
    echo "ERROR: Please execute the script in the bin directory!"
    echo "=================================================================="
    exit 21
fi

APP_HOME=${cd%/bin}

APP_NAME=NPDS-Manager

APP_MAIN_CLASS=cn.com.greattimes.npds.manager.boot.ManagerBootstrap

JPS_FLAG=ManagerBootstrap

LIBRARY_PATH=$APP_HOME/jni

JAVA_OPTS="-server
-Xmx1G
-Xms1G"

DEBUG=0

RET_CODE=0

FORCE_KILL=0

CHECK_STATUS=1

CHECK_STATUS_TIMEOUT=5

check_env() {
    local DIR=${APP_HOME:POS+1}

if [ ! $DIR == $APP_NAME ]
    then
        echo "=================================================================="
        exit 22
    fi

if [ ! -d "$APP_HOME/logs" ]
    then
        mkdir $APP_HOME/logs
    fi

if [ $DEBUG -eq 1 ]
    then
        local DBG_PORT=9310
    fi
}

check_prometheus() {
    if [ -e "$APP_HOME/conf/namenode.conf" ]
    then
        local JMX_PORT=15914
    fi

if [ -e "$APP_HOME/conf/namenode.yaml" ]
    then
        local WEB_PORT=9210
    fi
}

check() {
    PID=0
    local TMP=$(jps -v | grep $JPS_FLAG | grep $APP_HOME)
    TMP=${TMP%% *}

if [ ${#TMP} -ne 0 ]
    then
        PID=$TMP
    fi

if [ $PID -ne 0 ]
    then
        RUNNING=1
    else
        RUNNING=0
    fi
}

print() {
    if [ $QUIET_MODE -eq 1 ]
    then
        return
    fi

echo "$1" "$2"
}
    if [ ! -n "$1" ]
    then
        return 2
    fi

ps -p $1 > /dev/null

if [ $? -eq 0 ]
    then
        kill -9 $1
    fi
}

start() {
    check

if [ $RUNNING -eq 1 ]
    then
        print "=================================================================="
        print "WARN: $APP_NAME(PID=$PID) is running."
        print "=================================================================="
        return 1
    fi

info

if [ $CHECK_STATUS -eq 0 ]
    then
        print -n "..."
        print
        print "------------------------------------------------------------------"
        print "WARN: $APP_NAME is started without checking status."
        print
        return 1
    fi

local n=0

for ((; n<$CHECK_STATUS_TIMEOUT; n++))
    do
        if [ $n -lt 3 ]
        then
            sleep 1
            print -n "."
        else
            check

if [ $RUNNING -eq 1 ]
            then
                print
                print "Done!"
                print
                return 0
            else
                sleep 1
            fi
        fi
    done

print
    print "------------------------------------------------------------------"
    print "ERROR: $APP_NAME failed to start for unknown reasons. "
    print "       Please refer to the log file for details."
    print
    return 2
stop() {
    check

if [ $RUNNING -eq 0 ]
    then
        print "=================================================================="
        print "WARN: $APP_NAME is stopped."
        print "=================================================================="
        return 1
    fi

info
    print -n "Stopping $APP_NAME"

if [ $FORCE_KILL -eq 1 ]
    then
        print -n "..."
        print

kill_pid $PID

print "------------------------------------------------------------------"
        print "WARN: $APP_NAME was killed by force."
        print
        return 1

if [ $CHECK_STATUS -eq 0 ]
    then
        print -n "..."
        print
        print "------------------------------------------------------------------"
        print "WARN: $APP_NAME is stopped without checking status."
        print
        return 1
    fi

local n=0

for ((; n<$CHECK_STATUS_TIMEOUT; n++))
    do
        if [ $n -lt 3 ]
        then
            sleep 1
            print -n "."
        else
            check

if [ $RUNNING -eq 0 ]
            then
                print
                print "Done!"
                print
                return 0
            else
                sleep 1
            fi
        fi
    done

kill_pid $PID

print
    print "------------------------------------------------------------------"
    print "WARN: $APP_NAME was killed for stopping timeout."
    print
    return 1
}

restart() {
    check

if [ $RUNNING -eq 1 ]
    then
        if [ $CHECK_STATUS -eq 0 ]
        then
            FORCE_KILL=1
        fi
        stop
    fi

start
}

status() {
    check

if [ $RUNNING -eq 0 ]
    then
        print "=================================================================="
        print "INFO: $APP_NAME is stopped."
        print "=================================================================="
        return 0
    else
        print "=================================================================="
        print "INFO: $APP_NAME(PID=$PID) is running."
        print "=================================================================="
        return 1
    fi
}

info() {
    if [ $QUIET_MODE -eq 1 ]
    then
        return
    fi

echo "=================================================================="
    echo "$APP_NAME Information:"
    echo "------------------------------------------------------------------"
    echo "JAVA_HOME=$JAVA_HOME"
    echo "CLASS_PATH=$CLASS_PATH"
    echo
    echo `$JAVA_HOME/bin/java -version`
    echo "APP_HOME=$APP_HOME"
    echo "APP_MAIN_CLASS=$APP_MAIN_CLASS"
    echo "=================================================================="
}

check_env

if [ $# -gt 1 ]
then
    for v in $@
    do
        if [ "$v" == "$1" ]
        then
            continue
        fi
        case "$v" in
            '--quiet')
                QUIET_MODE=1
                ;;
            '--nocheck')
                CHECK_STATUS=0
                ;;
            '--force')
                FORCE_KILL=1
                ;;
            *)
                ;;
        esac
    done
fi

case "$1" in
    'start')
        check_prometheus
        start
        ;;
    'stop')
        check_prometheus
        stop
        ;;
    'restart')
        check_prometheus
        restart
        ;;
    'status')
        status
        ;;
    'info')
        info
        ;;
    *)
        echo "=================================================================="
        echo "Usage: $0 <commands> [options]"
        echo "------------------------------------------------------------------"
        echo "where commands include:"
        echo
        echo -e "      start [options]"
        echo -e "            --quiet\twithout console output"
        echo -e "            --nocheck\twithout checking status"
        echo
        echo -e "       stop [options]"
        echo -e "            --quiet\twithout console output"
        echo -e "            --nocheck\twithout checking status"
        echo -e "            --force\tforce-kill"
        echo
        echo -e "    restart [options]"
        echo -e "            --quiet\twithout console output"
        echo -e "            --nocheck\twithout checking status"
        echo -e "            --force\tstart after force-kill"
        echo
        echo -e "     status \t\tdisplay running status"
        echo
        echo -e "       info \t\tdisplay environment information"
        echo "=================================================================="
        ;;
esac

RET_CODE=`echo $?`

exit $RET_CODE

prometheus监控java程序相关推荐

  1. 监控工具—Prometheus—监控Java程序

    原文作者:青蛙小白 原文地址:Prometheus监控实践:使用Prometheus监控Java应用 目录 1.Prometheus JVM Client 2.Prometheus的服务发现 3.Gr ...

  2. Prometheus 监控 Java 应用

    Prometheus 监控 Java 应用 Prometheus 监控 Java 应用有两种方式:一种是使用官方提供的jar包,然后嵌入到应用中.这种方式一般都是新项目.我认为也是最合适的一种.不过这 ...

  3. prometheus监控java项目(jvm等):k8s外、k8s内

    前言 虽然可以使用jvisualvm之类的工具监控java项目,但是集群环境下,还是捉襟见肘,下面介绍如何用主流的prometheus来监控java项目. java项目配置 在pom.xml中添加依赖 ...

  4. 使用jvisualvm的jstatd方式远程监控Java程序

    使用Java自带的jvisualvm调试Java程序,可以查看CPU.内存.类及线程等信息,还可以进行Dump,无疑是一个利器 由于客户端是Windows.服务端是Linux,并且是最小安装的Linu ...

  5. prometheus监控java应用的jvm指标

    在k8s环境中我们有很多的java应用,需要监控其性能我们可以通过集成jmx的客户端,然后通过promethues的自动发现来实现监控数据的获取. promethues的部署he相关配置可参考:pro ...

  6. 监控工具—Prometheus—监控Redis

    原文作者:wyl9527 原文地址:Grafana Prometheus系统监控Redis服务 目录 1.下载redis_exporter安装包 2.解压安装 3.systemd管理redis_exp ...

  7. java程序怎么监控错误_Fundebug上线Java程序错误监控啦!

    原标题:Fundebug上线Java程序错误监控啦! 摘要: Fundebug竭诚为你的Java程序保驾护航. 理论上讲,BUG是无法避免的,实时监控可以帮助开发者第一时间发现BUG,及时修复BUG, ...

  8. Prometheus监控(kube-prometheus)

    Prometheus监控实战(kube-prometheus) 部署kube-prometheus监控套件 调试 manifests下用户可以自定义CRD等资源配置 增加prometheus监控K8S ...

  9. java 程序架构知识

    流程类 Activity 的介绍和使用(一) https://blog.csdn.net/litengit/article/details/51065442 三分钟明白 Activity工作流 -- ...

最新文章

  1. C++ 笔记(27)— 指针变量、数组和指针、指针数组、数组指针、指针常量与常量指针
  2. Typescript之 范型
  3. 端子排怎么生成_防雷接地图纸怎么看?
  4. 在python中等号前面与后面分别是什么意思-python中is与双等于号“==”的区别示例详解...
  5. python写web难受-用python写脚本此页面上造成web运行速度减慢
  6. 一二三系列之优先队列、st表——Battle,Heapsort,A Magic Lamp
  7. 界面设计方法 (1) — 5. 表单功能的设计
  8. 2019.02.19 bzoj2655: calc(生成函数+拉格朗日插值)
  9. 下行法求最小割集案例_最小割集求法.docx
  10. 关于Pearson相关系数的显著性p值如何计算以及背后原因的思考
  11. 11g DB与AFD不兼容导致的 oracle[3038361] oracleafd:19:1616:Failed to map IO buffer in kernel memory 报错
  12. 内存超频对游戏提升大吗 玩游戏有必要超频吗
  13. 在线暴躁:script /问题
  14. 从零开始的MySQL数据库三部曲(二、MySQL数据库的创库创表增删改查篇)
  15. 主机名 域名 网站名 URL
  16. 方法详解(命名规则)
  17. Google登录强制启用二次身份验证与FIDO解决方案
  18. 微信小程序 人脸追踪+人脸识别+视频上传 页面
  19. in和exists的区别和使用场景纪要
  20. 什么是HTTP协议和HTTPS协议,以及两者的区别

热门文章

  1. 区块链100篇之哈希算法
  2. Vue组件封装,(面试回答)
  3. c语言 用指针对数组元素排序
  4. 函数奇偶性运算法则,以及复合函数奇偶性判断 ln的运算法则,对数函数运算法则 对数函数运算法则口诀,简单记忆
  5. mysql 怎么统计年龄段_mysql统计年龄段分布
  6. python计算平均年龄和男性人数_知道了总人数,和各个年龄段的人,怎么算平均年龄...
  7. Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
  8. 【小5聊】微信公众平台用户信息相关接口调整,不再返回性别和地区信息(2021.10.21)
  9. (电路汇总)ACDC电源电路 优缺点分析
  10. python中对类变量的访问形式_Python 面向对象中类、方法、变量、实例化和对象的概念,python定义类和访问权限?python三大支柱封装、继承和多态-立地货...