Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hover text to instance metrics, surfacing details about cached memory and disk size #1112

Merged
merged 1 commit into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/components/Meter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ interface Props {
percentage: number;
secondaryPercentage?: number;
text: string;
hoverText?: string;
}

const Meter: FC<Props> = ({
percentage,
secondaryPercentage = 0,
text,
hoverText,
}: Props) => {
return (
<>
<div className="p-meter u-no-margin--bottom">
<div className="p-meter u-no-margin--bottom" title={hoverText}>
<div
style={{ width: `max(${percentage}%, 5px)` }}
className={classnames({
Expand Down
23 changes: 12 additions & 11 deletions src/pages/instances/InstanceDisk.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,26 @@ const InstanceUsageDisk: FC<Props> = ({ instance }) => {
const { data: metrics = [] } = useMetrics(instance.location);

const instanceMetrics = getInstanceMetrics(metrics, instance);
const disk = instanceMetrics.disk;

return instanceMetrics.disk ? (
if (!disk) {
return "";
}

const used = disk.total - disk.free;

return (
<div>
<Meter
percentage={
(100 / instanceMetrics.disk.total) *
(instanceMetrics.disk.total - instanceMetrics.disk.free)
}
percentage={(100 / disk.total) * used}
text={
humanFileSize(
instanceMetrics.disk.total - instanceMetrics.disk.free,
) +
humanFileSize(disk.total - disk.free) +
" of " +
humanFileSize(instanceMetrics.disk.total)
humanFileSize(disk.total)
}
hoverText={`free: ${humanFileSize(disk.free)}\nused: ${humanFileSize(used)}`}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never thought of using new line chars with title attribute, neat 👍

/>
</div>
) : (
""
);
};

Expand Down
33 changes: 17 additions & 16 deletions src/pages/instances/InstanceUsageMemory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,30 @@ const InstanceUsageMemory: FC<Props> = ({ instance }) => {

const instanceMetrics = getInstanceMetrics(metrics, instance);

return instanceMetrics.memory ? (
const memory = instanceMetrics.memory;
if (!memory) {
return "";
}

const used = memory.total - memory.free - memory.cached;

return (
<div>
<Meter
percentage={
(100 / instanceMetrics.memory.total) *
(instanceMetrics.memory.total -
instanceMetrics.memory.free -
instanceMetrics.memory.cached)
}
secondaryPercentage={
(100 / instanceMetrics.memory.total) * instanceMetrics.memory.cached
}
percentage={(100 / memory.total) * used}
secondaryPercentage={(100 / memory.total) * memory.cached}
text={
humanFileSize(
instanceMetrics.memory.total - instanceMetrics.memory.free,
) +
humanFileSize(memory.total - memory.free) +
" of " +
humanFileSize(instanceMetrics.memory.total)
humanFileSize(memory.total)
}
hoverText={
`free: ${humanFileSize(memory.free)}\n` +
`used: ${humanFileSize(used)}\n` +
`cached: ${humanFileSize(memory.cached)}\n`
}
/>
</div>
) : (
""
);
};

Expand Down