acelyc111 commented on code in PR #1466: URL: https://github.com/apache/incubator-pegasus/pull/1466#discussion_r1185896498
########## collector/metrics/metric_collector.go: ########## @@ -0,0 +1,354 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package metrics + +import ( + "errors" + "time" + "fmt" + "io/ioutil" + "net/http" + + log "github.com/sirupsen/logrus" + "github.com/spf13/viper" + "gopkg.in/tomb.v2" + "github.com/tidwall/gjson" + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promauto" +) + +const ( + META_SERVER int = 0 + REPLICA_SERVER int = 1 +) + +type Metric struct { + name string + value int64 + mtype string + desc string + unit string +} + +type Metrics []Metric + +type Attribute struct { + name string + value string +} + +type Entity struct { + etype string + eid string + attributes string + metrics []Metric +} + +var gaugeMetricsMap_ map[string]prometheus.GaugeVec +var counterMetricsMap_ map[string]prometheus.CounterVec +var histogramMetricsMap_ map[string]prometheus.Histogram +var summaryMetricsMap_ map[string]prometheus.Summary + +var dataSource_ int + +type MetricCollector interface { + Start(tom *tomb.Tomb) error +} + +func NewMetricCollector(dataSource int) MetricCollector { + dataSource_ = dataSource + gaugeMetricsMap_ = make(map[string]prometheus.GaugeVec, 128) + counterMetricsMap_ = make(map[string]prometheus.CounterVec, 128) + histogramMetricsMap_ = make(map[string]prometheus.Histogram, 128) + summaryMetricsMap_ = make(map[string]prometheus.Summary, 128) + initMetrics() + return &Collector{detectInterval: 10, detectTimeout: 10} +} + +type Collector struct { + detectInterval time.Duration + detectTimeout time.Duration +} + +func (collector *Collector) Start(tom *tomb.Tomb) error { + ticker := time.NewTicker(collector.detectInterval) + for { + select { + case <-tom.Dying(): + return nil + case <-ticker.C: + processAllMetaServerMetrics() + break + default: + } + } +} + +func initMetrics() { + var addrs []string + if dataSource_ == META_SERVER { + addrs = viper.GetStringSlice("meta_servers") + } else { + addrs = viper.GetStringSlice("replica_servers") Review Comment: Generally, the replica servers list is not exposed like meta servers list, we can fetch replica servers list via meta servers instead, by HTTP `curl localhost:34601/meta/nodes` Further more, we have to update server list periodically to tolerate the case of scale in and scale out. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
