先上pom依赖

        <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<version>1.1.3</version>
</dependency>

再上配置

    @Bean
MeterRegistryCustomizer<MeterRegistry> configurer(@Value("${spring.application.name}") String applicationName) {
return (registry) -> registry.config().commonTags("application", applicationName);
}
management.endpoints.web.exposure.include=*
management.metrics.tags.application=${spring.application.name}
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s). # Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093 # Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml" # A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prometheus' # metrics_path defaults to '/metrics'
# scheme defaults to 'http'. static_configs:
- targets: ['localhost:9090']
- job_name: 'xf_aa'
scrape_interval: 5s
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['localhost:8082']
- job_name: 'tomcat'
scrape_interval: 5s
static_configs:
- targets: ['localhost:30013']
labels:
appname: 'testjmx'

启动命令添加

-javaagent:e:/es/jmx_prometheus_javaagent-0.12.0.jar=30013:e:/es/jar.yml

jar下载地址:https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/0.12.0/jmx_prometheus_javaagent-0.12.0.jar

另:jmx_exporter config文件示例地址:https://github.com/prometheus/jmx_exporter/tree/master/example_configs

jar.yml配置

lowercaseOutputLabelNames: true
lowercaseOutputName: true
whitelistObjectNames: ["java.lang:type=OperatingSystem"]
blacklistObjectNames: []
rules:
- pattern: 'Tomcat<type=GlobalRequestProcessor, name=\"(\w+-\w+)-(\d+)\"><>(\w+):'
name: tomcat_$3_total
labels:
port: "$2"
protocol: "$1"
help: Tomcat global $3
type: COUNTER
- pattern: 'Tomcat<j2eeType=Servlet, WebModule=//([-a-zA-Z0-9+&@#/%?=~_|!:.,;]*[-a-zA-Z0-9+&@#/%=~_|]), name=([-a-zA-Z0-9+/$%~_-|!.]*), J2EEApplication=none, J2EEServer=none><>(requestCount|maxTime|processingTime|errorCount):'
name: tomcat_servlet_$3_total
labels:
module: "$1"
servlet: "$2"
help: Tomcat servlet $3 total
type: COUNTER
- pattern: 'Tomcat<type=ThreadPool, name="(\w+-\w+)-(\d+)"><>(currentThreadCount|currentThreadsBusy|keepAliveCount|pollerThreadCount|connectionCount):'
name: tomcat_threadpool_$3
labels:
port: "$2"
protocol: "$1"
help: Tomcat threadpool $3
type: GAUGE
- pattern: 'Tomcat<type=Manager, host=([-a-zA-Z0-9+&@#/%?=~_|!:.,;]*[-a-zA-Z0-9+&@#/%=~_|]), context=([-a-zA-Z0-9+/$%~_-|!.]*)><>(processingTime|sessionCounter|rejectedSessions|expiredSessions):'
name: tomcat_session_$3_total
labels:
context: "$2"
host: "$1"
help: Tomcat session $3 total
type: COUNTER
- pattern: 'java.lang<type=OperatingSystem><>(committed_virtual_memory|free_physical_memory|free_swap_space|total_physical_memory|total_swap_space)_size:'
name: os_$1_bytes
type: GAUGE
attrNameSnakeCase: true
- pattern: 'java.lang<type=OperatingSystem><>((?!process_cpu_time)\w+):'
name: os_$1
type: GAUGE
attrNameSnakeCase: true
- pattern: ".*"

自定义监控

    @Autowired
PrometheusMeterRegistry registry; @Bean
public Counter getCounter() {
Counter counter = Counter.builder("goods_rank_sync_count").tags("xf_status", "success")
.description("Number of successful goods rank sync").register(registry);
return counter;
}

在业务相关的地方注入Counter,调用counter.increment()

备注:

grafana配置使用id为8563是jmx的,4701是jvm相关的

最新文章

  1. JDBC MySQL 多表关联查询查询
  2. oracle 11g安装过程中问题:找不到WFMLRSVCApp.ear
  3. CSS三列布局
  4. Android基于mAppWidget实现手绘地图(九)–如何处理地图对象的touch事件
  5. SAML : A SAML stack
  6. MUI 个推
  7. Web Farm和Web Garden的区别
  8. dictionary (key-value) (map容器)
  9. 学好php可以做的事情真多!
  10. SpringCloud路由(网关)
  11. Skip the Class
  12. delete,truncate ,drop区别
  13. enum类使用
  14. 完美解决centos安装linux后不能上网的问题
  15. OpenShift-OKD3.10基础环境部署
  16. python项目离线环境配置指南
  17. Xcode 5中非常期待的6个功能
  18. JAVA中JDBC连接Mysql数据库简单测试
  19. linux用户及用户组操作
  20. 「美团 CodeM 资格赛」跳格子

热门文章

  1. 「浙江理工大学ACM入队200题系列」问题 K: 零基础学C/C++84——奇偶ASCII值判断
  2. mycat搭建
  3. MobaXterm/Xshell快速命令宏配置
  4. redisson分布式锁原理剖析
  5. Vscode连接gitee远程仓库
  6. 【Java面试指北】Exception Error Throwable 你分得清么?
  7. ArcObjects SDK开发 014 MapSurround和普通Element
  8. 回溯法求解n皇后问题(复习)
  9. 实践GoF的23种设计模式:命令模式
  10. Apache HttpClient 5 笔记: SSL, Proxy 和 Multipart Upload