https://github.com/bsm/openmetrics
A standalone, dependency-free implementation of OpenMetrics v1.0
https://github.com/bsm/openmetrics
Last synced: 10 months ago
JSON representation
A standalone, dependency-free implementation of OpenMetrics v1.0
- Host: GitHub
- URL: https://github.com/bsm/openmetrics
- Owner: bsm
- License: apache-2.0
- Created: 2021-05-05T13:47:30.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2023-03-21T10:44:23.000Z (about 3 years ago)
- Last Synced: 2025-07-19T05:14:13.105Z (11 months ago)
- Language: Go
- Size: 91.8 KB
- Stars: 9
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# OpenMetrics
[](https://pkg.go.dev/github.com/bsm/openmetrics)
[](https://github.com/bsm/openmetrics/actions/workflows/test.yml)
[](https://opensource.org/licenses/Apache-2.0)
OpenMetrics is a standalone, dependency-free implementation of [OpenMetrics v1.0](https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md) specification for [Go](https://golang.org/).
## Example
To expose metrics on a HTTP server endpoint and to instrument HTTP servers, please see examples in the [omhttp](./omhttp/) package.
```go
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
```text
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.
```