一、写测试代码,端口6060java
package com.example.demo.controller; import com.example.demo.entity.User; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate; import java.util.Random; import java.util.concurrent.TimeUnit; @RestController public class TestController { @PostMapping("/order") public User getUser() { User user = new User(); user.setId(1L); try { TimeUnit.MILLISECONDS.sleep(new Random().nextInt(10) * 100); } catch (InterruptedException e) { } return user; } public static void main(String[] args) { RestTemplate restTemplate = new RestTemplate(); while (true) { String url = "http://localhost:6060/order"; if (new Random().nextInt(10) > 3) { url = "http://localhost:5050/order"; } String result = restTemplate.postForObject(url, null, String.class); System.out.println(result); } } }
访问:http://localhost:6060/actuator/prometheusweb
结果以下(访问了接口,才有数据):spring
二、新建一个Dashboardapp
三、选择图表dom
四、编辑图表post
五、在DataSouce选择数据源,输入查询条件测试