Skip to content

Commit

Permalink
resolved conflict
Browse files Browse the repository at this point in the history
Signed-off-by: Shlomi Noach <[email protected]>
  • Loading branch information
shlomi-noach committed Nov 11, 2024
1 parent 9341eb8 commit e3c5ebd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 40 deletions.
14 changes: 2 additions & 12 deletions go/vt/mysqlctl/mysqld.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import (
"vitess.io/vitess/config"
"vitess.io/vitess/go/mysql"
"vitess.io/vitess/go/mysql/sqlerror"
"vitess.io/vitess/go/osutil"
"vitess.io/vitess/go/protoutil"
"vitess.io/vitess/go/sqltypes"
"vitess.io/vitess/go/vt/dbconfigs"
Expand Down Expand Up @@ -1332,18 +1333,7 @@ func hostMetrics(ctx context.Context, cnf *Mycnf) (*mysqlctlpb.HostMetricsRespon

_ = func() error {
metric := newMetric("loadavg")
if runtime.GOOS != "linux" {
return withError(metric, fmt.Errorf("loadavg metric is only available on Linux"))
}
content, err := os.ReadFile("/proc/loadavg")
if err != nil {
return withError(metric, err)
}
fields := strings.Fields(string(content))
if len(fields) == 0 {
return withError(metric, fmt.Errorf("unexpected /proc/loadavg content"))
}
loadAvg, err := strconv.ParseFloat(fields[0], 64)
loadAvg, err := osutil.LoadAvg()
if err != nil {
return withError(metric, err)
}
Expand Down
33 changes: 5 additions & 28 deletions go/vt/vttablet/tabletserver/throttle/base/self_metric_loadavg.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,12 @@ package base

import (
"context"
"fmt"
"os"
"runtime"
"strconv"
"strings"

"vitess.io/vitess/go/osutil"
"vitess.io/vitess/go/vt/vttablet/tabletserver/connpool"
)

var (
loadavgOnlyAvailableOnLinuxMetric = &ThrottleMetric{
Scope: SelfScope,
Err: fmt.Errorf("loadavg metric is only available on Linux"),
}
)

var _ SelfMetric = registerSelfMetric(&LoadAvgSelfMetric{})

type LoadAvgSelfMetric struct {
Expand All @@ -56,26 +46,13 @@ func (m *LoadAvgSelfMetric) RequiresConn() bool {
}

func (m *LoadAvgSelfMetric) Read(ctx context.Context, throttler ThrottlerMetricsPublisher, conn *connpool.Conn) *ThrottleMetric {
if runtime.GOOS != "linux" {
return loadavgOnlyAvailableOnLinuxMetric
}
metric := &ThrottleMetric{
Scope: SelfScope,
}
{
content, err := os.ReadFile("/proc/loadavg")
if err != nil {
return metric.WithError(err)
}
fields := strings.Fields(string(content))
if len(fields) == 0 {
return metric.WithError(fmt.Errorf("unexpected /proc/loadavg content"))
}
loadAvg, err := strconv.ParseFloat(fields[0], 64)
if err != nil {
return metric.WithError(err)
}
metric.Value = loadAvg / float64(runtime.NumCPU())
val, err := osutil.LoadAvg()
if err != nil {
return metric.WithError(err)
}
metric.Value = val / float64(runtime.NumCPU())
return metric
}

0 comments on commit e3c5ebd

Please sign in to comment.