Skip to content

Commit

Permalink
refactor: update logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Siumauricio committed Jan 4, 2025
1 parent 1ad0637 commit 64c5c0d
Show file tree
Hide file tree
Showing 9 changed files with 628 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ interface FormattedMetric {
const chartConfig = {
read: {
label: "Read",
color: "hsl(var(--chart-5))",
color: "hsl(217, 91%, 60%)", // Azul brillante
},
write: {
label: "Write",
color: "hsl(var(--chart-6))",
color: "hsl(142, 71%, 45%)", // Verde brillante
},
} satisfies ChartConfig;

Expand Down Expand Up @@ -85,24 +85,24 @@ export const ContainerBlockChart = ({ data }: Props) => {
<linearGradient id="fillRead" x1="0" y1="0" x2="0" y2="1">
<stop
offset="5%"
stopColor="hsl(var(--chart-5))"
stopOpacity={0.8}
stopColor="hsl(217, 91%, 60%)"
stopOpacity={0.3}
/>
<stop
offset="95%"
stopColor="hsl(var(--chart-5))"
stopColor="hsl(217, 91%, 60%)"
stopOpacity={0.1}
/>
</linearGradient>
<linearGradient id="fillWrite" x1="0" y1="0" x2="0" y2="1">
<stop
offset="5%"
stopColor="hsl(var(--chart-6))"
stopOpacity={0.8}
stopColor="hsl(142, 71%, 45%)"
stopOpacity={0.3}
/>
<stop
offset="95%"
stopColor="hsl(var(--chart-6))"
stopColor="hsl(142, 71%, 45%)"
stopOpacity={0.1}
/>
</linearGradient>
Expand Down Expand Up @@ -159,20 +159,22 @@ export const ContainerBlockChart = ({ data }: Props) => {
}}
/>
<Area
name="Read"
dataKey="read"
name="Write"
dataKey="write"
type="monotone"
fill="url(#fillRead)"
stroke="hsl(var(--chart-5))"
fill="url(#fillWrite)"
stroke="hsl(142, 71%, 45%)"
strokeWidth={2}
fillOpacity={0.3}
/>
<Area
name="Write"
dataKey="write"
name="Read"
dataKey="read"
type="monotone"
fill="url(#fillWrite)"
stroke="hsl(var(--chart-6))"
fill="url(#fillRead)"
stroke="hsl(217, 91%, 60%)"
strokeWidth={2}
fillOpacity={0.3}
/>
<ChartLegend
content={<ChartLegendContent />}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ interface ContainerMetric {
percentage: number;
used: number;
total: number;
unit: string;
usedUnit: string;
totalUnit: string;
};
}

Expand All @@ -36,11 +37,18 @@ const chartConfig = {
},
} satisfies ChartConfig;

const formatMemoryValue = (value: number) => {
return value.toLocaleString('en-US', {
minimumFractionDigits: 1,
maximumFractionDigits: 2
});
};

export const ContainerMemoryChart = ({ data }: Props) => {
const formattedData = data.map((metric) => ({
timestamp: metric.timestamp,
memory: metric.Memory.percentage,
usage: `${metric.Memory.used} / ${metric.Memory.total} ${metric.Memory.unit}`,
usage: `${formatMemoryValue(metric.Memory.used)}${metric.Memory.usedUnit} / ${formatMemoryValue(metric.Memory.total)}${metric.Memory.totalUnit}`,
}));

const latestData = formattedData[formattedData.length - 1] || {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { ShowDockerLogs } from "@/components/dashboard/application/logs/show";
import { ShowPreviewDeployments } from "@/components/dashboard/application/preview-deployments/show-preview-deployments";
import { UpdateApplication } from "@/components/dashboard/application/update-application";
import { ContainerMonitoring } from "@/components/dashboard/monitoring/container/show";
import { DockerMonitoring } from "@/components/dashboard/monitoring/docker/show";
// import { DockerMonitoring } from "@/components/dashboard/monitoring/docker/show";
import { ProjectLayout } from "@/components/layouts/project-layout";
import { StatusTooltip } from "@/components/shared/status-tooltip";
import { Badge } from "@/components/ui/badge";
Expand Down
72 changes: 72 additions & 0 deletions apps/golang/containers/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package containers

import (
"encoding/json"
"os"
"strings"
)

var config *MonitoringConfig

func LoadConfig() error {
configStr := os.Getenv("CONTAINER_MONITORING_CONFIG")
if configStr == "" {
config = &MonitoringConfig{
IncludeServices: []ContainerConfig{},
ExcludeServices: []ContainerConfig{},
}
return nil
}

config = &MonitoringConfig{}
return json.Unmarshal([]byte(configStr), config)
}

func ShouldMonitorContainer(containerName string) bool {
if config == nil {
return false
}

// Si está en la lista de excluidos, no monitorear
for _, excluded := range config.ExcludeServices {
if strings.Contains(containerName, excluded.AppName) {
return false
}
}

// Si hay servicios incluidos, solo monitorear esos
if len(config.IncludeServices) > 0 {
for _, included := range config.IncludeServices {
if strings.Contains(containerName, included.AppName) {
return true
}
}
return false
}

return true
}

func GetContainerConfig(containerName string) *ContainerConfig {
if config == nil {
return &ContainerConfig{MaxFileSizeMB: 10}
}

for _, included := range config.IncludeServices {
if strings.Contains(containerName, included.AppName) {
return &included
}
}

return &ContainerConfig{MaxFileSizeMB: 10}
}

func GetServiceName(containerName string) string {
// Eliminar caracteres especiales y obtener el nombre base
name := strings.TrimPrefix(containerName, "/")
parts := strings.Split(name, "-")
if len(parts) > 1 {
return strings.Join(parts[:len(parts)-1], "-")
}
return name
}
Loading

0 comments on commit 64c5c0d

Please sign in to comment.