Skip to content

Commit

Permalink
added job type metrics label
Browse files Browse the repository at this point in the history
  • Loading branch information
kuzxnia committed Feb 18, 2024
1 parent a8dea2c commit 6c6f1bb
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 30 deletions.
3 changes: 0 additions & 3 deletions cli/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ func StartAgent(context context.Context, config *lbot.AgentRequest, stdin bool,
if lo.IsEmpty(requestConfig.Agent.Port) {
requestConfig.Agent.Port = "1234"
}
if lo.IsEmpty(requestConfig.Agent.MetricsExportPort) {
requestConfig.Agent.MetricsExportPort = "9090"
}

if lo.IsNotEmpty(config.Name) {
requestConfig.Agent.Name = config.Name
Expand Down
8 changes: 3 additions & 5 deletions cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

"github.com/kuzxnia/loadbot/lbot"
"github.com/kuzxnia/loadbot/lbot/proto"
log "github.com/sirupsen/logrus"
"google.golang.org/grpc"
)

Expand All @@ -21,16 +20,15 @@ import (
func SetConfigDriver(conn *grpc.ClientConn, parsedConfig *lbot.ConfigRequest) (err error) {
requestConfig := BuildConfigRequest(parsedConfig)

log.Info("🚀 Setting new config")
fmt.Println("🚀 Setting new config")

client := proto.NewSetConfigProcessClient(conn)
reply, err := client.Run(context.TODO(), requestConfig)
_, err = client.Run(context.TODO(), requestConfig)
if err != nil {
return fmt.Errorf("Setting config failed: %w", err)
}

log.Infof("Received: %v", reply)
log.Info("✅ Setting config succeeded")
fmt.Println("✅ Setting config succeeded")

return
}
Expand Down
8 changes: 3 additions & 5 deletions cli/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"

"github.com/kuzxnia/loadbot/lbot/proto"
log "github.com/sirupsen/logrus"
"google.golang.org/grpc"
)

Expand All @@ -14,17 +13,16 @@ import (
// tutaj nie powinno wchodzić proto
func StartDriver(conn grpc.ClientConnInterface, request *proto.StartRequest) (err error) {
// todo: mapowanie to proto
log.Info("🚀 Starting stress test")
fmt.Println("🚀 Starting stress test")

client := proto.NewStartProcessClient(conn)

reply, err := client.Run(context.TODO(), request)
_, err = client.Run(context.TODO(), request)
if err != nil {
return fmt.Errorf("starting stress test failed: %w", err)
}

log.Infof("Received: %v", reply)
log.Info("✅ Starting stress test succeeded")
fmt.Println("✅ Starting stress test succeeded")

return
}
8 changes: 4 additions & 4 deletions cli/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@ package cli

import (
"context"
"fmt"

"github.com/kuzxnia/loadbot/lbot/proto"
log "github.com/sirupsen/logrus"
"google.golang.org/grpc"
)

func StopDriver(conn grpc.ClientConnInterface, request *proto.StopRequest) (err error) {
log.Info("🚀 Stopping stress test")
fmt.Println("🚀 Stopping stress test")

client := proto.NewStopProcessClient(conn)

reply, err := client.Run(context.TODO(), request)
_, err = client.Run(context.TODO(), request)
if err != nil {
log.Fatal("arith error:", err)
return
}

log.Infof("Received: %v", reply)
log.Info("✅ Stopping stress test succeeded")
fmt.Println("✅ Stopping stress test succeeded")

return nil
}
12 changes: 6 additions & 6 deletions docs/setup/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Configure the [agent](/loadbot/setup/agent/) using the following flags:

The metrics available for monitoring encompass both system-level metrics and custom metrics related to your workloads. Here are some popular metrics from a Go application's perspective:

System Metrics:
##### System Metrics:

- `go_goroutines`
- `go_threads`
Expand All @@ -35,20 +35,20 @@ System Metrics:
- `go_memstats_alloc_bytes_total`
- `process_resident_memory_bytes`

Custom Workload Metrics:
##### Custom Workload Metrics:

- `requests_total`
- `requests_error`
- `requests_duration_seconds (histogram)`
- `requests_duration_seconds`

#### Labels for Querying
When querying metrics, you can utilize labels to specify job-related information:
When querying custom workload metrics, you can utilize labels to specify job-related information:

```
{job="job_name_here", job_uuid="auto_generate_uuid", agent="agent_name_here"}
{job="job_name_here", job_uuid="auto_generate_uuid", job_type="write|bulk_write|read|update..." agent="agent_name_here"}
```

Example query:
##### Example query:
```
requests_total{job="workload 1", agent="186.12.9.19"}
```
Expand Down
6 changes: 3 additions & 3 deletions lbot/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,16 @@ func (a *Agent) Listen() error {
}
}()

if a.lbot.config.Agent.MetricsExportPort != "" {
if lo.IsNotEmpty(a.lbot.config.Agent.MetricsExportPort) {
http.HandleFunc("/metrics", func(w http.ResponseWriter, req *http.Request) {
metrics.WritePrometheus(w, true)
})
go func() {
log.Infof("Started metrics exporter on :%s/metrics", a.lbot.config.Agent.MetricsExportPort)
http.ListenAndServe(":"+a.lbot.config.Agent.MetricsExportPort, nil)
}()
} else if a.lbot.config.Agent.MetricsExportUrl != "" {
log.Info("Started exporting metrics :", a.lbot.config.Agent.MetricsExportPort)
} else if lo.IsNotEmpty(a.lbot.config.Agent.MetricsExportUrl) {
log.Info("Started exporting metrics to ", a.lbot.config.Agent.MetricsExportUrl)

metricsLabels := lo.If(
a.lbot.config.Agent.Name != "",
Expand Down
2 changes: 1 addition & 1 deletion lbot/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func NewWorker(ctx context.Context, cfg *config.Config, job *config.Job, dataPoo
worker.wg.Add(int(job.Connections))
worker.pool = NewJobPool(job)
worker.rateLimiter = NewLimiter(job)
worker.Metrics = NewMetrics(job.Name)
worker.Metrics = NewMetrics(job)
worker.done = false

// introduce no db worker
Expand Down
7 changes: 4 additions & 3 deletions lbot/driver/metrics.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package driver

import (
"fmt"
"time"

"github.com/VictoriaMetrics/metrics"
"github.com/google/uuid"
"github.com/kuzxnia/loadbot/lbot/config"
)

type Metrics struct {
Expand All @@ -15,9 +17,8 @@ type Metrics struct {
// ResponseSize *metrics.Histogram
}

func NewMetrics(job_name string) *Metrics {
// toto: move uuid to worker, and change label to worker uuid
jobLabel := "{job=\"" + job_name + "\", job_uuid=\"" + uuid.New().String() + "\"}"
func NewMetrics(job *config.Job) *Metrics {
jobLabel := fmt.Sprintf(`{job="%s",job_uuid="%s",job_type="%s"}`, job.Name, uuid.New().String(), job.Type)

return &Metrics{
requests: metrics.NewCounter("requests_total" + jobLabel),
Expand Down

0 comments on commit 6c6f1bb

Please sign in to comment.