-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
134 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# NG Monitoring Server Configuration. | ||
|
||
# Server address. | ||
addr = "0.0.0.0:{{.Port}}" | ||
|
||
[log] | ||
# Log path | ||
path = "{{.LogDir}}" | ||
|
||
# Log level: INFO, WARN, ERROR | ||
level = "INFO" | ||
|
||
[pd] | ||
# Addresses of PD instances within the TiDB cluster. Multiple addresses are separated by commas, e.g. "10.0.0.1:2379","10.0.0.2:2379" | ||
endpoints = [{{.PDAddrs}}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// Copyright 2020 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package config | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"os" | ||
"path" | ||
"text/template" | ||
|
||
"github.com/pingcap/tiup/embed" | ||
) | ||
|
||
// NgMonitoringConfig represent the data to generate NgMonitoring config | ||
type NgMonitoringConfig struct { | ||
ClusterName string | ||
TLSEnabled bool | ||
Port int | ||
PDAddrs string | ||
LogDir string | ||
} | ||
|
||
// NewNgMonitoringConfig returns a PrometheusConfig | ||
func NewNgMonitoringConfig(clusterName, clusterVersion string, enableTLS bool) *NgMonitoringConfig { | ||
cfg := &NgMonitoringConfig{ | ||
ClusterName: clusterName, | ||
TLSEnabled: enableTLS, | ||
} | ||
return cfg | ||
} | ||
|
||
// AddPD add a PD address | ||
func (c *NgMonitoringConfig) AddPD(ip string, port uint64) *NgMonitoringConfig { | ||
if c.PDAddrs == "" { | ||
c.PDAddrs = fmt.Sprintf("\"%s:%d\"", ip, port) | ||
} else { | ||
c.PDAddrs += fmt.Sprintf(",\"%s:%d\"", ip, port) | ||
} | ||
return c | ||
} | ||
|
||
// AddLog add logdir to ng-monitoring conf | ||
func (c *NgMonitoringConfig) AddLog(logdir string) *NgMonitoringConfig { | ||
c.LogDir = logdir | ||
return c | ||
} | ||
|
||
// AddPort add port to ng-monitoring conf | ||
func (c *NgMonitoringConfig) AddPort(port int) *NgMonitoringConfig { | ||
c.Port = port | ||
return c | ||
} | ||
|
||
// ConfigWithTemplate generate the Prometheus config content by tpl | ||
func (c *NgMonitoringConfig) ConfigWithTemplate(tpl string) ([]byte, error) { | ||
tmpl, err := template.New("NgMonitoring").Parse(tpl) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
content := bytes.NewBufferString("") | ||
if err := tmpl.Execute(content, c); err != nil { | ||
return nil, err | ||
} | ||
|
||
return content.Bytes(), nil | ||
} | ||
|
||
// Config generate the config file data. | ||
func (c *NgMonitoringConfig) Config() ([]byte, error) { | ||
fp := path.Join("templates", "config", "ngmonitoring.yml.tpl") | ||
tpl, err := embed.ReadTemplate(fp) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return c.ConfigWithTemplate(string(tpl)) | ||
} | ||
|
||
// ConfigToFile write config content to specific path | ||
func (c *NgMonitoringConfig) ConfigToFile(file string) error { | ||
config, err := c.Config() | ||
if err != nil { | ||
return err | ||
} | ||
return os.WriteFile(file, config, 0755) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters