Skip to content

Commit 66058aa

Browse files
authored
Merge pull request #214 from prometheus/beorn7/registry
Create a public registry interface and separate out HTTP exposition
2 parents 52437c8 + a6321dd commit 66058aa

29 files changed

+1940
-1103
lines changed

NOTICE

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@ SoundCloud Ltd. (http://soundcloud.com/).
77

88
The following components are included in this product:
99

10-
goautoneg
11-
http://bitbucket.org/ww/goautoneg
12-
Copyright 2011, Open Knowledge Foundation Ltd.
13-
See README.txt for license details.
14-
1510
perks - a fork of https://github.com/bmizerany/perks
1611
https://github.com/beorn7/perks
1712
Copyright 2013-2015 Blake Mizerany, Björn Rabenstein

prometheus/README.md

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1 @@
1-
# Overview
2-
This is the [Prometheus](http://www.prometheus.io) telemetric
3-
instrumentation client [Go](http://golang.org) client library. It
4-
enable authors to define process-space metrics for their servers and
5-
expose them through a web service interface for extraction,
6-
aggregation, and a whole slew of other post processing techniques.
7-
8-
# Installing
9-
$ go get github.com/prometheus/client_golang/prometheus
10-
11-
# Example
12-
```go
13-
package main
14-
15-
import (
16-
"net/http"
17-
18-
"github.com/prometheus/client_golang/prometheus"
19-
)
20-
21-
var (
22-
indexed = prometheus.NewCounter(prometheus.CounterOpts{
23-
Namespace: "my_company",
24-
Subsystem: "indexer",
25-
Name: "documents_indexed",
26-
Help: "The number of documents indexed.",
27-
})
28-
size = prometheus.NewGauge(prometheus.GaugeOpts{
29-
Namespace: "my_company",
30-
Subsystem: "storage",
31-
Name: "documents_total_size_bytes",
32-
Help: "The total size of all documents in the storage.",
33-
})
34-
)
35-
36-
func main() {
37-
http.Handle("/metrics", prometheus.Handler())
38-
39-
indexed.Inc()
40-
size.Set(5)
41-
42-
http.ListenAndServe(":8080", nil)
43-
}
44-
45-
func init() {
46-
prometheus.MustRegister(indexed)
47-
prometheus.MustRegister(size)
48-
}
49-
```
50-
51-
# Documentation
52-
53-
[![GoDoc](https://godoc.org/github.com/prometheus/client_golang?status.png)](https://godoc.org/github.com/prometheus/client_golang)
1+
See [![go-doc](https://godoc.org/github.com/prometheus/client_golang/prometheus?status.svg)](https://godoc.org/github.com/prometheus/client_golang/prometheus).

prometheus/collector.go

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ package prometheus
1515

1616
// Collector is the interface implemented by anything that can be used by
1717
// Prometheus to collect metrics. A Collector has to be registered for
18-
// collection. See Register, MustRegister, RegisterOrGet, and MustRegisterOrGet.
18+
// collection. See Registerer.Register.
1919
//
20-
// The stock metrics provided by this package (like Gauge, Counter, Summary) are
21-
// also Collectors (which only ever collect one metric, namely itself). An
22-
// implementer of Collector may, however, collect multiple metrics in a
23-
// coordinated fashion and/or create metrics on the fly. Examples for collectors
24-
// already implemented in this library are the metric vectors (i.e. collection
25-
// of multiple instances of the same Metric but with different label values)
26-
// like GaugeVec or SummaryVec, and the ExpvarCollector.
20+
// The stock metrics provided by this package (Gauge, Counter, Summary,
21+
// Histogram, Untyped) are also Collectors (which only ever collect one metric,
22+
// namely itself). An implementer of Collector may, however, collect multiple
23+
// metrics in a coordinated fashion and/or create metrics on the fly. Examples
24+
// for collectors already implemented in this library are the metric vectors
25+
// (i.e. collection of multiple instances of the same Metric but with different
26+
// label values) like GaugeVec or SummaryVec, and the ExpvarCollector.
2727
type Collector interface {
2828
// Describe sends the super-set of all possible descriptors of metrics
2929
// collected by this Collector to the provided channel and returns once
@@ -37,39 +37,39 @@ type Collector interface {
3737
// executing this method, it must send an invalid descriptor (created
3838
// with NewInvalidDesc) to signal the error to the registry.
3939
Describe(chan<- *Desc)
40-
// Collect is called by Prometheus when collecting metrics. The
41-
// implementation sends each collected metric via the provided channel
42-
// and returns once the last metric has been sent. The descriptor of
43-
// each sent metric is one of those returned by Describe. Returned
44-
// metrics that share the same descriptor must differ in their variable
45-
// label values. This method may be called concurrently and must
46-
// therefore be implemented in a concurrency safe way. Blocking occurs
47-
// at the expense of total performance of rendering all registered
48-
// metrics. Ideally, Collector implementations support concurrent
49-
// readers.
40+
// Collect is called by the Prometheus registry when collecting
41+
// metrics. The implementation sends each collected metric via the
42+
// provided channel and returns once the last metric has been sent. The
43+
// descriptor of each sent metric is one of those returned by
44+
// Describe. Returned metrics that share the same descriptor must differ
45+
// in their variable label values. This method may be called
46+
// concurrently and must therefore be implemented in a concurrency safe
47+
// way. Blocking occurs at the expense of total performance of rendering
48+
// all registered metrics. Ideally, Collector implementations support
49+
// concurrent readers.
5050
Collect(chan<- Metric)
5151
}
5252

53-
// SelfCollector implements Collector for a single Metric so that that the
54-
// Metric collects itself. Add it as an anonymous field to a struct that
55-
// implements Metric, and call Init with the Metric itself as an argument.
56-
type SelfCollector struct {
53+
// selfCollector implements Collector for a single Metric so that the Metric
54+
// collects itself. Add it as an anonymous field to a struct that implements
55+
// Metric, and call init with the Metric itself as an argument.
56+
type selfCollector struct {
5757
self Metric
5858
}
5959

60-
// Init provides the SelfCollector with a reference to the metric it is supposed
60+
// init provides the selfCollector with a reference to the metric it is supposed
6161
// to collect. It is usually called within the factory function to create a
6262
// metric. See example.
63-
func (c *SelfCollector) Init(self Metric) {
63+
func (c *selfCollector) init(self Metric) {
6464
c.self = self
6565
}
6666

6767
// Describe implements Collector.
68-
func (c *SelfCollector) Describe(ch chan<- *Desc) {
68+
func (c *selfCollector) Describe(ch chan<- *Desc) {
6969
ch <- c.self.Desc()
7070
}
7171

7272
// Collect implements Collector.
73-
func (c *SelfCollector) Collect(ch chan<- Metric) {
73+
func (c *selfCollector) Collect(ch chan<- Metric) {
7474
ch <- c.self
7575
}

prometheus/counter.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ type Counter interface {
3535
// Prometheus metric. Do not use it for regular handling of a
3636
// Prometheus counter (as it can be used to break the contract of
3737
// monotonically increasing values).
38+
//
39+
// Deprecated: Use NewConstMetric to create a counter for an external
40+
// value. A Counter should never be set.
3841
Set(float64)
3942
// Inc increments the counter by 1.
4043
Inc()
@@ -55,7 +58,7 @@ func NewCounter(opts CounterOpts) Counter {
5558
opts.ConstLabels,
5659
)
5760
result := &counter{value: value{desc: desc, valType: CounterValue, labelPairs: desc.constLabelPairs}}
58-
result.Init(result) // Init self-collection.
61+
result.init(result) // Init self-collection.
5962
return result
6063
}
6164

@@ -102,7 +105,7 @@ func NewCounterVec(opts CounterOpts, labelNames []string) *CounterVec {
102105
valType: CounterValue,
103106
labelPairs: makeLabelPairs(desc, lvs),
104107
}}
105-
result.Init(result) // Init self-collection.
108+
result.init(result) // Init self-collection.
106109
return result
107110
},
108111
},

prometheus/desc.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
// Copyright 2016 The Prometheus Authors
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
114
package prometheus
215

316
import (

0 commit comments

Comments
 (0)