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