我想在没有 Spring Boot 的情况下进行服务发现。所以我下载了 netflix 项目示例,因为它的 gradle 项目我想使它成为 maven。
所以我创建了 maven 项目,导入了类和配置,并添加了依赖项。
我将它eureka.war放在 Tomcat webapps 文件夹中,然后启动了 eureka 服务器。
但是当我在 eclipse 中运行应用程序时,我收到了一个错误。
错误 c.netflix.discovery.DiscoveryClient - DiscoveryClient_UNKNOWN/DESKTOP-B997GFD - 无法刷新其缓存!status = 没有已知的尤里卡服务器;集群服务器列表为空 com.netflix.discovery.shared.transport.TransportException: 没有已知的尤里卡服务器;集群服务器列表为空
并且无法从尤里卡获取示例服务的实例以与之交谈
我有 Spring Boot 应用程序,并且正在使用 vertx。我想监控服务和 jvm,为此我选择了 Prometheus。
这是我的 MonitoringConfig 类:
@Configuration
public class MonitoringConfig {
@Bean
SpringBootMetricsCollector springBootMetricsCollector(Collection<PublicMetrics> publicMetrics) {
SpringBootMetricsCollector springBootMetricsCollector = new SpringBootMetricsCollector(publicMetrics);
springBootMetricsCollector.register();
return springBootMetricsCollector;
}
@Bean
public ServletRegistrationBean servletRegistrationBean() {
DefaultExports.initialize();
return new ServletRegistrationBean(new MetricsServlet(), "/prometheus");
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的依赖项:
<dependency>
<groupId>com.moelholm</groupId>
<artifactId>prometheus-spring-boot-starter</artifactId>
<version>1.0.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.prometheus/simpleclient -->
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient</artifactId>
<version>0.0.25</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.prometheus/simpleclient_hotspot -->
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_hotspot</artifactId>
<version>0.0.25</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.prometheus/simpleclient_spring_boot -->
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_spring_boot</artifactId>
<version>0.0.25</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.prometheus/simpleclient_servlet -->
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_servlet</artifactId>
<version>0.0.25</version>
</dependency> …Run Code Online (Sandbox Code Playgroud) 我想将 JSch 日志保存在文件中,因为它在控制台中没有显示任何内容。
这是我的代码:
public boolean openConnection() throws ItsSshException {
boolean connectSuccess = false;
JSch.setLogger(new MyLogger());
Properties config = new Properties();
config.put("StrictHostKeyChecking", "no");
jschSSH.setConfig(config);
try {
sshSession = jschSSH.getSession(username, hostname, port);
sshSession.setPassword(password);
sshSession.connect(connectionTimeout);
LOGGER.info("Connection timeout : " + connectionTimeout);
Thread.sleep(1000);
sshHChannel = sshSession.openChannel("shell");
sshHChannel.connect();
in = sshHChannel.getInputStream();
out = new PrintStream(sshHChannel.getOutputStream());
clearInitialSocketState();
connectSuccess = true;
} catch (Exception e) {
LOGGER.error("Error during connectiong to host: " + hostname +
", port: " + port + "!", e);
throw new ItsSshException("Error …Run Code Online (Sandbox Code Playgroud) 我有带有肥皂客户端的 Spring Boot 应用程序,它正在检查某些应用程序是否还活着。如果应用程序处于活动状态,我将仪表设置为 1,否则我将其设置为 0。问题是当我启动应用程序并发送请求并且响应正常时,我在普罗米修斯中看到仪表值为 1,但是当我停止服务器并发送另一个请求时,我希望仪表值应为 0,但又为 1。
这是我的代码。我也尝试过使用原子整数,但仍然存在问题。
@Autowired
MeterRegistry meterRegistry;
public void callWebService() throws IOException {
String request = "message";
List<String> list = convertUsingJava8(url);
for (String string : list) {
// AtomicInteger n = meterRegistry.gauge(string, new AtomicInteger(0));
// Gauge shit = Gauge.build().name(string).help("shit").register();
StringEntity stringEntity;
stringEntity = new StringEntity(request, "UTF-8");
stringEntity.setChunked(true);
HttpPost httpPost = new HttpPost(string);
httpPost.setEntity(stringEntity);
try (CloseableHttpClient httpClient = HttpClientBuilder.create().build()) {
HttpResponse response = null;
response = httpClient.execute(httpPost);
StringBuilder total = getMessage(response);
System.out.println(total.toString());
if (total.toString().contains("true")) { …Run Code Online (Sandbox Code Playgroud) 我正在与 Eureka Netflix 合作,但遇到了一个小问题。当应用程序在 eureka 上自行注册时,它会像 DESKTOP 一样注册....
这是我的服务器属性:
server.port=8761
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.instance.preferIpAddress=true
logging.level.com.netflix.eureka=OFF
logging.level.com.netflix.discovery=OFF
Run Code Online (Sandbox Code Playgroud)
这是客户端:
spring:
application:
name: Test 2
server:
port: 0
eureka:
client:
serviceUrl:
defaultZone: ${EUREKA_URI:http://localhost:8761/eureka}
instance:
preferIpAddress: true
Run Code Online (Sandbox Code Playgroud)
所以我认为这是一些配置问题,但我不知道是什么。
java ×3
spring-boot ×3
prometheus ×2
jsch ×1
logging ×1
micrometer ×1
netflix ×1
ssh ×1
vert.x ×1