-
-
Notifications
You must be signed in to change notification settings - Fork 568
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1ad0637
commit 64c5c0d
Showing
9 changed files
with
628 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.