Skip to content

Commit d0e4433

Browse files
authored
Merge pull request #1128 from utmstack/bugfix/10.7.2/installer-resource-distribution
Bugfix/10.7.2/installer resource distribution
2 parents a8c3283 + df160b8 commit d0e4433

File tree

3 files changed

+108
-22
lines changed

3 files changed

+108
-22
lines changed

installer/sample/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.csv

installer/sample/sample.go

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package main
2+
3+
import (
4+
"encoding/csv"
5+
"fmt"
6+
"log"
7+
"os"
8+
"sort"
9+
"strconv"
10+
11+
"github.com/utmstack/UTMStack/installer/types"
12+
"github.com/utmstack/UTMStack/installer/utils"
13+
)
14+
15+
func main() {
16+
// Total memory values in MB.
17+
totals := []int{16000, 20000, 32000, 48000, 64000, 120000, 200000}
18+
19+
// Create a sorted copy of the services (sorted by Priority then Name).
20+
sortedServices := make([]utils.ServiceConfig, len(types.Services))
21+
copy(sortedServices, types.Services)
22+
sort.Slice(sortedServices, func(i, j int) bool {
23+
if sortedServices[i].Priority == sortedServices[j].Priority {
24+
return sortedServices[i].Name < sortedServices[j].Name
25+
}
26+
return sortedServices[i].Priority < sortedServices[j].Priority
27+
})
28+
29+
// Create the output CSV file.
30+
file, err := os.Create("output.csv")
31+
if err != nil {
32+
log.Fatalf("Error creating CSV file: %v", err)
33+
}
34+
defer file.Close()
35+
36+
// Create a CSV writer.
37+
writer := csv.NewWriter(file)
38+
defer writer.Flush()
39+
40+
// Iterate over each total memory value.
41+
for _, total := range totals {
42+
// Write a comment line indicating the total memory.
43+
comment := fmt.Sprintf("# Total Memory: %d MB", total)
44+
// Since csv.Writer does not support comment lines,
45+
// write the comment directly to the file.
46+
if _, err := file.WriteString(comment + "\n"); err != nil {
47+
log.Fatalf("Error writing comment: %v", err)
48+
}
49+
50+
// Write the header row.
51+
if err := writer.Write([]string{"Service", "AssignedMemory"}); err != nil {
52+
log.Fatalf("Error writing header: %v", err)
53+
}
54+
55+
// Balance memory using the utils package.
56+
rsrcs, err := utils.BalanceMemory(types.Services, total)
57+
if err != nil {
58+
log.Fatalf("Error balancing memory for total %d MB: %v", total, err)
59+
}
60+
61+
// Write each service's allocated memory.
62+
for _, svc := range sortedServices {
63+
// Assume that rsrcs[svc.Name] returns a pointer to a ServiceConfig,
64+
// and that AssignedMemory is an integer field.
65+
assigned := rsrcs[svc.Name].AssignedMemory
66+
row := []string{svc.Name, strconv.Itoa(assigned)}
67+
if err := writer.Write(row); err != nil {
68+
log.Fatalf("Error writing row: %v", err)
69+
}
70+
}
71+
72+
// Flush the CSV writer so far.
73+
writer.Flush()
74+
if err := writer.Error(); err != nil {
75+
log.Fatalf("Error flushing CSV writer: %v", err)
76+
}
77+
78+
// Write an empty line to separate tables.
79+
if _, err := file.WriteString("\n"); err != nil {
80+
log.Fatalf("Error writing empty line: %v", err)
81+
}
82+
}
83+
84+
log.Println("CSV file 'output.csv' created successfully")
85+
}

installer/types/stack.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,26 @@ type StackConfig struct {
2121
ShmFolder string
2222
}
2323

