簡體   English   中英

Prometheus - 連接:沒有到主機的路由。 即使服務已啟動

[英]Prometheus - connect: no route to host. Even though the service is up

當我訪問 Prometheus 目標時,這些目標之一正在“狀態下降”,即使我可以在瀏覽器上訪問它( 在此處輸入圖片說明 )。 我可能錯過了一些東西。 我想知道它是什么,因為我已經搜索了幾個小時,但找不到原因。 我什至禁用了 Windows 防火牆一段時間,但它不起作用。

我正在使用 docker 和 Spring。 我創建的 Rest 服務運行良好。 (myIP 是代碼和圖像中的本地主機)。

我的 docker 配置如下。

docker-compose.yml

使用 root/example 作為用戶/密碼憑據

版本:'3.8'

服務:

  mysql:
    image: mysql:8.0.22
    container_name: mysql
    ports:
      - 3306:3306
    environment:
      MYSQL_USER: atendente
      MYSQL_PASSWORD: atendente
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: plano_saude_db
  jaeger:
    image: jaegertracing/all-in-one:1.21
    container_name: jaeger
    ports:
      - 5775:5775/udp
      - 6831:6831/udp
      - 5778:5778
      - 16686:16686
      - 14268:14268
      - 14250:14250
      - 9411:9411
  prometheus:
    image: prom/prometheus:v2.24.1
    container_name: prometheus
    ports:
      - 9090:9090
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml
    command:
      '--config.file=/etc/prometheus/prometheus.yml'

prometheus.yml:

global: scrape_interval: 15s # 默認情況下,每 15 秒抓取一次目標。

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  - job_name: 'prometheus'
    scrape_interval: 5s
    static_configs:
      - targets: ['localhost:9090']
  - job_name: 'planosaude-sys'
    scrape_interval: 5s
    metrics_path: '/actuator/prometheus'
    static_configs:
      - targets: ['<myIp>:8080']

訪問 http://myIp:8080/actuator/prometheus 我得到以下信息:

