Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

1.8 KB
Raw Blame
import type { ResourceType as HistoryResourceType } from '@/api/charts';
import { HOST_METRICS_HISTORY_GROUPS } from '@/components/shared/hostMetricsHistoryModel';
import type { Resource } from '@/types/resource';

import type {
  GuestDrawerHistoryGroupConfig,
  GuestDrawerHistoryTarget,
} from '@/components/Workloads/guestDrawerModel';

export interface DockerHostDrawerHistoryTarget extends GuestDrawerHistoryTarget {
  resourceType: Extract<HistoryResourceType, 'agent' | 'docker-host'>;
}

const stripAgentPrefix = (value: string): string =>
  value.startsWith('agent:') ? value.slice('agent:'.length) : value;

// Docker hosts report the same agent telemetry shape as PVE nodes and
// standalone machines, so all host drawers consume one shared group catalog.
export const DOCKER_HOST_DRAWER_HISTORY_GROUPS: GuestDrawerHistoryGroupConfig[] =
  HOST_METRICS_HISTORY_GROUPS;

export const getDockerHostDrawerHistoryTarget = (
  host: Resource,
): DockerHostDrawerHistoryTarget | null => {
  const explicitType = host.metricsTarget?.resourceType;
  const explicitId = host.metricsTarget?.resourceId.trim();
  if ((explicitType === 'agent' || explicitType === 'docker-host') && explicitId) {
    return { resourceType: explicitType, resourceId: explicitId };
  }

  const candidate = host.agent?.agentId || host.id || host.name || '';
  const resourceId = stripAgentPrefix(candidate.trim());
  if (!resourceId) return null;
  return { resourceType: 'agent', resourceId };
};

export const getDockerHostDrawerCurrentMetrics = (
  host: Resource,
): Record<string, number | undefined> => {
  const finite = (value: number | undefined): number | undefined =>
    typeof value === 'number' && Number.isFinite(value) ? value : undefined;
  const temperature = finite(host.temperature) ?? finite(host.docker?.temperature);
  return { temperature };
};