本文整理汇总了Golang中github.com/rcrowley/go-metrics.NewRegistry函数的典型用法代码示例。如果您正苦于以下问题:Golang NewRegistry函数的具体用法?Golang NewRegistry怎么用?Golang NewRegistry使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewRegistry函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewGaugeDiff
func NewGaugeDiff(name string, r metrics.Registry) *GaugeDiff {
return &GaugeDiff{
Delta: metrics.NewRegisteredGauge(name, r),
Absolute: metrics.NewRegisteredGauge(name+"-absolute", metrics.NewRegistry()),
Previous: metrics.NewRegisteredGauge(name+"-previous", metrics.NewRegistry()),
}
}
示例2: init
func init() {
Reg1s = IndexRegistry{
Registry: metrics.NewRegistry(),
PrivateCPURegistry: metrics.NewRegistry(),
PrivateInterfaceRegistry: metrics.NewRegistry(),
PrivateDFRegistry: metrics.NewRegistry(),
}
Reg1s.PrivateCPUAll = /* *Reg1s.RegisterCPU */ *system.NewMetricCPU(
/* pcreg := */ metrics.NewRegistry(), "all")
// pcreg.Register("all", Reg1s.PrivateCPUAll)
Reg1s.RAM = system.NewMetricRAM(Reg1s.Registry)
Reg1s.Swap = operating.NewMetricSwap(Reg1s.Registry)
Reg1s.Load = operating.NewMetricLoad(Reg1s.Registry)
}
示例3: newBot
func newBot() (b MMJira) {
b = MMJira{l: zap.NewJSON(zap.DebugLevel), reg: metrics.NewRegistry()}
data, err := ioutil.ReadFile("config.yaml")
if err != nil {
b.l.Panic("not able to read the file", zap.Error(err))
}
var config InstanceConfig
if err = yaml.Unmarshal(data, &config); err != nil {
b.l.Panic("not able to marshal the file", zap.Error(err))
}
b.c = &config
if !b.c.Debug {
b.l.SetLevel(zap.ErrorLevel)
}
mmpost, err := mmcontroller.NewController(b.c.MMicon, b.c.MMuser, b.c.Hooks, b.c.Debug, metrics.NewPrefixedChildRegistry(b.reg, "mmc."))
if err != nil {
panic(err)
}
b.m = mmpost
b.l.Debug("outputting config", zap.Object("config", b.c))
b.r = mux.NewRouter()
b.r.HandleFunc("/", b.homeHandler)
b.r.HandleFunc("/hooks/", b.getHandler).Methods("GET")
b.r.HandleFunc("/hooks/{hookid}", b.postHandler).Methods("POST")
b.r.Handle("/metrics", exp.ExpHandler(b.reg))
b.r.HandleFunc("/config/", b.configGetHandler).Methods("GET")
return b
}
示例4: newGCMetricaDataSource
func newGCMetricaDataSource(pollInterval int) goMetricaDataSource {
r := metrics.NewRegistry()
metrics.RegisterDebugGCStats(r)
go metrics.CaptureDebugGCStats(r, time.Duration(pollInterval)*time.Second)
return goMetricaDataSource{r}
}
示例5: main
func main() {
if len(os.Args) < 2 {
fmt.Println("Please provide one or more IP:Port pairs")
os.Exit(1)
}
h := &httpmetrics.Handler{
Registries: make(map[string]*metrics.Registry),
Socket: "/tmp/tcp-monitor.sock",
}
for _, addr := range os.Args[1:] {
r := metrics.NewRegistry()
a := &Addr{
Address: addr,
Registry: &r,
}
addrs = append(addrs, a)
a.startPing()
h.Registries[addr] = &r
}
if err := h.CreateServer(); err != nil {
panic(err)
}
}
示例6: InitDefaultMetrics
func InitDefaultMetrics() {
Gm = util.NewStreamingMetrics(metrics.NewRegistry())
metricsAddr := "tcp://127.0.0.1:5450"
logPrefix := "Go-stream"
go statsSender(&metricsAddr, &logPrefix)
}
示例7: ExtraNewMetricRAM
func ExtraNewMetricRAM(r metrics.Registry, extra RAMUpdater) *MetricRAM {
return &MetricRAM{
Free: metrics.NewRegisteredGauge("memory.memory-free", r),
Total: metrics.NewRegisteredGauge("memory.memory-total", metrics.NewRegistry()),
Extra: extra,
}
}
示例8: New
// New will mint a new Instrumentation - getting statsd connection details from the config service and then looking out
// for any changes.
func New() *Instrumentation {
ch := config.SubscribeChanges()
addr := loadStatsdAddr()
inst := &Instrumentation{
namespace: "default",
confHash: addr,
statsd: loadStatsd(addr),
registry: metrics.NewRegistry(),
savedTimers: make(map[string]metrics.Timer),
savedCounters: make(map[string]metrics.Counter),
savedGauges: make(map[string]metrics.Gauge),
launched: time.Now(),
instRuntime: false,
}
inst.StartRuntime()
// Launch listener for config changes
go func() {
for _ = range ch {
inst.mtx.Lock()
if addr := loadStatsdAddr(); addr != inst.confHash {
// @todo close old statsd here -- but no way to do this yet
inst.statsd = loadStatsd(addr)
}
inst.mtx.Unlock()
}
}()
return inst
}
示例9: monitorIssueTracker
// monitorIssueTracker reads the counts for all the types of issues in the skia
// issue tracker (code.google.com/p/skia) and stuffs the counts into Graphite.
func monitorIssueTracker() {
c := &http.Client{
Transport: &http.Transport{
Dial: dialTimeout,
},
}
if *useMetadata {
*apikey = metadata.Must(metadata.ProjectGet(metadata.APIKEY))
}
// Create a new metrics registry for the issue tracker metrics.
addr, err := net.ResolveTCPAddr("tcp", *graphiteServer)
if err != nil {
glog.Fatalln("Failed to resolve the Graphite server: ", err)
}
issueRegistry := metrics.NewRegistry()
go graphite.Graphite(issueRegistry, common.SAMPLE_PERIOD, "issues", addr)
// IssueStatus has all the info we need to capture and record a single issue status. I.e. capture
// the count of all issues with a status of "New".
type IssueStatus struct {
Name string
Metric metrics.Gauge
URL string
}
allIssueStatusLabels := []string{
"New", "Accepted", "Unconfirmed", "Started", "Fixed", "Verified", "Invalid", "WontFix", "Done", "Available", "Assigned",
}
issueStatus := []*IssueStatus{}
for _, issueName := range allIssueStatusLabels {
issueStatus = append(issueStatus, &IssueStatus{
Name: issueName,
Metric: metrics.NewRegisteredGauge(strings.ToLower(issueName), issueRegistry),
URL: "https://www.googleapis.com/projecthosting/v2/projects/skia/issues?fields=totalResults&key=" + *apikey + "&status=" + issueName,
})
}
liveness := imetrics.NewLiveness("issue-tracker")
for _ = range time.Tick(ISSUE_TRACKER_PERIOD) {
for _, issue := range issueStatus {
resp, err := c.Get(issue.URL)
jsonResp := map[string]int64{}
dec := json.NewDecoder(resp.Body)
if err := dec.Decode(&jsonResp); err != nil {
glog.Warningf("Failed to decode JSON response: %s", err)
util.Close(resp.Body)
continue
}
issue.Metric.Update(jsonResp["totalResults"])
glog.Infof("Num Issues: %s - %d", issue.Name, jsonResp["totalResults"])
if err == nil && resp.Body != nil {
util.Close(resp.Body)
}
}
liveness.Update()
}
}
示例10: NewConfigLocal
// NewConfigLocal constructs a new ConfigLocal with default components.
func NewConfigLocal() *ConfigLocal {
config := &ConfigLocal{}
config.SetClock(wallClock{})
config.SetReporter(NewReporterSimple(config.Clock(), 10))
config.SetConflictRenamer(TimeAndWriterConflictRenamer{config})
config.SetMDCache(NewMDCacheStandard(5000))
config.SetKeyCache(NewKeyCacheStandard(5000))
// Limit the block cache to 10K entries or 512 MB of bytes
config.SetBlockCache(NewBlockCacheStandard(config, 10000, 512*1024*1024))
config.SetCodec(NewCodecMsgpack())
config.SetMDOps(&MDOpsStandard{config})
config.SetBlockOps(&BlockOpsStandard{config})
config.SetKeyOps(&KeyOpsStandard{config})
config.SetRekeyQueue(NewRekeyQueueStandard(config))
config.maxFileBytes = maxFileBytesDefault
config.maxNameBytes = maxNameBytesDefault
config.maxDirBytes = maxDirBytesDefault
// Don't bother creating the registry if UseNilMetrics is set.
if !metrics.UseNilMetrics {
registry := metrics.NewRegistry()
config.SetMetricsRegistry(registry)
}
return config
}
示例11: GetOrRegisterPrivateDF
func (ir *IndexRegistry) GetOrRegisterPrivateDF(fs sigar.FileSystem) operating.MetricDF {
ir.PrivateMutex.Lock()
defer ir.PrivateMutex.Unlock()
if fs.DirName == "/" {
fs.DevName = "root"
} else {
fs.DevName = strings.Replace(strings.TrimPrefix(fs.DevName, "/dev/"), "/", "-", -1)
}
if metric := ir.PrivateDFRegistry.Get(fs.DevName); metric != nil {
return metric.(operating.MetricDF)
}
label := func(tail string) string {
return fmt.Sprintf("df-%s.df_complex-%s", fs.DevName, tail)
}
r, unusedr := ir.Registry, metrics.NewRegistry()
i := operating.MetricDF{
DF: &operating.DF{
DevName: &operating.StandardMetricString{}, // unregistered
DirName: &operating.StandardMetricString{}, // unregistered
Free: metrics.NewRegisteredGaugeFloat64(label("free"), r),
Reserved: metrics.NewRegisteredGaugeFloat64(label("reserved"), r),
Total: metrics.NewRegisteredGauge(label("total"), unusedr),
Used: metrics.NewRegisteredGaugeFloat64(label("used"), r),
Avail: metrics.NewRegisteredGauge(label("avail"), unusedr),
UsePercent: metrics.NewRegisteredGaugeFloat64(label("usepercent"), unusedr),
Inodes: metrics.NewRegisteredGauge(label("inodes"), unusedr),
Iused: metrics.NewRegisteredGauge(label("iused"), unusedr),
Ifree: metrics.NewRegisteredGauge(label("ifree"), unusedr),
IusePercent: metrics.NewRegisteredGaugeFloat64(label("iusepercent"), unusedr),
},
}
ir.PrivateDFRegistry.Register(fs.DevName, i) // error is ignored
// errs when the type is not derived from (go-)metrics types
return i
}
示例12: newMemoryMetricaDataSource
func newMemoryMetricaDataSource(pollInterval int) goMetricaDataSource {
r := metrics.NewRegistry()
metrics.RegisterRuntimeMemStats(r)
metrics.CaptureRuntimeMemStatsOnce(r)
go metrics.CaptureRuntimeMemStats(r, time.Duration(pollInterval)*time.Second)
return goMetricaDataSource{r}
}
示例13: newStats
func newStats() *stats {
return &stats{
registry: metrics.NewRegistry(),
startTime: time.Now(),
timers: make(map[Endpoint]endpointTimers),
recordChan: make(chan *endpointResult, 100),
terminate: make(chan chan bool),
}
}
示例14: monitorIssueTracker
// monitorIssueTracker reads the counts for all the types of issues in the Skia
// issue tracker (bugs.chromium.org/p/skia) and stuffs the counts into Graphite.
func monitorIssueTracker(c *http.Client) {
// Create a new metrics registry for the issue tracker metrics.
addr, err := net.ResolveTCPAddr("tcp", *graphiteServer)
if err != nil {
glog.Fatalln("Failed to resolve the Graphite server: ", err)
}
issueRegistry := metrics.NewRegistry()
go graphite.Graphite(issueRegistry, common.SAMPLE_PERIOD, "issues", addr)
// IssueStatus has all the info we need to capture and record a single issue status. I.e. capture
// the count of all issues with a status of "New".
type IssueStatus struct {
Name string
Metric metrics.Gauge
URL string
}
allIssueStatusLabels := []string{
"New", "Accepted", "Unconfirmed", "Started", "Fixed", "Verified", "Invalid", "WontFix", "Done", "Available", "Assigned",
}
issueStatus := []*IssueStatus{}
for _, issueName := range allIssueStatusLabels {
q := url.Values{}
q.Set("fields", "totalResults")
q.Set("status", issueName)
issueStatus = append(issueStatus, &IssueStatus{
Name: issueName,
Metric: metrics.NewRegisteredGauge(strings.ToLower(issueName), issueRegistry),
URL: issues.MONORAIL_BASE_URL + "?" + q.Encode(),
})
}
liveness := imetrics.NewLiveness("issue-tracker")
for _ = range time.Tick(ISSUE_TRACKER_PERIOD) {
for _, issue := range issueStatus {
resp, err := c.Get(issue.URL)
if err != nil {
glog.Errorf("Failed to retrieve response from %s: %s", issue.URL, err)
continue
}
jsonResp := map[string]int64{}
dec := json.NewDecoder(resp.Body)
if err := dec.Decode(&jsonResp); err != nil {
glog.Warningf("Failed to decode JSON response: %s", err)
util.Close(resp.Body)
continue
}
issue.Metric.Update(jsonResp["totalResults"])
glog.Infof("Num Issues: %s - %d", issue.Name, jsonResp["totalResults"])
if err == nil && resp.Body != nil {
util.Close(resp.Body)
}
}
liveness.Update()
}
}
示例15: newStandardBucket
func newStandardBucket(name string) standardBucket {
registry := gometrics.NewRegistry()
gometrics.RegisterRuntimeMemStats(registry)
go gometrics.CaptureRuntimeMemStats(registry, RuntimeMemStatsSampleInterval)
return standardBucket{
name: name,
registry: registry,
timers: make(map[string]Timer),
gauges: make(map[string]Gauge),
}
}