24+
var Services = []utils.ServiceConfig{
25+
{Name: "correlation", Priority: 1, MinMemory: 3 * 1024, MaxMemory: 60 * 1024},
26+
{Name: "logstash", Priority: 1, MinMemory: 2700, MaxMemory: 60 * 1024},
27+
{Name: "opensearch", Priority: 1, MinMemory: 4500, MaxMemory: 60 * 1024},
28+
{Name: "log-auth-proxy", Priority: 1, MinMemory: 1 * 1024, MaxMemory: 4 * 1024},
29+
{Name: "backend", Priority: 2, MinMemory: 700, MaxMemory: 8 * 1024},
30+
{Name: "web-pdf", Priority: 2, MinMemory: 1024, MaxMemory: 2 * 1024},
31+
{Name: "postgres", Priority: 2, MinMemory: 500, MaxMemory: 1 * 1024},
32+
{Name: "user-auditor", Priority: 3, MinMemory: 200, MaxMemory: 1024},
33+
{Name: "agentmanager", Priority: 3, MinMemory: 200, MaxMemory: 1024},
34+
{Name: "mutate", Priority: 3, MinMemory: 50, MaxMemory: 1024},
35+
{Name: "aws", Priority: 3, MinMemory: 50, MaxMemory: 1024},
36+
{Name: "filebrowser", Priority: 3, MinMemory: 50, MaxMemory: 512},
37+
{Name: "sophos", Priority: 3, MinMemory: 50, MaxMemory: 1024},
38+
{Name: "frontend", Priority: 3, MinMemory: 80, MaxMemory: 1024},
39+
{Name: "socai", Priority: 3, MinMemory: 30, MaxMemory: 512},
40+
{Name: "bitdefender", Priority: 3, MinMemory: 30, MaxMemory: 100},
41+
{Name: "office365", Priority: 3, MinMemory: 30, MaxMemory: 100},
42+
}
43+
2444
func (s *StackConfig) Populate(c *Config) error {
2545
cores, err := cpu.Counts(false)
2646
if err != nil {
@@ -45,29 +65,9 @@ func (s *StackConfig) Populate(c *Config) error {
4565
s.LocksDir = utils.MakeDir(0777, c.DataDir, "locks")
4666
s.ShmFolder = utils.MakeDir(0777, c.DataDir, "tmpfs")
4767

48-
services := []utils.ServiceConfig{
49-
{Name: "correlation", Priority: 1, MinMemory: 4 * 1024, MaxMemory: 60 * 1024},
50-
{Name: "logstash", Priority: 1, MinMemory: 2700, MaxMemory: 60 * 1024},
51-
{Name: "opensearch", Priority: 1, MinMemory: 4500, MaxMemory: 60 * 1024},
52-
{Name: "log-auth-proxy", Priority: 1, MinMemory: 128, MaxMemory: 512},
53-
{Name: "backend", Priority: 2, MinMemory: 700, MaxMemory: 2 * 1024},
54-
{Name: "web-pdf", Priority: 2, MinMemory: 1024, MaxMemory: 2 * 1024},
55-
{Name: "postgres", Priority: 2, MinMemory: 500, MaxMemory: 1 * 1024},
56-
{Name: "user-auditor", Priority: 3, MinMemory: 200, MaxMemory: 1024},
57-
{Name: "agentmanager", Priority: 3, MinMemory: 200, MaxMemory: 1024},
58-
{Name: "mutate", Priority: 3, MinMemory: 50, MaxMemory: 1024},
59-
{Name: "aws", Priority: 3, MinMemory: 50, MaxMemory: 1024},
60-
{Name: "filebrowser", Priority: 3, MinMemory: 50, MaxMemory: 512},
61-
{Name: "sophos", Priority: 3, MinMemory: 50, MaxMemory: 1024},
62-
{Name: "frontend", Priority: 3, MinMemory: 80, MaxMemory: 1024},
63-
{Name: "socai", Priority: 3, MinMemory: 30, MaxMemory: 1024},
64-
{Name: "bitdefender", Priority: 3, MinMemory: 30, MaxMemory: 512},
65-
{Name: "office365", Priority: 3, MinMemory: 30, MaxMemory: 512},
66-
}
67-
68-
total := int(mem.Total/1024/1024) - utils.SYSTEM_RESERVED_MEMORY
68+
total := int(mem.Total / 1024 / 1024)
6969

70-
rsrcs, err := utils.BalanceMemory(services, total)
70+
rsrcs, err := utils.BalanceMemory(Services, total)
7171
if err != nil {
7272
return err
7373
}

0 commit comments

Comments
 (0)