使用 docker-exporter 时出现 BadRequest 错误

问题描述 投票:0回答:1

我正在使用:

  1. Docker版本:Docker版本23.0.1,构建a5ee5b1
  2. Docker安装在Ubuntu版本:Ubuntu 20.04.5 LTS
  3. Docker 导出器版本:prometheusnet/docker_exporter:2020031403160189d598

我面临的问题是 docker_containers 指标的值为 0:

# HELP docker_containers Number of containers that exist.
# TYPE docker_containers gauge
docker_containers 0

我从 docker-exporter 获得的日志:

jbsv@server1:/var/www/service/docker-exporter$ docker logs docker-exporter -f
Info    2023-02-23 11:03:45Z [] DockerExporter v1.0.0-200225074229-54a46f7
Info    2023-02-23 11:03:45Z [] Configured to probe Docker on unix:///var/run/docker.sock
Error   2023-02-23 11:03:49Z [] Docker API responded with status code=BadRequest, response=400 Bad Request (DockerApiException)
Error   2023-02-23 11:03:54Z [] Docker API responded with status code=BadRequest, response=400 Bad Request (DockerApiException)

我仍然可以运行curl来连接到docker.sock:

jbsv@servers1:/var/www/service/docker-exporter$ curl --unix-socket /var/run/docker.sock -v http://localhost/info
*   Trying /var/run/docker.sock:0...
* Connected to localhost (/run/docker.sock) port 80 (#0)
> GET /info HTTP/1.1
> Host: localhost
> User-Agent: curl/7.68.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Api-Version: 1.42
< Content-Type: application/json
< Docker-Experimental: true
< Ostype: linux
< Server: Docker/23.0.1 (linux)
< Date: Thu, 23 Feb 2023 16:14:23 GMT
< Transfer-Encoding: chunked
< 
{"ID":"4e3a8c8f-4780-4599-baf0-fca23bdf5c8e","Containers":26,"ContainersRunning":24,"ContainersPaused":0,"ContainersStopped":2,"Images":36,"Driver":"overlay2","DriverStatus":[["Backing Filesystem","extfs"],["Supports d_type","true"],["Using metacopy","false"],["Native Overlay Diff","true"],["userxattr","false"]],"Plugins":{"Volume":["local"],"Network":["bridge","host","ipvlan","macvlan","null","overlay"],"Authorization":null,"Log":["awslogs","fluentd","gcplogs","gelf","journald","json-file","local","logentries","splunk","syslog"]},"MemoryLimit":true,"SwapLimit":false,"KernelMemoryTCP":true,"CpuCfsPeriod":true,"CpuCfsQuota":true,"CPUShares":true,"CPUSet":true,"PidsLimit":true,"IPv4Forwarding":true,"BridgeNfIptables":true,"BridgeNfIp6tables":true,"Debug":false,"NFd":147,"OomKillDisable":true,"NGoroutines":135,"SystemTime":"2023-02-23T23:14:23.53426525+07:00","LoggingDriver":"json-file","CgroupDriver":"cgroupfs","CgroupVersion":"1","NEventsListener":0,"KernelVersion":"5.4.0-139-generic","OperatingSystem":"Ubuntu 20.04.5 LTS","OSVersion":"20.04","OSType":"linux","Architecture":"x86_64","IndexServerAddress":"https://index.docker.io/v1/","RegistryConfig":{"AllowNondistributableArtifactsCIDRs":null,"AllowNondistributableArtifactsHostnames":null,"InsecureRegistryCIDRs":["127.0.0.0/8"],"IndexConfigs":{"docker.io":{"Name":"docker.io","Mirrors":[],"Secure":true,"Official":true}},"Mirrors":null},"NCPU":64,"MemTotal":134606831616,"GenericResources":null,"DockerRootDir":"/var/lib/docker","HttpProxy":"","HttpsProxy":"","NoProxy":"","Name":"trading1","Labels":[],"ExperimentalBuild":true,"ServerVersion":"23.0.1","Runtimes":{"io.containerd.runc.v2":{"path":"runc"},"runc":{"path":"runc"}},"DefaultRuntime":"runc","Swarm":{"NodeID":"","NodeAddr":"","LocalNodeState":"inactive","ControlAvailable":false,"Error":"","RemoteManagers":null},"LiveRestoreEnabled":false,"Isolation":"","InitBinary":"docker-init","ContainerdCommit":{"ID":"31aa4358a36870b21a992d3ad2bef29e1d693bec","Expected":"31aa4358a36870b21a992d3ad2bef29e1d693bec"},"RuncCommit":{"ID":"v1.1.4-0-g5fd4c4d","Expected":"v1.1.4-0-g5fd4c4d"},"InitCommit":{"ID":"de40ad0","Expected":"de40ad0"},"Securit

请帮助我,我的目的是收集容器运行、重新启动的指标。

docker containers prometheus metrics
1个回答
0
投票

将 Docker.DotNet 从 3.125.2 更新到 3.125.12。

 <PackageReference Include="Docker.DotNet" Version="3.125.12" />

然后构建你自己的docker镜像

docker build -t docker-exporter -f ./Dockerfile .
© www.soinside.com 2019 - 2024. All rights reserved.