<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<version>1.9.0</version>
</dependency>
application.yml
management:
endpoints:
web:
exposure:
include: "*"
metrics:
tags:
application: ${spring.application.name}
instance: ${spring.application.instance_id:${random.value}}
service: ${spring.application.name}
service-instance-id: ${spring.application.instance_id:${random.value}}
# http://localhost:8081/actuator/prometheus
案例
package com.me.stress1.controller;
import cn.hutool.core.date.TimeInterval;
import com.alibaba.excel.EasyExcel;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.me.stress1.domain.IdmsUser;
import com.me.stress1.mapper.IdmsUserMapper;
import com.me.stress1.service.IdmsUserService;
import io.micrometer.core.annotation.Timed;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Counter;
import org.apache.ibatis.cursor.Cursor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
@RestController
public class IndexController {
private Logger logger = LoggerFactory.getLogger(IndexController.class);
@Timed("basic.createID")
@RequestMapping("/generateId")
public String createID(){
System.out.println("fffffldlfdlfld");
logger.info("createID");
return UUID.randomUUID().toString();
}
@Autowired
private MeterRegistry meterRegistry;
private Counter counter;
/**
*
* 使用 jmeter 进行压力测试使用
* 默认 单笔 或2笔数据
* 测试其相应速度
* qps 相关指标
*
* @param idmsUser
* @return
*/
@PostMapping("/add")
public JSONObject add(@RequestBody List<IdmsUser> idmsUser){
/**
* 统计 调用次数
*/
counter = meterRegistry.counter("app_requests_method_count","method","com.me.stress1.controller.IndexController.add");
/**
*
* 业务逻辑
*/
JSONObject object = new JSONObject();
object.put("code",200);
object.put("msg","ok");
object.put("data",idmsUser);
counter.increment();
return object;
}
}
把项目的端口地址配置到 prometheus 配置文件中去 即可实现微服务监控
标签:core,springboot,application,prometheus,整合,org,import,stress1,com From: https://blog.csdn.net/confident3/article/details/144436290