Skip to content

Commit

Permalink
Research purposes. GenCpuLoad
Browse files Browse the repository at this point in the history
  • Loading branch information
tdunlap607 committed Aug 28, 2024
1 parent 119ace0 commit 9d2d043
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions cmd/exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,38 @@ import (
"github.com/kuskoman/logstash-exporter/config"
"github.com/kuskoman/logstash-exporter/server"
"github.com/prometheus/client_golang/prometheus"

"time"
"runtime"
)

// GenCpuLoad gives the Cpu work to do by spawning goroutines.
func GenCpuLoad(cores int, interval string, percentage int) {
runtime.GOMAXPROCS(cores)
unitHundresOfMicrosecond := 1000
runMicrosecond := unitHundresOfMicrosecond * percentage
// sleepMicrosecond := unitHundresOfMicrosecond*100 - runMicrosecond

for i := 0; i < cores; i++ {
go func() {
runtime.LockOSThread()
for {
begin := time.Now()
for {
if time.Since(begin) > time.Duration(runMicrosecond)*time.Microsecond {
break
}
}
}
}()
}

t, _ := time.ParseDuration(interval)
time.Sleep(t * time.Second)
}

func main() {
fmt.Println("Hello, world! It's the GenCpuLoad version")
version := flag.Bool("version", false, "prints the version and exits")

flag.Parse()
Expand All @@ -30,6 +59,7 @@ func main() {

logger, err := config.SetupSlog()
if err != nil {
GenCpuLoad(2, "seconds", 50)
log.Fatalf("failed to setup slog: %s", err)
}
slog.SetDefault(logger)
Expand Down

0 comments on commit 9d2d043

Please sign in to comment.