Skip to content

Commit

Permalink
introduce elasticsearch index name
Browse files Browse the repository at this point in the history
Signed-off-by: ZhangJian He <shoothzj@gmail.com>
  • Loading branch information
shoothzj committed Feb 23, 2023
1 parent 71dc523 commit 2c74293
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 2 additions & 0 deletions docs/design/usage-based-scheduling.md
Expand Up @@ -60,6 +60,8 @@ metrics: # metrics server related configuration
type: prometheus # Optional, The metrics source type, prometheus by default, support prometheus and elasticsearch
address: http://192.168.0.10:9090 # mandatory, The metrics source address
interval: 30s # Optional, The scheduler pull metrics from Prometheus with this interval, 5s by default
elasticsearch: # Optional, The elasticsearch configuration
index: "custom-index-name" # Optional, The elasticsearch index name, "metricbeat-*" by default
```

### How to predicate node
Expand Down
2 changes: 1 addition & 1 deletion pkg/scheduler/metrics/source/metrics_client.go
Expand Up @@ -37,7 +37,7 @@ func NewMetricsClient(metricsConf map[string]string) (MetricsClient, error) {
}
metricsType := metricsConf["type"]
if metricsType == "elasticsearch" {
return NewElasticsearchMetricsClient(address)
return NewElasticsearchMetricsClient(address, metricsConf)
}
return &PrometheusMetricsClient{address: address}, nil
}
13 changes: 10 additions & 3 deletions pkg/scheduler/metrics/source/metrics_client_elasticsearch.go
Expand Up @@ -33,12 +33,19 @@ const (
)

type ElasticsearchMetricsClient struct {
address string
es *elasticsearch.Client
address string
indexName string
es *elasticsearch.Client
}

func NewElasticsearchMetricsClient(address string) (*ElasticsearchMetricsClient, error) {
func NewElasticsearchMetricsClient(address string, conf map[string]string) (*ElasticsearchMetricsClient, error) {
e := &ElasticsearchMetricsClient{address: address}
indexConf := conf["elasticsearch.index"]
if len(indexConf) == 0 {
e.indexName = "metricbeat-*"
} else {
e.indexName = indexConf
}
var err error
e.es, err = elasticsearch.NewDefaultClient()
if err != nil {
Expand Down

0 comments on commit 2c74293

Please sign in to comment.