WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

bsm/openmetrics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenMetrics

Go Reference Test License

OpenMetrics is a standalone, dependency-free implementation of OpenMetrics v1.0 specification for Go.

Example

To expose metrics on a HTTP server endpoint and to instrument HTTP servers, please see examples in the omhttp package.

import(
	"bytes"
	"fmt"

	"github.com/bsm/openmetrics"
)

func main() {
	reg := openmetrics.NewConsistentRegistry(mockNow)	// or, openmetrics.DefaultRegistry()
	requestCount := reg.Counter(openmetrics.Desc{
		Name:	"http_request",
		Help:	"A counter example",
		Labels:	[]string{"status"},
	})
	responseTime := reg.Histogram(openmetrics.Desc{
		Name:	"http_request",
		Unit:	"seconds",
		Help:	"A histogram example",
		Labels:	[]string{"status"},
	}, .005, .01, .05, .1, .5, 1, 5, 10)

	requestCount.With("200").Add(1)
	responseTime.With("200").Observe(0.56)

	var buf bytes.Buffer
	if _, err := reg.WriteTo(&buf); err != nil {
		panic(err)
	}
	fmt.Print(buf.String())

}

License

Copyright 2021 Black Square Media Ltd

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,
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.

About

A standalone, dependency-free implementation of OpenMetrics v1.0

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •