-
Notifications
You must be signed in to change notification settings - Fork 312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: A new port is added for prometheus collection, and the indicator init… #1826
Changes from 5 commits
78c35f2
be84904
1cdec2b
be1127d
a4bcb86
44936f7
5518743
8580b73
5e2cee8
a9d864a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't add binaries to the codebase. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,9 +26,12 @@ import ( | |
"strings" | ||
"syscall" | ||
|
||
"github.com/pegasus-kv/collector/avail" | ||
"github.com/pegasus-kv/collector/metrics" | ||
"github.com/pegasus-kv/collector/webui" | ||
// "github.com/pegasus-kv/collector/avail" | ||
// "github.com/pegasus-kv/collector/metrics" | ||
// "github.com/pegasus-kv/collector/webui" | ||
"github.com/limowang/incubator-pegasus/collector/avail" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the comments and use the apache repository. |
||
"github.com/limowang/incubator-pegasus/collector/metrics" | ||
"github.com/limowang/incubator-pegasus/collector/webui" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/viper" | ||
"gopkg.in/natefinch/lumberjack.v2" | ||
|
@@ -81,7 +84,8 @@ func main() { | |
return | ||
} | ||
|
||
webui.StartWebServer() | ||
metrics.InitMetrics() | ||
//webui.StartWebServer() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just remove it if it's not needed. |
||
|
||
tom := &tomb.Tomb{} | ||
setupSignalHandler(func() { | ||
|
@@ -97,5 +101,7 @@ func main() { | |
tom.Go(func() error { | ||
return metrics.NewReplicaServerMetricCollector().Start(tom) | ||
}) | ||
|
||
webui.StartWebServer() | ||
<-tom.Dead() // gracefully wait until all goroutines dead | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,22 +67,13 @@ func NewMetricCollector( | |
dataSource int, | ||
detectInterval time.Duration, | ||
detectTimeout time.Duration) MetricCollector { | ||
DataSource = dataSource | ||
GaugeMetricsMap = make(map[string]prometheus.GaugeVec, 128) | ||
CounterMetricsMap = make(map[string]prometheus.CounterVec, 128) | ||
SummaryMetricsMap = make(map[string]prometheus.Summary, 128) | ||
RoleByDataSource = make(map[int]string, 128) | ||
TableNameByID = make(map[string]string, 128) | ||
RoleByDataSource[0] = "meta_server" | ||
RoleByDataSource[1] = "replica_server" | ||
initMetrics() | ||
|
||
return &Collector{detectInterval: detectInterval, detectTimeout: detectTimeout} | ||
return &Collector{detectInterval: detectInterval, detectTimeout: detectTimeout, dataSource: dataSource} | ||
} | ||
|
||
type Collector struct { | ||
detectInterval time.Duration | ||
detectTimeout time.Duration | ||
dataSource int | ||
} | ||
|
||
func (collector *Collector) Start(tom *tomb.Tomb) error { | ||
|
@@ -123,19 +114,10 @@ func getReplicaAddrs() ([]string, error) { | |
return rserverAddrs, nil | ||
} | ||
|
||
// Register all metrics. | ||
func initMetrics() { | ||
var addrs []string | ||
var err error | ||
if DataSource == MetaServer { | ||
addrs = viper.GetStringSlice("meta_servers") | ||
} else { | ||
addrs, err = getReplicaAddrs() | ||
if err != nil { | ||
log.Errorf("Get replica server address failed, err: %s", err) | ||
return | ||
} | ||
} | ||
//Get metrics with new labels | ||
|
||
// Get all metrics of meta-server and replica-server by their addrs | ||
func getAllMetricsByAddrs(addrs []string) { | ||
for _, addr := range addrs { | ||
data, err := getOneServerMetrics(addr) | ||
if err != nil { | ||
|
@@ -167,17 +149,15 @@ func initMetrics() { | |
Help: desc, | ||
}, []string{"endpoint", "role", "level", "title"}) | ||
GaugeMetricsMap[name] = *gaugeMetric | ||
case "Percentile": | ||
if _, ok := SummaryMetricsMap[name]; ok { | ||
case "Percentile": //这个需要改动不能用这个表示,用gauge来表示分位数 --level(p50,p99),title(task_name)来替代区分 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use English because this is a globally open-source project. |
||
if _, ok := GaugeMetricsMap[name]; ok { | ||
continue | ||
} | ||
summaryMetric := promauto.NewSummary(prometheus.SummaryOpts{ | ||
gaugeMetric := promauto.NewGaugeVec(prometheus.GaugeOpts{ | ||
Name: name, | ||
Help: desc, | ||
Objectives: map[float64]float64{ | ||
0.5: 0.05, 0.9: 0.01, 0.95: 0.005, 0.99: 0.001, 0.999: 0.0001}, | ||
}) | ||
SummaryMetricsMap[name] = summaryMetric | ||
}, []string{"endpoint", "role", "level", "title"}) | ||
GaugeMetricsMap[name] = *gaugeMetric | ||
case "Histogram": | ||
default: | ||
log.Errorf("Unsupport metric type %s", mtype) | ||
|
@@ -187,6 +167,27 @@ func initMetrics() { | |
} | ||
} | ||
|
||
// Register all metrics. | ||
func InitMetrics() { | ||
GaugeMetricsMap = make(map[string]prometheus.GaugeVec, 256) | ||
CounterMetricsMap = make(map[string]prometheus.CounterVec, 256) | ||
SummaryMetricsMap = make(map[string]prometheus.Summary, 256) | ||
RoleByDataSource = make(map[int]string, 128) | ||
TableNameByID = make(map[string]string, 256) | ||
RoleByDataSource[0] = "meta_server" | ||
RoleByDataSource[1] = "replica_server" | ||
|
||
var addrs []string | ||
addrs = viper.GetStringSlice("meta_servers") | ||
replicAddrs, err := getReplicaAddrs() | ||
if err != nil { | ||
log.Errorf("Get raw metrics from %s failed, err: %s", replicAddrs, err) | ||
return | ||
} | ||
addrs = append(addrs, replicAddrs...) | ||
getAllMetricsByAddrs(addrs) | ||
} | ||
|
||
// Parse metric data and update metrics. | ||
func processAllServerMetrics() { | ||
var addrs []string | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -19,9 +19,12 @@ package webui | |||||
|
||||||
import ( | ||||||
"context" | ||||||
"net/http" | ||||||
"time" | ||||||
|
||||||
"github.com/kataras/iris/v12" | ||||||
"github.com/limowang/incubator-pegasus/collector/metrics" | ||||||
"github.com/prometheus/client_golang/prometheus" | ||||||
"github.com/prometheus/client_golang/prometheus/promhttp" | ||||||
) | ||||||
|
||||||
|
@@ -53,9 +56,22 @@ func StartWebServer() { | |||||
app.RegisterView(tmpl) | ||||||
|
||||||
go func() { | ||||||
err := app.Listen(":8080") | ||||||
err := app.Listen(":8081") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be better to read from config file or command line rather than hard code. The port should be user-defined to avoid port conflicts in user environments. |
||||||
if err != nil { | ||||||
return | ||||||
} | ||||||
}() | ||||||
|
||||||
//Provide metrics for prometheus | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
registry := prometheus.NewRegistry() | ||||||
for _, cV := range metrics.CounterMetricsMap { | ||||||
registry.MustRegister(cV) | ||||||
} | ||||||
for _, gV := range metrics.GaugeMetricsMap { | ||||||
registry.MustRegister(gV) | ||||||
} | ||||||
|
||||||
http.Handle("/metrics", promhttp.Handler()) | ||||||
|
||||||
_ = http.ListenAndServe(":8080", nil) | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.