一、寫測試代碼,端口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選擇數據源,輸入查詢條件測試