mirror of https://github.com/portainer/portainer
fix(docker): include healthy containers in running [EE-6264] (#10746)
parent
a305fe9e4c
commit
115b01cee3
|
@ -669,6 +669,7 @@
|
||||||
"snapshots": [
|
"snapshots": [
|
||||||
{
|
{
|
||||||
"Docker": {
|
"Docker": {
|
||||||
|
"ContainerCount": 0,
|
||||||
"DockerSnapshotRaw": {
|
"DockerSnapshotRaw": {
|
||||||
"Containers": null,
|
"Containers": null,
|
||||||
"Images": null,
|
"Images": null,
|
||||||
|
|
|
@ -201,9 +201,12 @@ func snapshotContainers(snapshot *portainer.DockerSnapshot, cli *client.Client)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.Contains(container.Status, "(healthy)") {
|
if container.State == "healthy" {
|
||||||
|
runningContainers++
|
||||||
healthyContainers++
|
healthyContainers++
|
||||||
} else if strings.Contains(container.Status, "(unhealthy)") {
|
}
|
||||||
|
|
||||||
|
if container.State == "unhealthy" {
|
||||||
unhealthyContainers++
|
unhealthyContainers++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,6 +225,7 @@ func snapshotContainers(snapshot *portainer.DockerSnapshot, cli *client.Client)
|
||||||
snapshot.GpuUseAll = gpuUseAll
|
snapshot.GpuUseAll = gpuUseAll
|
||||||
snapshot.GpuUseList = gpuUseList
|
snapshot.GpuUseList = gpuUseList
|
||||||
|
|
||||||
|
snapshot.ContainerCount = len(containers)
|
||||||
snapshot.RunningContainerCount = runningContainers
|
snapshot.RunningContainerCount = runningContainers
|
||||||
snapshot.StoppedContainerCount = stoppedContainers
|
snapshot.StoppedContainerCount = stoppedContainers
|
||||||
snapshot.HealthyContainerCount = healthyContainers
|
snapshot.HealthyContainerCount = healthyContainers
|
||||||
|
|
|
@ -215,6 +215,7 @@ type (
|
||||||
Swarm bool `json:"Swarm"`
|
Swarm bool `json:"Swarm"`
|
||||||
TotalCPU int `json:"TotalCPU"`
|
TotalCPU int `json:"TotalCPU"`
|
||||||
TotalMemory int64 `json:"TotalMemory"`
|
TotalMemory int64 `json:"TotalMemory"`
|
||||||
|
ContainerCount int `json:"ContainerCount"`
|
||||||
RunningContainerCount int `json:"RunningContainerCount"`
|
RunningContainerCount int `json:"RunningContainerCount"`
|
||||||
StoppedContainerCount int `json:"StoppedContainerCount"`
|
StoppedContainerCount int `json:"StoppedContainerCount"`
|
||||||
HealthyContainerCount int `json:"HealthyContainerCount"`
|
HealthyContainerCount int `json:"HealthyContainerCount"`
|
||||||
|
|
|
@ -2,7 +2,10 @@ import { Heart, Power } from 'lucide-react';
|
||||||
|
|
||||||
import { Icon } from '@/react/components/Icon';
|
import { Icon } from '@/react/components/Icon';
|
||||||
|
|
||||||
import { DockerContainer } from '../containers/types';
|
import {
|
||||||
|
DockerContainer,
|
||||||
|
ContainerStatus as Status,
|
||||||
|
} from '../containers/types';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
containers: DockerContainer[];
|
containers: DockerContainer[];
|
||||||
|
@ -40,20 +43,22 @@ export function ContainerStatus({ containers }: Props) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function runningContainersFilter(containers: DockerContainer[]) {
|
function runningContainersFilter(containers: DockerContainer[]) {
|
||||||
return containers.filter((container) => container.Status === 'running')
|
return containers.filter(
|
||||||
.length;
|
(container) =>
|
||||||
|
container.Status === Status.Running || container.Status === Status.Healthy
|
||||||
|
).length;
|
||||||
}
|
}
|
||||||
function stoppedContainersFilter(containers: DockerContainer[]) {
|
function stoppedContainersFilter(containers: DockerContainer[]) {
|
||||||
return containers.filter(
|
return containers.filter(
|
||||||
(container) =>
|
(container) =>
|
||||||
container.Status === 'exited' || container.Status === 'stopped'
|
container.Status === Status.Exited || container.Status === Status.Stopped
|
||||||
).length;
|
).length;
|
||||||
}
|
}
|
||||||
function healthyContainersFilter(containers: DockerContainer[]) {
|
function healthyContainersFilter(containers: DockerContainer[]) {
|
||||||
return containers.filter((container) => container.Status === 'healthy')
|
return containers.filter((container) => container.Status === Status.Healthy)
|
||||||
.length;
|
.length;
|
||||||
}
|
}
|
||||||
function unhealthyContainersFilter(containers: DockerContainer[]) {
|
function unhealthyContainersFilter(containers: DockerContainer[]) {
|
||||||
return containers.filter((container) => container.Status === 'unhealthy')
|
return containers.filter((container) => container.Status === Status.Unhealthy)
|
||||||
.length;
|
.length;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ export interface DockerSnapshot {
|
||||||
NodeCount: number;
|
NodeCount: number;
|
||||||
ImageCount: number;
|
ImageCount: number;
|
||||||
VolumeCount: number;
|
VolumeCount: number;
|
||||||
|
ContainerCount: number;
|
||||||
RunningContainerCount: number;
|
RunningContainerCount: number;
|
||||||
StoppedContainerCount: number;
|
StoppedContainerCount: number;
|
||||||
HealthyContainerCount: number;
|
HealthyContainerCount: number;
|
||||||
|
|
|
@ -41,6 +41,7 @@ export function EnvironmentStatsDocker({ snapshot }: Props) {
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<ContainerStats
|
<ContainerStats
|
||||||
|
total={snapshot.ContainerCount}
|
||||||
running={snapshot.RunningContainerCount}
|
running={snapshot.RunningContainerCount}
|
||||||
stopped={snapshot.StoppedContainerCount}
|
stopped={snapshot.StoppedContainerCount}
|
||||||
healthy={snapshot.HealthyContainerCount}
|
healthy={snapshot.HealthyContainerCount}
|
||||||
|
@ -70,6 +71,7 @@ export function EnvironmentStatsDocker({ snapshot }: Props) {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ContainerStatsProps {
|
interface ContainerStatsProps {
|
||||||
|
total: number;
|
||||||
running: number;
|
running: number;
|
||||||
stopped: number;
|
stopped: number;
|
||||||
healthy: number;
|
healthy: number;
|
||||||
|
@ -77,16 +79,16 @@ interface ContainerStatsProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
function ContainerStats({
|
function ContainerStats({
|
||||||
|
total,
|
||||||
running,
|
running,
|
||||||
stopped,
|
stopped,
|
||||||
healthy,
|
healthy,
|
||||||
unhealthy,
|
unhealthy,
|
||||||
}: ContainerStatsProps) {
|
}: ContainerStatsProps) {
|
||||||
const containersCount = running + stopped;
|
const actualTotal = total || running + stopped;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StatsItem value={addPlural(containersCount, 'container')} icon={Box}>
|
<StatsItem value={addPlural(actualTotal, 'container')} icon={Box}>
|
||||||
{containersCount > 0 && (
|
{actualTotal > 0 && (
|
||||||
<>
|
<>
|
||||||
<StatsItem value={running} icon={Power} iconClass="icon-success" />
|
<StatsItem value={running} icon={Power} iconClass="icon-success" />
|
||||||
<StatsItem value={stopped} icon={Power} iconClass="icon-danger" />
|
<StatsItem value={stopped} icon={Power} iconClass="icon-danger" />
|
||||||
|
|
Loading…
Reference in New Issue