mirror of https://github.com/portainer/portainer
fix(home): Show correct number of cpus and total memory for swarm (#2147)
* fix(home): show cpu/mem for swarm * fix(home): add nodes data to snapshot * fix(dashboard): get cpus/mem from snapshot * refactor(home): remove temp variablepull/2160/merge
parent
f3dc67a852
commit
594daf0de8
|
@ -30,6 +30,11 @@ func snapshot(cli *client.Client) (*portainer.Snapshot, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = snapshotNodes(snapshot, cli)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = snapshotContainers(snapshot, cli)
|
err = snapshotContainers(snapshot, cli)
|
||||||
|
@ -64,6 +69,22 @@ func snapshotInfo(snapshot *portainer.Snapshot, cli *client.Client) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func snapshotNodes(snapshot *portainer.Snapshot, cli *client.Client) error {
|
||||||
|
nodes, err := cli.NodeList(context.Background(), types.NodeListOptions{})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
var nanoCpus int64
|
||||||
|
var totalMem int64
|
||||||
|
for _, node := range nodes {
|
||||||
|
nanoCpus += node.Description.Resources.NanoCPUs
|
||||||
|
totalMem += node.Description.Resources.MemoryBytes
|
||||||
|
}
|
||||||
|
snapshot.TotalCPU = int(nanoCpus / 1e9)
|
||||||
|
snapshot.TotalMemory = totalMem
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func snapshotSwarmServices(snapshot *portainer.Snapshot, cli *client.Client) error {
|
func snapshotSwarmServices(snapshot *portainer.Snapshot, cli *client.Client) error {
|
||||||
stacks := make(map[string]struct{})
|
stacks := make(map[string]struct{})
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,10 @@
|
||||||
<td>Endpoint</td>
|
<td>Endpoint</td>
|
||||||
<td>
|
<td>
|
||||||
{{ endpoint.Name }}
|
{{ endpoint.Name }}
|
||||||
<span class="small text-muted space-left"><i class="fa fa-microchip"></i> {{ info.NCPU }}<i class="fa fa-memory space-left"></i> {{ info.MemTotal | humansize }}</span>
|
<span class="small text-muted space-left">
|
||||||
|
<i class="fa fa-microchip"></i> {{ endpoint.Snapshots[0].TotalCPU }}
|
||||||
|
<i class="fa fa-memory space-left"></i> {{ endpoint.Snapshots[0].TotalMemory | humansize }}
|
||||||
|
</span>
|
||||||
<span class="small text-muted"> - {{ info.Swarm && info.Swarm.NodeID !== '' ? 'Swarm' : 'Standalone' }} {{ info.ServerVersion }} <span ng-if="endpoint.Type === 2">+ <i class="fa fa-bolt" aria-hidden="true"></i> Agent</span></span>
|
<span class="small text-muted"> - {{ info.Swarm && info.Swarm.NodeID !== '' ? 'Swarm' : 'Standalone' }} {{ info.ServerVersion }} <span ng-if="endpoint.Type === 2">+ <i class="fa fa-bolt" aria-hidden="true"></i> Agent</span></span>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
@ -58,7 +58,7 @@
|
||||||
|
|
||||||
<div class="blocklist-item-line endpoint-item">
|
<div class="blocklist-item-line endpoint-item">
|
||||||
<span class="small text-muted">
|
<span class="small text-muted">
|
||||||
<span ng-if="$ctrl.model.Type === 1 && !$ctrl.model.Snapshots[0].Swarm">
|
<span ng-if="$ctrl.model.Type === 1">
|
||||||
<span class="small text-muted">
|
<span class="small text-muted">
|
||||||
<i class="fa fa-microchip"></i> {{ $ctrl.model.Snapshots[0].TotalCPU }}<i class="fa fa-memory space-left"></i> {{ $ctrl.model.Snapshots[0].TotalMemory | humansize }}
|
<i class="fa fa-microchip"></i> {{ $ctrl.model.Snapshots[0].TotalCPU }}<i class="fa fa-memory space-left"></i> {{ $ctrl.model.Snapshots[0].TotalMemory | humansize }}
|
||||||
</span>
|
</span>
|
||||||
|
|
Loading…
Reference in New Issue