Skip to content

Commit

Permalink
Fix app name in metric is unknown_ go_ service (alibaba#453)
Browse files Browse the repository at this point in the history
  • Loading branch information
kklinan committed Jan 26, 2022
1 parent ea8c74f commit ce23393
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 25 deletions.
8 changes: 8 additions & 0 deletions api/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ import (
"net"
"net/http"

"github.com/alibaba/sentinel-golang/core/circuitbreaker"
"github.com/alibaba/sentinel-golang/core/config"
"github.com/alibaba/sentinel-golang/core/flow"
"github.com/alibaba/sentinel-golang/core/log/metric"
"github.com/alibaba/sentinel-golang/core/stat"
"github.com/alibaba/sentinel-golang/core/system_metric"
metric_exporter "github.com/alibaba/sentinel-golang/exporter/metric"
"github.com/alibaba/sentinel-golang/util"
Expand Down Expand Up @@ -87,6 +90,11 @@ func initCoreComponents() error {
}
}

flow.Init()
stat.Init()
system_metric.Init()
circuitbreaker.Init()

systemStatInterval := config.SystemStatCollectIntervalMs()
loadStatInterval := systemStatInterval
cpuStatInterval := systemStatInterval
Expand Down
13 changes: 7 additions & 6 deletions core/circuitbreaker/circuit_breaker.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,20 @@ const (
)

var (
stateChangedCounter metric_exporter.Counter
)

func Init() {
stateChangedCounter = metric_exporter.NewCounter(
"circuit_breaker_state_changed_total",
"Circuit breaker total state change count",
[]string{"resource", "from_state", "to_state"})
)

func init() {
[]string{"resource", "from_state", "to_state"},
)
metric_exporter.Register(stateChangedCounter)
}

func newState() *State {
var state State
state = Closed
state := Closed

return &state
}
Expand Down
10 changes: 6 additions & 4 deletions core/flow/traffic_shaping.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ import (
)

var (
resourceFlowThresholdGauge metric_exporter.Gauge
)

func Init() {
resourceFlowThresholdGauge = metric_exporter.NewGauge(
"resource_flow_threshold",
"Resource flow threshold",
[]string{"resource"})
)

func init() {
[]string{"resource"},
)
metric_exporter.Register(resourceFlowThresholdGauge)
}

Expand Down
10 changes: 6 additions & 4 deletions core/stat/stat_slot.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ const (
var (
DefaultSlot = &Slot{}

handledCounter metric_exporter.Counter
)

func Init() {
handledCounter = metric_exporter.NewCounter(
"handled_total",
"Total handled count",
[]string{"resource", "result", "block_type"})
)

func init() {
[]string{"resource", "result", "block_type"},
)
metric_exporter.Register(handledCounter)
}

Expand Down
23 changes: 15 additions & 8 deletions core/system_metric/sys_metric_stat.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,8 @@ var (

ssStopChan = make(chan struct{})

cpuRatioGauge = metric_exporter.NewGauge(
"cpu_ratio",
"Process cpu ratio",
[]string{})
processMemoryGauge = metric_exporter.NewGauge(
"process_memory_bytes",
"Process memory in bytes",
[]string{})
cpuRatioGauge metric_exporter.Gauge
processMemoryGauge metric_exporter.Gauge
)

func init() {
Expand All @@ -73,8 +67,21 @@ func init() {
currentProcessOnce.Do(func() {
currentProcess.Store(p)
})
}

func Init() {
cpuRatioGauge = metric_exporter.NewGauge(
"cpu_ratio",
"Process cpu ratio",
[]string{},
)
metric_exporter.Register(cpuRatioGauge)

processMemoryGauge = metric_exporter.NewGauge(
"process_memory_bytes",
"Process memory in bytes",
[]string{},
)
metric_exporter.Register(processMemoryGauge)
}

Expand Down
4 changes: 1 addition & 3 deletions exporter/metric/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ var (
exporter Exporter

host string
app string
pid string
namespace string
)
Expand All @@ -39,7 +38,6 @@ func init() {
if host == "" {
host = "unknown"
}
app = config.AppName()
pid = strconv.Itoa(os.Getpid())
namespace = "sentinel_go"
}
Expand Down Expand Up @@ -111,8 +109,8 @@ func (e *prometheusExporter) HTTPHandler() http.Handler {
func newConstLabels() map[string]string {
return map[string]string{
"host": host,
"app": app,
"pid": pid,
"app": config.AppName(),
}
}

Expand Down

0 comments on commit ce23393

Please sign in to comment.