# HELP jdbc_connections_idle Number of established but idle connections.
# TYPE jdbc_connections_idle gauge jdbc_connections_idle{name="dataSource",} 10.0
# HELP tomcat_sessions_active_max_sessions  
# TYPE tomcat_sessions_active_max_sessions gauge tomcat_sessions_active_max_sessions 0.0
# HELP jvm_memory_max_bytes The maximum amount of memory in bytes that can be used for memory management
# TYPE jvm_memory_max_bytes gauge jvm_memory_max_bytes{area="nonheap",id="CodeHeap 'profiled
nmethods'",} 1.2288E8 jvm_memory_max_bytes{area="heap",id="G1 Survivor
Space",} -1.0 jvm_memory_max_bytes{area="heap",id="G1 Old Gen",}
1.579155456E9 jvm_memory_max_bytes{area="nonheap",id="Metaspace",} -1.0 jvm_memory_max_bytes{area="nonheap",id="CodeHeap 'non-nmethods'",} 5898240.0 jvm_memory_max_bytes{area="heap",id="G1
Eden Space",} -1.0 jvm_memory_max_bytes{area="nonheap",id="Compressed
Class Space",} 1.073741824E9
jvm_memory_max_bytes{area="nonheap",id="CodeHeap 'non-profiled
nmethods'",} 1.2288E8
# HELP jvm_threads_peak_threads The peak live thread count since the Java virtual machine started or peak was reset
# TYPE jvm_threads_peak_threads gauge jvm_threads_peak_threads 21.0
# HELP jvm_threads_states_threads The current number of threads having NEW state
# TYPE jvm_threads_states_threads gauge jvm_threads_states_threads{state="runnable",} 9.0
jvm_threads_states_threads{state="blocked",} 0.0
jvm_threads_states_threads{state="waiting",} 5.0
jvm_threads_states_threads{state="timed-waiting",} 6.0
jvm_threads_states_threads{state="new",} 0.0
jvm_threads_states_threads{state="terminated",} 0.0
# HELP jdbc_connections_max Maximum number of active connections that can be allocated at the same time.
# TYPE jdbc_connections_max gauge jdbc_connections_max{name="dataSource",} 10.0
# HELP process_uptime_seconds The uptime of the Java virtual machine
# TYPE process_uptime_seconds gauge process_uptime_seconds 2484.248
# HELP logback_events_total Number of error level events that made it to the logs
# TYPE logback_events_total counter logback_events_total{level="warn",} 1.0
logback_events_total{level="debug",} 0.0
logback_events_total{level="error",} 0.0
logback_events_total{level="trace",} 0.0
logback_events_total{level="info",} 15.0
# HELP jvm_classes_loaded_classes The number of classes that are currently loaded in the Java virtual machine
# TYPE jvm_classes_loaded_classes gauge jvm_classes_loaded_classes 12647.0
# HELP jvm_threads_live_threads The current number of live threads including both daemon and non-daemon threads
# TYPE jvm_threads_live_threads gauge jvm_threads_live_threads 20.0
# HELP hikaricp_connections_usage_seconds Connection usage time
# TYPE hikaricp_connections_usage_seconds summary hikaricp_connections_usage_seconds_count{pool="HikariPool-1",} 0.0
hikaricp_connections_usage_seconds_sum{pool="HikariPool-1",} 0.0
# HELP hikaricp_connections_usage_seconds_max Connection usage time
# TYPE hikaricp_connections_usage_seconds_max gauge hikaricp_connections_usage_seconds_max{pool="HikariPool-1",} 0.0
# HELP jvm_gc_max_data_size_bytes Max size of long-lived heap memory pool
# TYPE jvm_gc_max_data_size_bytes gauge jvm_gc_max_data_size_bytes 1.579155456E9
# HELP jvm_buffer_total_capacity_bytes An estimate of the total capacity of the buffers in this pool
# TYPE jvm_buffer_total_capacity_bytes gauge jvm_buffer_total_capacity_bytes{id="mapped - 'non-volatile memory'",}
0.0 jvm_buffer_total_capacity_bytes{id="mapped",} 0.0 jvm_buffer_total_capacity_bytes{id="direct",} 32768.0
# HELP jvm_memory_committed_bytes The amount of memory in bytes that is committed for the Java virtual machine to use
# TYPE jvm_memory_committed_bytes gauge jvm_memory_committed_bytes{area="nonheap",id="CodeHeap 'profiled
nmethods'",} 1.1337728E7 jvm_memory_committed_bytes{area="heap",id="G1
Survivor Space",} 2097152.0
jvm_memory_committed_bytes{area="heap",id="G1 Old Gen",} 3.7748736E7
jvm_memory_committed_bytes{area="nonheap",id="Metaspace",} 7.0582272E7
jvm_memory_committed_bytes{area="nonheap",id="CodeHeap
'non-nmethods'",} 2555904.0
jvm_memory_committed_bytes{area="heap",id="G1 Eden Space",} 2.62144E7
jvm_memory_committed_bytes{area="nonheap",id="Compressed Class
Space",} 9109504.0
jvm_memory_committed_bytes{area="nonheap",id="CodeHeap 'non-profiled
nmethods'",} 4325376.0
# HELP hikaricp_connections_pending Pending threads
# TYPE hikaricp_connections_pending gauge hikaricp_connections_pending{pool="HikariPool-1",} 0.0
# HELP tomcat_sessions_alive_max_seconds  
# TYPE tomcat_sessions_alive_max_seconds gauge tomcat_sessions_alive_max_seconds 0.0
# HELP tomcat_sessions_active_current_sessions  
# TYPE tomcat_sessions_active_current_sessions gauge tomcat_sessions_active_current_sessions 0.0
# HELP jdbc_connections_min Minimum number of idle connections in the pool.
# TYPE jdbc_connections_min gauge jdbc_connections_min{name="dataSource",} 10.0
# HELP jdbc_connections_active Current number of active connections that have been allocated from the data source.
# TYPE jdbc_connections_active gauge jdbc_connections_active{name="dataSource",} 0.0
# HELP jvm_threads_daemon_threads The current number of live daemon threads
# TYPE jvm_threads_daemon_threads gauge jvm_threads_daemon_threads 16.0
# HELP jvm_memory_used_bytes The amount of used memory
# TYPE jvm_memory_used_bytes gauge jvm_memory_used_bytes{area="nonheap",id="CodeHeap 'profiled
nmethods'",} 1.1297792E7 jvm_memory_used_bytes{area="heap",id="G1
Survivor Space",} 1651760.0 jvm_memory_used_bytes{area="heap",id="G1
Old Gen",} 2.7873792E7
jvm_memory_used_bytes{area="nonheap",id="Metaspace",} 7.0095672E7
jvm_memory_used_bytes{area="nonheap",id="CodeHeap 'non-nmethods'",}
1357312.0 jvm_memory_used_bytes{area="heap",id="G1 Eden Space",} 1.2582912E7 jvm_memory_used_bytes{area="nonheap",id="Compressed Class Space",} 8883800.0 jvm_memory_used_bytes{area="nonheap",id="CodeHeap
'non-profiled nmethods'",} 4293632.0
# HELP tomcat_sessions_rejected_sessions_total  
# TYPE tomcat_sessions_rejected_sessions_total counter tomcat_sessions_rejected_sessions_total 0.0
# HELP process_cpu_usage The "recent cpu usage" for the Java Virtual Machine process
# TYPE process_cpu_usage gauge process_cpu_usage 0.0013668563296602018
# HELP hikaricp_connections_active Active connections
# TYPE hikaricp_connections_active gauge hikaricp_connections_active{pool="HikariPool-1",} 0.0
# HELP tomcat_sessions_expired_sessions_total  
# TYPE tomcat_sessions_expired_sessions_total counter tomcat_sessions_expired_sessions_total 0.0
# HELP jvm_buffer_count_buffers An estimate of the number of buffers in the pool
# TYPE jvm_buffer_count_buffers gauge jvm_buffer_count_buffers{id="mapped - 'non-volatile memory'",} 0.0
jvm_buffer_count_buffers{id="mapped",} 0.0
jvm_buffer_count_buffers{id="direct",} 4.0
# HELP hikaricp_connections_creation_seconds_max Connection creation time
# TYPE hikaricp_connections_creation_seconds_max gauge hikaricp_connections_creation_seconds_max{pool="HikariPool-1",} 0.0
# HELP hikaricp_connections_creation_seconds Connection creation time
# TYPE hikaricp_connections_creation_seconds summary hikaricp_connections_creation_seconds_count{pool="HikariPool-1",} 10.0
hikaricp_connections_creation_seconds_sum{pool="HikariPool-1",} 0.943
# HELP jvm_gc_memory_promoted_bytes_total Count of positive increases in the size of the old generation memory pool before GC to after GC
# TYPE jvm_gc_memory_promoted_bytes_total counter jvm_gc_memory_promoted_bytes_total 1.356288E7
# HELP system_cpu_usage The "recent cpu usage" for the whole system
# TYPE system_cpu_usage gauge system_cpu_usage 0.07962681468188304
# HELP http_server_requests_seconds  
# TYPE http_server_requests_seconds summary http_server_requests_seconds_count{exception="None",method="GET",outcome="SUCCESS",status="200",uri="/actuator/prometheus",}
1.0 http_server_requests_seconds_sum{exception="None",method="GET",outcome="SUCCESS",status="200",uri="/actuator/prometheus",}
2.7254424
# HELP http_server_requests_seconds_max  
# TYPE http_server_requests_seconds_max gauge http_server_requests_seconds_max{exception="None",method="GET",outcome="SUCCESS",status="200",uri="/actuator/prometheus",}
0.0
# HELP hikaricp_connections_timeout_total Connection timeout total count
# TYPE hikaricp_connections_timeout_total counter hikaricp_connections_timeout_total{pool="HikariPool-1",} 0.0
# HELP hikaricp_connections_max Max connections
# TYPE hikaricp_connections_max gauge hikaricp_connections_max{pool="HikariPool-1",} 10.0
# HELP jvm_gc_live_data_size_bytes Size of long-lived heap memory pool after reclamation
# TYPE jvm_gc_live_data_size_bytes gauge jvm_gc_live_data_size_bytes 0.0
# HELP jvm_classes_unloaded_classes_total The total number of classes unloaded since the Java virtual machine has started execution
# TYPE jvm_classes_unloaded_classes_total counter jvm_classes_unloaded_classes_total 0.0
# HELP hikaricp_connections_idle Idle connections
# TYPE hikaricp_connections_idle gauge hikaricp_connections_idle{pool="HikariPool-1",} 10.0
# HELP hikaricp_connections Total connections
# TYPE hikaricp_connections gauge hikaricp_connections{pool="HikariPool-1",} 10.0
# HELP jvm_gc_pause_seconds Time spent in GC pause
# TYPE jvm_gc_pause_seconds summary jvm_gc_pause_seconds_count{action="end of minor GC",cause="Metadata GC
Threshold",} 1.0 jvm_gc_pause_seconds_sum{action="end of minor
GC",cause="Metadata GC Threshold",} 0.004
jvm_gc_pause_seconds_count{action="end of minor GC",cause="G1
Evacuation Pause",} 9.0 jvm_gc_pause_seconds_sum{action="end of minor
GC",cause="G1 Evacuation Pause",} 0.038
# HELP jvm_gc_pause_seconds_max Time spent in GC pause
# TYPE jvm_gc_pause_seconds_max gauge jvm_gc_pause_seconds_max{action="end of minor GC",cause="Metadata GC
Threshold",} 0.0 jvm_gc_pause_seconds_max{action="end of minor
GC",cause="G1 Evacuation Pause",} 0.0
# HELP jvm_gc_memory_allocated_bytes_total Incremented for an increase in the size of the (young) heap memory pool after one GC to before the
next
# TYPE jvm_gc_memory_allocated_bytes_total counter jvm_gc_memory_allocated_bytes_total 2.42221056E8
# HELP hikaricp_connections_acquire_seconds Connection acquire time
# TYPE hikaricp_connections_acquire_seconds summary hikaricp_connections_acquire_seconds_count{pool="HikariPool-1",} 0.0
hikaricp_connections_acquire_seconds_sum{pool="HikariPool-1",} 0.0
# HELP hikaricp_connections_acquire_seconds_max Connection acquire time
# TYPE hikaricp_connections_acquire_seconds_max gauge hikaricp_connections_acquire_seconds_max{pool="HikariPool-1",} 0.0
# HELP process_start_time_seconds Start time of the process since unix epoch.
# TYPE process_start_time_seconds gauge process_start_time_seconds 1.631847251003E9
# HELP tomcat_sessions_created_sessions_total  
# TYPE tomcat_sessions_created_sessions_total counter tomcat_sessions_created_sessions_total 0.0
# HELP jvm_buffer_memory_used_bytes An estimate of the memory that the Java virtual machine is using for this buffer pool
# TYPE jvm_buffer_memory_used_bytes gauge jvm_buffer_memory_used_bytes{id="mapped - 'non-volatile memory'",} 0.0
jvm_buffer_memory_used_bytes{id="mapped",} 0.0
jvm_buffer_memory_used_bytes{id="direct",} 32768.0
# HELP system_cpu_count The number of processors available to the Java virtual machine
# TYPE system_cpu_count gauge system_cpu_count 8.0
# HELP hikaricp_connections_min Min connections
# TYPE hikaricp_connections_min gauge hikaricp_connections_min{pool="HikariPool-1",} 10.0

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.4</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.planosaude</groupId>
    <artifactId>planosaude-sys</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>planosaude-sys</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>11</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-registry-prometheus</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
                
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

如果我使用 docker.for.win.localhost,我會收到錯誤消息:

“撥號 tcp:在 127.0.0.11:53 上查找 docker.for.win.localhost:沒有這樣的主機”。

我現在正在嘗試解決這個新錯誤。

解決了

如果我使用host.docker.internal ,它會起作用。

在字段<myip>您應該使用mysql

撰寫中的網絡中所述

服務的每個容器都加入默認網絡,並且可以被該網絡上的其他容器訪問,並且可以在與容器名稱相同的主機名處被它們發現。

如果您使用引用容器本身的localhost ,但在 prometheus 容器內,則只有 prometheus 正在運行,而不是 mysql 實例。

作業抓取 prometheus 正在工作,因為 prometheus 本身在 localhost 中運行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM