Commit Graph

613 Commits

Author SHA1 Message Date
hazey.dazey f36d4a3e73 Add new default metric go_info 2017-07-23 23:36:09 +02:00
beorn7 ed379b7d99 Remove remaining references to MetricVec from doc comments
MetricVec is un-experted by now. godoc handles that correctly by
showing the methods of the embedded un-exported metricVec with the
exported type (CounterVec, SummaryVec, ...) that embeds metricVec.
2017-07-12 15:13:09 +02:00
Maxime Song 90494ea7b1 fix typo in comments
Signed-off-by: Maxime Song <me@cppdo.com>
2017-07-07 23:28:24 +08:00
Björn Rabenstein 310ce84375 Merge pull request #319 from prometheus/beorn7/vec
Unexport MetricVec
2017-06-30 16:48:34 +02:00
beorn7 e04de4bfe3 Document the use of Go1.9+ for monotonic time where applicable 2017-06-29 16:07:12 +02:00
beorn7 f66cdf0736 Un-export MetricVec
This is in preparation for "curried" metric vecs, as discussed.

And it's a good thing anyway. The exported MetricVec was from a time
when I thought people would define own Metric types and then create
Vecs of it. That has never happened.
2017-06-28 17:55:59 +02:00
beorn7 721f93fda8 Deprecate UntypedVec 2017-06-28 17:00:33 +02:00
Alexey Palazhchenko f0c4c478a2 Minor documentation fix 2017-06-28 15:40:03 +03:00
beorn7 14730c70c0 promhttp: Bite the bullet and implement all 32 possible interface combos
As it turned out, it's not that esay to guess "common" combination of
interface upgrades. So I decided to just implement all 32 possible
combination of interface upgrades. (Only 16 with Go 1.7 and earlier.)

Clearly, this calls for code generation. But right now, we still need
to find out what's the best form of the code. For later additions,
implementing code generation might be useful.

Note that newDelegator is called for each HTTP request. Thus, this
commit aims to make the upgrade selection quick. (After the type
checks, it's just directly accessing an element in a slice.)
2017-06-02 19:03:08 +02:00
Norbert Tretkowski e7e903064f Import "log", it is required for log.Fatal(... (#305)
Import "log" in the example doc comment

Package log is required for log.Fatal.
2017-05-31 15:00:54 +02:00
stuart nelson 2b3ab50dcd Add time to write header handler middleware (#304) 2017-05-29 11:42:43 +02:00
beorn7 023c31fd59 Fix handling of ConstLabels in checkLabels 2017-05-10 20:39:36 +02:00
beorn7 753a259e20 Improve promhttp tests
- Use local registry to avoid conflicts between tests.
- Expose https://github.com/prometheus/client_golang/issues/299 by
  using ConstLabels in a test.
- Improve example: Buckets and help string must be consistent, even
  if the former is not enforced as of now, but see
  https://github.com/prometheus/client_golang/issues/222
2017-05-10 19:49:36 +02:00
beorn7 4ea620c5bf Point to promhttp in deprecation notices 2017-05-09 18:54:33 +02:00
stuart nelson d300d5cf21 Instrument RoundTripper via middleware (#295)
Instrument RoundTripper via middleware
2017-05-09 18:46:09 +02:00
stuart nelson d01fd62222 new handler instrumentation (#285)
Add new HTTP handler instrumentation
2017-04-24 15:13:19 -04:00
Björn Rabenstein 08fd2e1237 Merge pull request #281 from adjust/add_gc_cpu_fraction
Adding GCCPUFraction metric to goCollector
2017-04-01 12:34:46 +02:00
Tong 6d619ff5a8 Fix typo 2017-03-22 21:29:18 +08:00
Ivan Borshukov bea9149ebb Fix typo 2017-03-07 16:11:13 +02:00
Tobias Schmidt ae77d82d88 Fix invalid Timer (gauge) example
The example method is assumed to be used as main() function. As a main()
function doesn't have any return values, the example doesn't compile and
is invalid.
2017-02-28 11:13:17 -04:00
Julius Volz 69bb387064 Fix typo 2017-02-23 10:28:41 +01:00
Francis Stephens 56cf0be13f Adding GCCPUFraction metric to goCollector 2017-02-22 17:26:08 +01:00
Tobias Schmidt 70693bc297 Document graphite bridge 2017-02-15 12:19:46 -04:00
Peng Gao efb2f142f3 goCollector: change goroutines and treads type
Change gorountines and threads created Gauge to NewConstMetric.

Signed-off-by: Peng Gao <peng.gao.dut@gmail.com>
2017-02-15 13:06:22 +08:00
Peng Gao fa1cd67d1e goCollector: add thread count gauge in goCollector
Signed-off-by: Peng Gao <peng.gao.dut@gmail.com>
2017-02-13 19:39:00 +08:00
beorn7 9fdd167dba InstrumentHandler: Document issues with HTTP/2 2017-01-25 12:49:31 +01:00
beorn7 60e61927fc graphite: Adjust ExtractSamples call to new interface 2017-01-08 20:55:34 +01:00
Björn Rabenstein 575f371f78 Merge pull request #262 from prometheus/beorn7/summary
Allow Summaries with empty objectives and deprecate DefObjectives
2016-11-24 16:57:32 +01:00
Björn Rabenstein e83345f73f Merge pull request #250 from prometheus/timer-helper
Add timer helper function
2016-11-23 18:45:33 +01:00
beorn7 9c4b7780d7 Allow Summaries with empty objectives and deprecate DefObjectives
This also updates all tests and examples to use explicitly set
objectives.

In v0.10, DefObjectives will be completely removed, and the default
Summary will have no objectives then.

Fixes #118
2016-11-23 18:35:02 +01:00
beorn7 6bff9dc5a4 Make heap_released_bytes a Gauge.
It's not a counter after all.

Also, remove a misleading part of the sys_bytes help string.
2016-11-22 18:11:47 +01:00
beorn7 bc365741ee Improve timer examples 2016-11-21 19:16:56 +01:00
beorn7 89ca0458cb Change the Timer API
This finally makes the (presumably) common simple case as simple as it
gets.

The still quite common (but less common) case of using a Gauge is
slightly more verbose now, but not needing to provide a separate
constructor is totally worth it.

Finally, the advanced use case is not really more verbose as in my
original suggestion. However, the logic to decide which Observer to
use is now all in the ObserverFunc handed in at construction
time. This is deliberate and desired. It makes sure the selection
mechanism is all spelled out there. No surprises buried deep in the
function code somewhere.
2016-11-18 20:32:18 +01:00
beorn7 18c13ef63d Added doc comments 2016-11-18 20:32:18 +01:00
beorn7 8aba21aba3 Completed tests 2016-11-18 20:32:18 +01:00
beorn7 120be69578 Change timer naming from Start/Stop to New/ObserveDuration 2016-11-18 20:32:18 +01:00
beorn7 e63845e3ce Add observerFunc to observe with a Gauge 2016-11-18 20:32:18 +01:00
beorn7 8496756f6d Turn timer helper into a struct with methods 2016-11-18 20:32:18 +01:00
stuart nelson d845abb9f9 Add timer helper function 2016-11-18 20:32:18 +01:00
beorn7 e72c7946c6 Extend the example for pushing to pushgateway 2016-11-18 20:22:35 +01:00
beorn7 606b8f85e5 - Point from Inc and Dec to Add and Sub in doc comments.
- Deprecate Untyped for direct instrumentation.

- Add a SetToCurrentTime method to Gauge

Note that adding the SetToCurrentTime method is not really following
Go's principle of lean interfaces. However, the Gauge interface is
already quite fat. (The only methods really required are Set and
Add. Everything else could be expressed in terms of those two.) So we
have already quite a few "convenience" methods traditionally, so I
think we should stay consistent here.

The alternatives would be:

- Not support SetToCurrentTime at all (it's only a SHOULD in the
  guidelines).

- A top level function `SetToCurrentTime(Gauge)`.

- Just a helper `CurrentTime()` that returns the curent unix time in
  seconds as a float (which is pretty verbose using the standard
  library, see code in this commit). This would allow
  `myGauge.Set(CurrentTime)`.

Weighing all circumstances, I believe the way in this commit is the
least evil. Issue #223 could be used to rework interfaces more
fundamentally in a breaking change if feasible.
2016-11-18 19:32:10 +01:00
stuart nelson 7664178cb2 Graphite bridge (#244)
Add Graphite bridge
2016-11-14 14:43:07 +01:00
beorn7 dcbc5caa16 Remove local REs for label and metric names and use fast checks
All was a mess, we had duplicates of the REs for label name and metric
names here, and we sometimes used them, sometimes we used those from
common/model.

Now we are consistently using the fast checking functions from common/model.

(Tests for leading colons are included there, see
https://github.com/prometheus/common/pull/66 .)
2016-11-11 16:59:23 +01:00
Tobias Schmidt 99d64f8879 Fix namespace of process collector metrics 2016-11-02 14:09:24 -04:00
Marcus Franke 473bcd5aa1 [docs] enhanced the basic example
To protect people from starting their exporter multiple times, one has to
evaluate the error returned by http.ListenAndServe().
2016-11-02 10:48:36 +01:00
beorn7 2fee50beaa Remove deprecated features that are esay to replace
That's the "soft" part of the deprecation: Everything that has been
marked deprecated in v0.8 or earlier and is straight-forward to
replace by a non-deprecated way, is removed here.

Sadly, this does not include the HTTP part. We first need to provide a
replacement for HTTP instrumentation (as planned for v0.8) to then
remove the deprecated parts in v0.9.
2016-10-25 18:28:15 +02:00
beorn7 6450fc55b1 Convert process collector to const metrics
This is needed to remove the deprecated Set method from the Counter.
2016-10-25 18:19:24 +02:00
beorn7 6373fd9334 Adding a test for non-monotonic buckets 2016-10-17 13:57:02 +02:00
beorn7 c9325a4a67 Add goreport card and remove warnings where feasible 2016-09-16 19:59:04 +02:00
nghialv bc86b956d7 fix goroutine leak 2016-09-11 00:24:13 +09:00
beorn7 434a8ed85d Bring back zero-alloc label-value access for metric vecs
Also, fix mutex copy-by-value bug.
2016-08-17 14:01:11 +02:00
beorn7 1f823ab271 Refactor tests
Also, add a "real" collision to the tests.
2016-08-17 12:19:50 +02:00
beorn7 00d39222c2 Naming nit 2016-08-17 10:36:20 +02:00
Stephen J Day 4db77b04a8
metricvec: refactor collision handling to handle equality
After increasing unit test coverage, it was found that the split
function call nature of metric matching wasn't working well in many
cases. By increasing test coverage, we've ensured that both the fast
path and fallback collision path are working appropriately.

With these changes, there is a further performance hit, but now the
results are ensured to be correct.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
2016-08-16 18:34:16 -07:00
Stephen J Day 3cf50db5fd
metricvec: handle hash collision for labeled metrics
While hash collisions are quite rare, the current state of the client
library carries a risk of merging two separate label values into a
single metric bucket. The effects are near impossible to detect and the
result will be missing or incorrect counters.

This changeset handles hash collisions by falling back to collision
resolution if multiple label values hash to the same value. This works
similar to separate chaining using a slice. Extra storage is minimized
to only the value key slice to that metrics can be differentiated
within a bucket.

In general, the cost of handling collisions is completely minimized
under normal operation. Performance does show slight increases in
certain areas, but these are more likely statistically anomalies. More
importantly, zero allocation behavior for metrics is preserved on the
fast path. Minimal allocations may be made during collision handling but
this has minimal effect.

Benchmark comparisons with and without collision resolution follow.

```
benchmark                                                         old ns/op     new ns/op     delta
BenchmarkCounterWithLabelValues-4                                 99.0          107           +8.08%
BenchmarkCounterWithLabelValuesConcurrent-4                       79.6          91.0          +14.32%
BenchmarkCounterWithMappedLabels-4                                518           542           +4.63%
BenchmarkCounterWithPreparedMappedLabels-4                        127           137           +7.87%
BenchmarkCounterNoLabels-4                                        19.5          19.1          -2.05%
BenchmarkGaugeWithLabelValues-4                                   97.4          110           +12.94%
BenchmarkGaugeNoLabels-4                                          12.4          10.3          -16.94%
BenchmarkSummaryWithLabelValues-4                                 1204          915           -24.00%
BenchmarkSummaryNoLabels-4                                        936           847           -9.51%
BenchmarkHistogramWithLabelValues-4                               147           147           +0.00%
BenchmarkHistogramNoLabels-4                                      50.6          49.3          -2.57%
BenchmarkHistogramObserve1-4                                      37.9          37.5          -1.06%
BenchmarkHistogramObserve2-4                                      122           137           +12.30%
BenchmarkHistogramObserve4-4                                      310           352           +13.55%
BenchmarkHistogramObserve8-4                                      691           729           +5.50%
BenchmarkHistogramWrite1-4                                        3374          3097          -8.21%
BenchmarkHistogramWrite2-4                                        5310          5051          -4.88%
BenchmarkHistogramWrite4-4                                        12094         10690         -11.61%
BenchmarkHistogramWrite8-4                                        19416         17755         -8.55%
BenchmarkHandler-4                                                11934304      13765894      +15.35%
BenchmarkSummaryObserve1-4                                        1119          1105          -1.25%
BenchmarkSummaryObserve2-4                                        3679          3430          -6.77%
BenchmarkSummaryObserve4-4                                        10678         7982          -25.25%
BenchmarkSummaryObserve8-4                                        22974         16689         -27.36%
BenchmarkSummaryWrite1-4                                          25962         14680         -43.46%
BenchmarkSummaryWrite2-4                                          38019         35073         -7.75%
BenchmarkSummaryWrite4-4                                          78027         56816         -27.18%
BenchmarkSummaryWrite8-4                                          117220        132248        +12.82%
BenchmarkMetricVecWithLabelValuesBasic-4                          138           133           -3.62%
BenchmarkMetricVecWithLabelValues2Keys10ValueCardinality-4        150           144           -4.00%
BenchmarkMetricVecWithLabelValues4Keys10ValueCardinality-4        263           256           -2.66%
BenchmarkMetricVecWithLabelValues2Keys100ValueCardinality-4       145           155           +6.90%
BenchmarkMetricVecWithLabelValues10Keys100ValueCardinality-4      606           634           +4.62%
BenchmarkMetricVecWithLabelValues10Keys1000ValueCardinality-4     746           641           -14.08%

benchmark                                                         old allocs     new allocs     delta
BenchmarkCounterWithLabelValues-4                                 0              0              +0.00%
BenchmarkCounterWithLabelValuesConcurrent-4                       0              0              +0.00%
BenchmarkCounterWithMappedLabels-4                                2              2              +0.00%
BenchmarkCounterWithPreparedMappedLabels-4                        0              0              +0.00%
BenchmarkCounterNoLabels-4                                        0              0              +0.00%
BenchmarkGaugeWithLabelValues-4                                   0              0              +0.00%
BenchmarkGaugeNoLabels-4                                          0              0              +0.00%
BenchmarkSummaryWithLabelValues-4                                 0              0              +0.00%
BenchmarkSummaryNoLabels-4                                        0              0              +0.00%
BenchmarkHistogramWithLabelValues-4                               0              0              +0.00%
BenchmarkHistogramNoLabels-4                                      0              0              +0.00%
BenchmarkMetricVecWithLabelValuesBasic-4                          0              0              +0.00%
BenchmarkMetricVecWithLabelValues2Keys10ValueCardinality-4        0              0              +0.00%
BenchmarkMetricVecWithLabelValues4Keys10ValueCardinality-4        0              0              +0.00%
BenchmarkMetricVecWithLabelValues2Keys100ValueCardinality-4       0              0              +0.00%
BenchmarkMetricVecWithLabelValues10Keys100ValueCardinality-4      0              0              +0.00%
BenchmarkMetricVecWithLabelValues10Keys1000ValueCardinality-4     0              0              +0.00%

benchmark                                                         old bytes     new bytes     delta
BenchmarkCounterWithLabelValues-4                                 0             0             +0.00%
BenchmarkCounterWithLabelValuesConcurrent-4                       0             0             +0.00%
BenchmarkCounterWithMappedLabels-4                                336           336           +0.00%
BenchmarkCounterWithPreparedMappedLabels-4                        0             0             +0.00%
BenchmarkCounterNoLabels-4                                        0             0             +0.00%
BenchmarkGaugeWithLabelValues-4                                   0             0             +0.00%
BenchmarkGaugeNoLabels-4                                          0             0             +0.00%
BenchmarkSummaryWithLabelValues-4                                 0             0             +0.00%
BenchmarkSummaryNoLabels-4                                        0             0             +0.00%
BenchmarkHistogramWithLabelValues-4                               0             0             +0.00%
BenchmarkHistogramNoLabels-4                                      0             0             +0.00%
BenchmarkMetricVecWithLabelValuesBasic-4                          0             0             +0.00%
BenchmarkMetricVecWithLabelValues2Keys10ValueCardinality-4        0             0             +0.00%
BenchmarkMetricVecWithLabelValues4Keys10ValueCardinality-4        0             0             +0.00%
BenchmarkMetricVecWithLabelValues2Keys100ValueCardinality-4       0             0             +0.00%
BenchmarkMetricVecWithLabelValues10Keys100ValueCardinality-4      0             0             +0.00%
BenchmarkMetricVecWithLabelValues10Keys1000ValueCardinality-4     0             0             +0.00%
```

Signed-off-by: Stephen J Day <stephen.day@docker.com>
2016-08-15 16:47:53 -07:00
Stephen J Day c4004ef5f6
benchmark: measure label resolution in MetricVec
Signed-off-by: Stephen J Day <stephen.day@docker.com>
2016-08-15 16:47:42 -07:00
Bjoern Rabenstein 25db044749 Fix doc comment typo 2016-08-15 23:22:46 +02:00
beorn7 390e874a3f Fix doc comment typo 2016-08-15 15:54:18 +02:00
beorn7 a6321dd0b1 Create a "merge gatherer"
This allows to finally get rid of the infamous injection hook in the
interface. The old SetMetricFamilyInjectionHook still exist as a
deprecated function but is now implemented with the new plumbing under
the hood.

Now that we have multiple Gatherer implementation, I renamed
push.Registry to push.FromGatherer.

This commit also improves the consistency checks, which happened as a
byproduct of the refactoring to allow checking in both the "merge
gatherer" Gatherers as well as in the normal Registry.
2016-08-12 21:34:17 +02:00
beorn7 1dc03a72f6 Replace hashicorp/go-multierror by own implementation
The own implementation is much easier as it only has to serve our one
use case.
2016-08-04 16:03:06 +02:00
beorn7 f0c45acc50 Rename Deliver into Gather 2016-08-04 15:26:27 +02:00
beorn7 f9c977b1d6 Doc: Make the AlreadyRegisteredError example a real example 2016-08-04 11:41:02 +02:00
beorn7 bc0b2a3b17 Move http stuff in its own package promhttp
To keep backwards compatibility while not creating circular import
chains, some code had to be duplicated. But all functions using it
have been declared deprecated hereby.

The new ways of instrumenting handlers will all go into the new
package, and ultimately, the prometheus package itself will be
completely igorant of HTTP.
2016-08-03 18:06:48 +02:00
beorn7 2e66d12fe5 Act on DefaultRegisterer and DefaultDeliverer where possible
Both point to the DefaultRegistry anyway, but users can now replace it
with interfaces rather than only other Registry instances.
2016-08-03 12:50:39 +02:00
beorn7 e5c6302150 Fix a number of doc comments and similar nits 2016-08-03 12:23:37 +02:00
beorn7 5a918da56d Tweaked push package
- Moved the Deliverer parameter to the end of the list to mirror
  Collectors in push.Collectors.
- Improved doc comment and added an example for push.Registry.
2016-08-03 12:00:19 +02:00
beorn7 249069ec01 Unexport SelfCollector.
This is most likely used nowhere and can be unexported to clean up the
namespace.
2016-08-03 01:09:27 +02:00
beorn7 9c3fe750dd Expose the registry implementation and add two interfaces.
Registry is now a struct, which implements two interfaces, Registrerer
and Deliverer. The latter is particularly important as it is now the
argument type for pushes and HTTP handler construction (i.e. it is
easy to implement a custom Deliverer for testing or other
purposes). The Registerer interface is not used as a parameter type
but can (and should) be used by users of custom registries so that
they can easily do things like mocking it out for testing purposes.

With the broken up interfaces, adding MustRegister to the interface is
not such a big deal anymore (interface is still small). And since
setting the injection hook is such a rare thing to happen, it is
acceptable to not have it in any of the interfaces.

The renaming from `Collect` to `Deliver` was done to avoid confusion
with Collectors. (The registry _collects_ from the Collectors, and
then _delivers_ to the exposition mechanism.)
2016-08-03 01:02:34 +02:00
beorn7 cf7e1caf17 Create a public registry interface and separate out HTTP exposition
General context and approch
===========================

This is the first part of the long awaited wider refurbishment of
`client_golang/prometheus/...`. After a lot of struggling, I decided
to not go for one breaking big-bang, but cut things into smaller steps
after all, mostly to keep the changes manageable and easy to
review. I'm aiming for having the invasive breaking changes
concentrated in as few steps as possible (ideally one). Some steps
will not be breaking at all, but typically there will be breaking
changes that only affect quite special cases so that 95+% of users
will not be affected. This first step is an example for that, see
details below.

What's happening in this commit?
================================

This step is about finally creating an exported registry
interface. This could not be done by simply export the existing
internal implementation because the interface would be _way_ too
fat. This commit introduces a qutie lean `Registry` interface
(compared to the previous interval implementation). The functions that
act on the default registry are retained (with very few exceptions) so
that most use cases won't see a change. However, several of those are
deprecated now to clean up the namespace in the future.

The default registry is kept in the public variable
`DefaultRegistry`. This follows the example of the http package in the
standard library (cf. `http.DefaultServeMux`, `http.DefaultClient`)
with the same implications. (This pattern is somewhat disputed within
the Go community but I chose to go with the devil you know instead of
creating something more complex or even disallowing any changes to the
default registry. The current approach gives everybody the freedom to
not touch DefaultRegistry or to do everything with a custom registry
to play save.)

Another important part in making the registry lean is the extraction
of the HTTP exposition, which also allows for customization of the
HTTP exposition. Note that the separation of metric collection and
exposition has the side effect that managing the MetricFamily and
Metric protobuf objects in a free-list or pool isn't really feasible
anymore. By now (with better GC in more recent Go versions), the
returns were anyway dimisishing. To be effective at all, scrapes had
to happen more often than GC cycles, and even then most elements of
the protobufs (everything excetp the MetricFamily and Metric structs
themselves) would still cause allocation churn. In a future breaking
change, the signature of the Write method in the Metric interface will
be adjusted accordingly. In this commit, avoiding breakage is more
important.

The following issues are fixed by this commit (some solved "on the
fly" now that I was touching the code anyway and it would have been
stupid to port the bugs):

https://github.com/prometheus/client_golang/issues/46
https://github.com/prometheus/client_golang/issues/100
https://github.com/prometheus/client_golang/issues/170
https://github.com/prometheus/client_golang/issues/205

Documentation including examples have been amended as required.

What future changes does this commit enable?
============================================

The following items are not yet implemented, but this commit opens the
possibility of implementing these independently.

- The separation of the HTTP exposition allows the implementation of
  other exposition methods based on the Registry interface, as known
  from other Prometheus client libraries, e.g. sending the metrics to
  Graphite.
  Cf. https://github.com/prometheus/client_golang/issues/197

- The public `Registry` interface allows the implementation of
  convenience tools for testing metrics collection. Those tools can
  inspect the collected MetricFamily protobufs and compare them to
  expectation. Also, tests can use their own testing instance of a
  registry.
  Cf. https://github.com/prometheus/client_golang/issues/58

Notable non-goals of this commit
================================

Non-goals that will be tackled later
------------------------------------

The following two issues are quite closely connected to the changes in
this commit but the line has been drawn deliberately to address them
in later steps of the refurbishment:

- `InstrumentHandler` has many known problems. The plan is to create a
  saner way to conveniently intrument HTTP handlers and remove the old
  `InstrumentHandler` altogether. To keep breakage low for now, even
  the default handler to expose metrics is still using the old
  `InstrumentHandler`. This leads to weird naming inconsistencies but
  I have deemed it better to not break the world right now but do it
  in the change that provides better ways of instrumenting HTTP
  handlers.
  Cf. https://github.com/prometheus/client_golang/issues/200

- There is work underway to make the whole handling of metric
  descriptors (`Desc`) more intuitive and transparent for the user
  (including an ability for less strict checking,
  cf. https://github.com/prometheus/client_golang/issues/47). That's
  quite invasive from the perspective of the internal code, namely the
  registry. I deliberately kept those changes out of this commit.

- While this commit adds new external dependency, the effort to vendor
  anything within the library that is not visible in any exported
  types will have to be done later.

Non-goals that _might_ be tackled later
---------------------------------------

There is a strong and understandable urge to divide the `prometheus`
package into a number of sub-packages (like `registry`, `collectors`,
`http`, `metrics`, …). However, to not run into a multitude of
circular import chains, this would need to break every single existing
usage of the library. (As just one example, if the ubiquitious
`prometheus.MustRegister` (with more than 2,000 uses on GitHub alone)
is kept in the `prometheus` package, but the other registry concerns
go into a new `registry` package, then the `prometheus` package would
import the `registry` package (to call the actual register method),
while at the same time the `registry` package needs to import the
`prometheus` package to access `Collector`, `Metric`, `Desc` and
more. If we moved `MustRegister` into the `registry` package,
thousands of code lines would have to be fixed (which would be easy if
the world was a mono repo, but it is not). If we moved everything else
the proposed registry package needs into packages of their own, we
would break thousands of other code lines.)

The main problem is really the top-level functions like
`MustRegister`, `Handler`, …, which effectively pull everything into
one package. Those functions are however very convenient for the easy
and very frequent use-cases.

This problem has to be revisited later.

For now, I'm trying to keep the amount of exported names in the
package as low as possible (e.g. I unexported expvarCollector in this
commit because the NewExpvarCollector constructor is enough to export,
and it is now consistent with other collectors, like the goCollector).

Non-goals that won't be tackled anytime soon
--------------------------------------------

Something that I have played with a lot is "streaming collection",
i.e. allow an implementation of the `Registry` interface that collects
metrics incrementally and serves them while doing so. As it has turned
out, this has many many issues and makes the `Registry` interface very
clunky. Eventually, I made the call that it is unlikely we will really
implement streaming collection; and making the interface more clunky
for something that might not even happen is really a big no-no. Note
that the `Registry` interface only creates the in-memory
representation of the metric family protobufs in one go. The
serializaton onto the wire can still be handled in a streaming fashion
(which hasn't been done so far, without causing any trouble, but might
be done in the future without breaking any interfaces).

What are the breaking changes?
==============================

- Signatures of functions pushing to Pushgateway have changed to allow
  arbitrary grouping (which was planned for a long time anyway, and
  now that I had to work on the Push code anyway for the registry
  refurbishment, I finally did it,
  cf. https://github.com/prometheus/client_golang/issues/100).
  With the gained insight that pushing to the default registry is almost
  never the right thing, and now that we are breaking the Push call
  anyway, all the Push functions were moved to their own package,
  which cleans up the namespace and is more idiomatic (pushing
  Collectors is now literally done by `push.Collectors(...)`).

- The registry is doing more consistency checks by default now. Past
  creators of inconsistent metrics could have masked the problem by
  not setting `EnableCollectChecks`. Those inconsistencies will now be
  detected. (But note that a "best effort" metrics collection is now
  possible with `HandlerOpts.ErrorHandling = ContinueOnError`.)

- `EnableCollectChecks` is gone. The registry is now performing some
  of those checks anyway (see previous item), and a registry with all
  of those checks can now be created with `NewPedanticRegistry` (only
  used for testing).

- `PanicOnCollectError` is gone. This behavior can now be configured
  when creating a custom HTTP handler.
2016-08-02 18:46:22 +02:00
Uwe Dauernheim c1e8a41238 Fix typo in doc string 2016-08-01 23:14:45 +02:00
Andrew Stuart e63e6e3db7
Extend MustRegister function to accept variadic args 2016-07-11 15:04:23 -07:00
Matt Bostock c7f1ecb643 Fix GoDoc indentation
The line after the first in each bullet point was appearing as
preformatted blocks when viewed as HTML in GoDoc.
2016-06-27 15:26:48 +01:00
Chris Lonng 7752efd9d6 comment contains some misspell 2016-06-27 17:49:34 +08:00
Björn Rabenstein 488edd04dc Merge pull request #202 from mattyw/01-docs
prometheus/docs: Added a link to the metric types page
2016-05-31 11:15:28 +02:00
mattyw 3c063fb533 prometheus/docs: Added a link to the metric types page 2016-05-31 10:07:50 +01:00
beorn7 f6b16ed256 Document the issues of InstrumentHandler
Obvious next step: Fix those issues.
2016-05-15 17:59:51 +02:00
Matt Harden e3340f3371 Fix max_fds process collector test
This test fails when max_fds is a large value; say 4.5e+06, for example. Change it to match virtual_memory_bytes, which also has to handle large values.
2016-05-12 16:55:21 -07:00
Brian Brazil 09374d92aa Remove anti-pattern of having target labels in instrumentation example. 2016-03-17 13:22:20 +00:00
Harmen e48dd8ee97 fix go_memstats_last_gc_time_seconds division 2016-02-08 01:28:30 +01:00
Michael Stapelberg c1370d07ca Strip trailing / from push URL.
This circumvents the following problem:
• The prometheus client library appends “/metrics/…” to the pushURL.
• When pushURL ends in a trailing slash, the URL becomes e.g.
  http://pushgateway.example.com:9091//metrics/…
• The pushgateway will reply with an HTTP 307 status code
  (temporary redirect).
• While Go’s net/http client follows redirects by default, it will only
  follow HTTP 302 (Found) and HTTP 303 (See Other) redirects for PUT and
  POST requests, which the prometheus client library uses.

Hence, when calling e.g.:

    prometheus.Push("foo", "bar", "http://pushgateway.example.com:9091/")

…your metrics would not actually get pushed successfully, but rather
you’d see the error message:

    2015/11/26 10:59:49 main.go:209: unexpected status code 307 while pushing to http://push...
2015-11-26 19:16:53 +01:00
Michael Stapelberg 1a09b46c2e fix typo: s/addr/url/ 2015-11-25 08:46:01 +01:00
Harmen 5d4fdca1a5 use local fnv hash everywhere 2015-11-12 14:07:23 +01:00
Björn Rabenstein cfd904193d Merge pull request #180 from dnesting/dnesting-sort-metrics
Make metric sort stable and sort by timestamp
2015-11-10 22:31:22 +01:00
David Nesting b0bd184e74 Simplify metricSorter timestamp comparison and improve comment 2015-11-10 09:37:58 -05:00
David Nesting 544f65f7fc metricSorter stops relying on time.Now and respects nil timestamps 2015-11-09 17:14:07 -05:00
David Nesting 5fb1b89678 Make metric sort stable and sort by timestamp 2015-11-09 16:55:26 -05:00
Robert Vollmert 8c96b12588 try getting metrics with a read lock, first 2015-11-09 15:16:26 +01:00
Robert Vollmert 5183814775 ok not has 2015-11-09 15:16:26 +01:00
Robert Vollmert 1312da4c0c Inline hash/fnv. 2015-11-09 15:16:26 +01:00
Robert Vollmert 39a26f2e35 concurrency benchmark 2015-11-09 14:34:37 +01:00
Björn Rabenstein e51041b3fa Merge pull request #146 from KevinPike/memstats
memstats collection
2015-10-08 16:32:47 +02:00
Kevin Pike db58b27d95 heap bytes released total 2015-10-07 11:21:49 -07:00
Kevin Pike 1eb8d032a8 use counter for heap released bytes 2015-10-06 08:18:17 -07:00
Kevin Pike 9a6b9d3ddf fix descriptions 2015-10-05 09:27:28 -07:00
Kevin Pike 6c7a1db6bf don't reuse memstats 2015-10-05 07:37:59 -07:00
Kevin Pike 8a031ee219 unembed memstats collector 2015-10-02 18:10:36 -07:00
beorn7 90ddfa1c1e Move from client_golang/text to common/expfmt 2015-09-17 13:06:43 +02:00
Björn Rabenstein 29939ec908 Merge pull request #160 from ardan-bkennedy/master
Update histogram_test.go
2015-08-28 12:34:13 +02:00
Fabian Reinartz f2de0f589a Remove client_golang/model als direct dependency 2015-08-23 13:51:32 +02:00
Julius Volz 4a339dcbca Fix minor typos in comment. 2015-08-17 12:58:16 +02:00
William Kennedy f075821cbb Update histogram_test.go
These tests are always timing out in our Jenkins CI environment. We have moved our timeout to 2 minutes. I have added a check for the short flag so other can skip these tests as we are until this can be identified.
2015-08-12 17:51:21 -04:00
William Kennedy a794f77b54 Update go_collector_test.go
We are running into a timeout with TestHistogramConcurrency on our Jenkins box. I noticed in the stack trace for the timeout this block.

goroutine 2348 [chan send]:
github.comcast.com/ventris/kober/vnd/github.com/prometheus/client_golang/prometheus.(*goCollector).Collect(0xc20801e8e0, 0xc20800a7e0)
	/var/lib/jenkins/jobs/Kober/workspace/src/github.comcast.com/ventris/kober/vnd/github.com/prometheus/client_golang/prometheus/go_collector.go:49 +0x6dd
github.comcast.com/ventris/kober/vnd/github.com/prometheus/client_golang/prometheus.func·028()
	/var/lib/jenkins/jobs/Kober/workspace/src/github.comcast.com/ventris/kober/vnd/github.com/prometheus/client_golang/prometheus/go_collector_test.go:27 +0x11a
created by github.comcast.com/ventris/kober/vnd/github.com/prometheus/client_golang/prometheus.TestGoCollector
	/var/lib/jenkins/jobs/Kober/workspace/src/github.comcast.com/ventris/kober/vnd/github.com/prometheus/client_golang/prometheus/go_collector_test.go:28 +0x35e

This suggested that even though the TestGoCollector test was finished, a goroutine was still hanging around. I traced it back to the call to c.Collect always sending twice of the provided channel. This change receives that second value and allows the goroutine to finish with the test.

Still can't figure out why TestHistogramConcurrency is timing out after 2 minutes :(
2015-08-12 15:23:41 -04:00
Robert Vollmert 1e201f4328 Reword, using "φ-quantile". 2015-08-03 14:10:20 +02:00
Robert Vollmert 5b1aa4ab69 More explicit documentation of SummaryOpts.Objectives. 2015-08-03 13:49:15 +02:00
Kevin Pike c945ed62c1 use metrics struct. include more statistics 2015-07-21 20:29:02 -07:00
Kevin Pike 5e9294fbb7 continue to fix errors 2015-07-21 08:38:46 -07:00
Kevin Pike 59305998f6 remove prometheus namespace references, copy paste error 2015-07-21 08:34:50 -07:00
Kevin Pike b14b149930 use counters where applicable, improve descriptions 2015-07-21 08:24:22 -07:00
Kevin Pike 8a6e3ecf23 adds general and heap memory statistics 2015-07-20 20:55:38 -07:00
beorn7 7abba842b0 Document the possibility to create "empty" metrics in a metric vector.
This fixes https://github.com/prometheus/client_golang/issues/119.
2015-07-15 13:13:56 +02:00
Julius Volz a03cc290e7 Merge pull request #139 from prometheus/fix-untyped-ref
Fix doc-comment reference to Untyped metric.
2015-06-13 12:22:23 +02:00
Julius Volz 209414d85f Mention histograms in doc.go. 2015-06-13 12:20:08 +02:00
Julius Volz b6525949dd Fix doc-comment reference to Untyped metric. 2015-06-13 02:16:27 +02:00
beorn7 59f2c7d8b0 Fix a number of minor things.
- Clarify documentation about sorting requirements.
- Add missing histogram support in consistency check.
- Add label sorting to consistency check.
- Improve error messages when reporting a metric.
  (Previously, the metric name was not printed.)
2015-06-09 12:03:07 +02:00
Tomasz Elendt dd4dd69878 Solve "The Proxy Problem" of InstrumentHandler
InstrumentHandler provides proxy object over given http.ResponseWriter
- responseWriterDelegator that only implements the bare minimum
required of an http.ResponseWriter and doesn’t implement any interface
upgrades (http.Flusher, http.Hijacker, etc.). This commit fixes it by
providing fancyResponseWriterDelegator with all the fancy bells and
whistles if standard library http.ResponseWriter is detected.

Heavily inspired by Goji's middleware.

https://avtok.com/2014/11/05/interface-upgrades.html#the-proxy-problem
2015-06-04 23:48:40 +02:00
Tomasz Elendt 288762e79c Change responseWriterDelegator.written to int64
Change responseWriterDelegator.written to int64 so that responses
bigger than 4GB could be properly observed on 32 bit systems.
2015-06-04 23:14:37 +02:00
beorn7 10eab41b48 Make LabelNameRE public. 2015-06-01 15:41:09 +02:00
Michael Stapelberg 23ef520369 doc fix: s/DefObjectives/DefBuckets/ 2015-05-30 17:30:45 +02:00
beorn7 944920c696 Ensure alignment of struct members used in sync.atomic functions. 2015-05-21 12:19:38 +02:00
Tobias Schmidt 765c1152ca Rename process_goroutines to go_goroutines
The decision was made to use the language name for language specific
metrics, so go_goroutines is the right names similar to
go_gc_duration_seconds.
2015-05-19 15:47:08 -04:00
Oliver 21b132f5a2 record quantiles as well 2015-05-05 12:33:35 -04:00
Oliver ff586eaac1 Add garbage collection stats 2015-05-05 09:52:36 -04:00
beorn7 c8a7ccf663 Improvements after review. 2015-05-04 13:13:06 +02:00
beorn7 70419a3485 Add examples for const summary/histogram. 2015-05-04 12:22:15 +02:00
Bjoern Rabenstein 9c4fec0bce Implement constSummary and constHistogram. 2015-05-04 00:32:15 +02:00
Julius Volz 066ab78410 Correct typo in Counter.Set() docstring. 2015-04-30 18:51:33 +02:00
beorn7 63acb006f7 Purge another trace of ext -> pbutil. 2015-04-07 15:19:47 +02:00
Julius Volz 7b2ff852ca Inline and remove processCollectSupported(). 2015-04-01 01:18:20 +02:00
Julius Volz 2b9d181f5b Merge process_collector{,procfs}.go files into one. 2015-03-31 18:24:46 +02:00
Julius Volz 21b7c6b048 Always build the procfs collector.
The cgo dependency in the "procfs" package is being removed in:

  https://github.com/prometheus/procfs/pull/4

So now it should be fine to always import the "procfs" package and have
it determine dynamically at runtime whether the proc filesystem is
actually there.

This fixes a problem for users which were vendoring client_golang on
MacOS X, but building the result on Linux (the procfs package was
missing in the vendored packages).
2015-03-31 18:07:40 +02:00
beorn7 4ab527fc50 Fix merge conflicts. 2015-03-16 15:15:02 +01:00
beorn7 f3cda15667 Add functions to push individual collectors to a Pushgateway.
Move all Pushgateway related top-level functions to push.go.
2015-03-15 19:29:57 +01:00
beorn7 a762e0612e Allow the metric family injection hook to merge with existing metric families.
If a metric family returned by the injection hook already exists (with
the same name), then its metrics are simply merged into that metric
family. With enabled collect-time checks, even uniqueness is checked,
but in general, things stay the same that the caller is responsible to
ensure metric consistency.

This fixes https://github.com/prometheus/pushgateway/issues/27 .
2015-03-15 16:34:31 +01:00
beorn7 715be73ac9 Return NaN when summaries have no observations yet.
Also, properly handle decay upon Write().

This fixes https://github.com/prometheus/client_golang/issues/85 .
2015-03-15 16:33:56 +01:00
Julius Volz 738b69e61a Use non-rewritten Godep imports. 2015-02-27 16:49:40 +01:00
Julius Volz 169c8a68e1 Use godep with import rewriting for vendoring.
The new vendoring was produced by running:

    godep save -r ./examples/... ./prometheus/... ./text/... ./model/... ./extraction/...

Two things to note:

- "extraction/processor0_0_{1,2}_test.go" imported a package from
  "github.com/prometheus/prometheus", all for just one tiny testing
  function. To not have to deal with a circular vendoring dependency, I
  simply replaced the usage of the function by some in-line logic.

- godep grouped the rewritten imports slightly differently for some
  reason, but at least the standard library imports are still in a
  separate section. Not sure if it's worth manually keeping our old
  import grouping scheme or if we should simply use that godep-generated
  one.
2015-02-26 00:47:03 +01:00
Peter Bourgon 69c8dc87e9 Fix for Histogram in registry.writePB 2015-02-20 19:08:36 +01:00
beorn7 79efd06178 Use binary search to pick bucket.
With the usual number of buckets, this doesn't really make a
difference, but it should scale... See the added TODO for the precise
numbers.
2015-02-20 15:53:53 +01:00
beorn7 9eaf3705d2 Avoid "online serving system". 2015-02-19 16:03:24 +01:00
beorn7 000ef45157 Replaced http by HTTP if used as the name of the protocol in English. 2015-02-19 15:54:26 +01:00
beorn7 b1e7299877 Turned "le" and "quantile" label names into constants. 2015-02-19 15:54:26 +01:00
beorn7 3e50eddd64 Do not count the +Inf bucket for bucket creation.
Add explanation for DefBuckets.
2015-02-19 15:54:26 +01:00
beorn7 4c4f51d546 Catch illegal label names for summaries in histograms. 2015-02-19 15:54:26 +01:00
beorn7 6958242277 Add support for histograms to the Go client library. 2015-02-19 15:54:26 +01:00
beorn7 a7c56882af Mark slow test as such and exclude them from travis. 2015-02-19 15:51:11 +01:00
Julius Volz 765fdaf37e Update protobuf library package name.
The Golang protocol buffer library has now moved to GitHub:

https://github.com/golang/protobuf

Although "go get"-ing the old package name still works, moving
everything to the new one will make vendoring cleaner.

See also https://github.com/matttproud/golang_protobuf_extensions/pull/7
2015-02-14 00:00:34 +01:00
Deyuan Deng 550b950411 Fix document 2015-02-11 17:35:04 -05:00
Tobias Schmidt 98061eecab Add todo comment to bring back error reporting 2015-02-11 14:58:35 -05:00
Tobias Schmidt 7faf9e76ef Handle process collector errors gracefully
As it is expected that the process collector can fail under certain
conditions (proc information for a process only readable by root or
other user for example) and as there is currently no option to configure
the error behavior of the client, this change reverts the error
reporting introduced in 159e96f. This effectively means that errors are
simply ignored and there won't be any samples for the process_* metrics
in case of an error.

Once a user can control how to behave in case of errors returned by
collectors, this change should probably be reverted.
2015-02-10 16:19:27 -05:00
Johannes 'fish' Ziemke 93d11c8e35 Remove procfs dependency unless cgo is enabled 2015-02-09 16:38:04 +01:00
Tobias Schmidt d1d9dee31b Remove dependency on procfs/cgo in non-procfs systems
The procfs package has a cgo dependency (necessary to calculate system
times). As procfs is not available under windows, darwin and supposely
all newer BSD systems, this change remove the procfs dependency on these
systems.
2015-02-02 15:40:04 -05:00
Tobias Schmidt 3cb16a9503 Use clear error interface for process pidFn
If a given pidFn for a process collector can't determine the pid, this
had to be signaled with an invalid pid so far (pid <= 0). In order to
make the error interface clearer for users, this change introduces an
explicit error parameter.
2015-02-02 14:59:24 -05:00
beorn7 4f73a8b017 Improve Gauge and Counter performance.
This is accomplished by using the functions from the atomic packages
instead of a mutex.

benchmark                                      old ns/op     new ns/op     delta
BenchmarkGaugeNoLabels-2                       118           9.40          -92.03%
BenchmarkGaugeNoLabels                         117           9.38          -91.98%
BenchmarkGaugeNoLabels-4                       117           9.40          -91.97%
BenchmarkCounterNoLabels-2                     137           16.8          -87.74%
BenchmarkCounterNoLabels                       136           16.8          -87.65%
BenchmarkCounterNoLabels-4                     136           16.8          -87.65%
BenchmarkGaugeWithLabelValues-4                400           279           -30.25%
BenchmarkGaugeWithLabelValues-2                398           279           -29.90%
BenchmarkGaugeWithLabelValues                  400           283           -29.25%
BenchmarkCounterWithLabelValues-4              397           286           -27.96%
BenchmarkCounterWithLabelValues-2              396           286           -27.78%
BenchmarkCounterWithLabelValues                394           285           -27.66%
BenchmarkCounterWithPreparedMappedLabels       587           454           -22.66%
BenchmarkCounterWithPreparedMappedLabels-2     581           456           -21.51%
BenchmarkCounterWithPreparedMappedLabels-4     654           539           -17.58%
BenchmarkCounterWithMappedLabels-2             1441          1218          -15.48%
BenchmarkCounterWithMappedLabels               1099          963           -12.37%
BenchmarkCounterWithMappedLabels-4             1636          1501          -8.25%
2015-02-02 18:11:11 +01:00
Bjoern Rabenstein d7f8eb1083 Change "Prometheus Team" to "The Prometheus Authors". 2015-02-02 15:14:36 +01:00
Julius Volz f3e101bd1c Fix race condition in writePB().
The RLock already needs to be acquired when reading r.dimHashesByName.

This fixes https://github.com/prometheus/client_golang/issues/61
2015-01-31 22:10:27 +01:00
Bjoern Rabenstein 3798bbca12 Add const labels to counter. 2015-01-28 15:47:48 +01:00
juliusv 3713bd7d97 Merge pull request #48 from prometheus/beorn7/fix-summary-dimensions
Beorn7/fix summary dimensions
2015-01-22 17:03:39 +01:00
Bjoern Rabenstein 31b6c1fe12 Make number notation consistent. 2015-01-21 15:24:34 +01:00
Bjoern Rabenstein 15c9ded5a3 Fix the summary decay by avoiding the Merge method.
This makes the Observe method of summaries more expensive. :-(
2015-01-21 13:44:43 +01:00
Bjoern Rabenstein 6b9530d72e Update vendoring of perks to newest (fixed) version.
Adjust the API and usage accordingly.
Make tests stricter.

Since the merging is still faulty, test are broken now.
The next commit will fix it by avoiding merging.
2015-01-20 18:27:10 +01:00
Bjoern Rabenstein 26e2417d3e Quick-fix the doc comment. 2015-01-13 17:26:38 +01:00
Bjoern Rabenstein 5c6a472617 Merge branch 'beorn7/allow-collect-errors' into beorn7/fix-summary-dimensions 2015-01-13 16:54:12 +01:00
Bjoern Rabenstein dd4e57186a Improve doc comment for Describe. 2015-01-13 16:52:42 +01:00
Bjoern Rabenstein 05059724f8 Remove the partition of summaries by HTTP status code and method.
Summaries as implemented cannot be aggregated in a meaningful
way. Partitoning them by status code and method only made sense if we
were interested in the individual latency and size of e.g. GET request
that result in status 503. In general, that's not the case. Most of
the time, the user will be interested in the latency and size of _all_
HTTP requests.

(With future changes to client_golang, we will consider making the
HTTP instrumentation configurable, e.g. to handle the case where the
user is only interested in the latency of successful requests.)
2015-01-13 14:57:37 +01:00
Bjoern Rabenstein 159e96f6c7 Allow error reporting during metrics collection and simplify Register().
Both are interface changes I want to get in before public
announcement. They only break rare usage cases, and are always easy to
fix, but still we want to avoid breaking changes after a wider
announcement of the project.

The change of Register() simply removes the return of the Collector,
which nobody was using in practice. It was just bloating the call
syntax. Note that this is different from RegisterOrGet(), which is
used at various occasions where you want to register something that
might or might not be registered already, but if it is, you want the
previously registered Collector back (because that's the relevant
one).

WRT error reporting: I first tried the obvious way of letting the
Collector methods Describe() and Collect() return error. However, I
had to conclude that that bloated _many_ calls and their handling in
very obnoxious ways. On the other hand, the case where you actually
want to report errors during registration or collection is very
rare. Hence, this approach has the wrong trade-off. The approach taken
here might at first appear clunky but is in practice quite handy,
mostly because there is almost no change for the "normal" case of "no
special error handling", but also because it plays well with the way
descriptors and metrics are handled (via channels).

Explaining the approach in more detail:

- During registration / describe: Error handling was actually already
  in place (for invalid descriptors, which carry an error anyway). I
  only added a convenience function to create an invalid descriptor
  with a given error on purpose.

- Metrics are now treated in a similar way. The Write method returns
  an error now (the only change in interface). An "invalid metric" is
  provided that can be sent via the channel to signal that that metric
  could not be collected. It alse transports an error.

NON-GOALS OF THIS COMMIT:

This is NOT yet the major improvement of the whole registry part,
where we want a public Registry interface and plenty of modular
configurations (for error handling, various auto-metrics, http
instrumentation, testing, ...). However, we can do that whole thing
without breaking existing interfaces. For now (which is a significant
issue) any error during collection will either cause a 500 HTTP
response or a panic (depending on registry config). Later, we
definitely want to have a possibility to skip (and only report
somehow) non-collectible metrics instead of aborting the whole scrape.
2015-01-12 19:16:09 +01:00
Jeff Younker 014d4bd173 Remove a Go 1.4ism to allow compilation under Go 1.3. 2015-01-09 14:52:23 +01:00
Tobias Schmidt d66557ae59 Register process and go collectors by default 2014-12-22 13:55:44 -05:00
Tobias Schmidt dbd48d666b Add ProcessCollector and GoCollector
This change adds two new collectors to the prometheus package which
export metrics about a given or the current process.

* ProcessCollector exports metrics about cpu time, vss, rss, fd usage as
  well as the start time of a given process.
* GoCollector exports currently only the number of active goroutines.
2014-12-22 13:49:45 -05:00
Julius Volz 7fcb2c594a Drain collector channel when returning prematurely. 2014-12-19 14:18:55 +01:00
Bjoern Rabenstein 4c69ef579b Disable the timing-sensitive test TestSummaryDecay for now.
Obviously, the proper solution is to implement the test in a way that
does not depend on timing.
2014-12-18 18:05:06 +01:00
Bjoern Rabenstein f4be228ba0 Fix a race condition in the http instrumentation.
computeApproximateRequestSize is run in a goroutine, but the
handlerFunc that runs in parallel may modify the URL, which is also
needed by computeApproximateRequestSize. So get the URL length
beforehand.

Change-Id: Idb84735845afe7be4ef79b3d642d5764f6d26a7c
2014-10-08 19:01:24 +02:00
Bjoern Rabenstein 6fbc8ef5c2 Fix typo in doc comment.
Change-Id: Ifa40feb83e89b60b8e3efea298264d91f3758ecb
2014-09-19 13:20:59 +02:00
Bjoern Rabenstein b09d588309 Add missing error check.
Change-Id: I6fcf6d5d50333ff0c205fd87cdb9430f1bc02c43
2014-07-30 19:02:39 +02:00
Bjoern Rabenstein 96297bcbae Add a configurable version of InstrumentHandler and InstrumentHandlerFunc.
Also, remove quotes from the Content-type header. It's not illegal to
have quotes there, but they are not needed, and at other places, we
are not using them. So fewer characters and more consistency.

Change-Id: If7a78bde85154163e4426daec493d973213e83e9
2014-07-22 17:40:20 +02:00
Bjoern Rabenstein 23e5e5fefd Add gzip support.
Change-Id: I6ea6e0dcbe7234ad143403d262da6cb40e7d3b50
2014-07-04 17:08:57 +02:00
Bjoern Rabenstein 5ac9f00fa9 Add Content-Length header.
Since we prepare the whole content in a buf before sending, we can as
well set the Content-Length explicitly.

Change-Id: Ifd91764c90af53be49f93f0b33032138130b6f96
2014-07-03 13:12:39 +02:00
Bjoern Rabenstein 0afe1a813e Add pushgateway support.
Change-Id: I4730b150ac84ae38939b16effaf4b2ad4afa5bc0
2014-07-03 13:12:39 +02:00
Bjoern Rabenstein 998774096c Make the collectorID independent of the desc order.
This is actually the intended behavior, and (as a nice side effect)
makes things cheaper to calculate.

Also, introduce a separator character to avoid hash collisions
(like label values {"ab","c"} vs {"a", "bc"}).

Apply the same principles to signature.go.

Change-Id: I607db544f278ed89684fe5fa11abdbc3e03d3061
2014-06-26 15:50:11 +02:00
Bjoern Rabenstein 010dc1af88 Vendorize perks/quantile.
Change-Id: I2b24bddf5a975a46ceb598db328c317982154466
2014-06-23 19:48:50 +02:00
Bjoern Rabenstein f9401ffab9 Added "callback" metrics, e.g. GaugeFunc.
Change-Id: I449b558207963ce60572bd04c8102f1db684dd4c
2014-06-23 14:35:01 +02:00
Bjoern Rabenstein 5122dc6cc0 Fix doc comment typo.
Change-Id: I19b4b553b01823da0c1015d779f1f05b2c2cfb5b
2014-06-23 11:45:49 +02:00
Bjoern Rabenstein 8234d12ed0 Add InstrumentHandlerFunc.
Also, fix seconds to microseconds fot the http instrumentation to
match the metric name.

Fix Desc.String().

Simplify http error display.

Change-Id: Ib7397f4eac1eeed92b291e1c9cc88c080aee99ca
2014-06-20 20:57:27 +02:00
Bjoern Rabenstein 5d40912fd2 Complete rewrite of the exposition library.
This rewrite had may backs and forths. In my git repository, it
consists of 35 commits which I cannot group or merge into reasonable
review buckets. Gerrit breaks fundamental git semantics, so I have to
squash the 35 commits into one for the review.

I'll push this not with refs/for/master, but with refs/for/next so
that we can transition after submission in a controlled fashion.

For the review, I recommend to start with looking at godoc and in
particular the many examples. After that, continue with a line-by-line
detailed review. (The big picture is hopefully as expected after
wrapping up the discussion earlier.)

Change-Id: Ib38cc46493a5139ca29d84020650929d94cac850
2014-06-17 14:08:22 +02:00
Bjoern Rabenstein 3dfae09d30 Fix things commented on in past code review.
Change-Id: I4dafd098eefa99bc37fdbfebeb4c61a7251ad0be
2014-04-29 13:37:49 +02:00
Bjoern Rabenstein 84dc53148d Enable the Golang client library to create the new text formats.
Most important here is the simple & flat text format, but while I'm on
it, I have also added the text representations for protobufs (which is
purely meant for debugging purposes). I hope my basic idea about
handling those various protocols (and the text package) becomes
clearer now.

Change-Id: I7299853eadc82a426101e907f2b3d4e37f9e4c71
2014-04-25 21:45:04 +02:00
Bjoern Rabenstein 9da2fbcce3 Eliminate a number of style-guide violations.
Change-Id: Iedcd611e5c7ad24c84c004d8d6c551d1734e443c
2014-04-25 21:18:04 +02:00
Bjoern Rabenstein 00816363e4 Remove the one duplication of the Tester interface.
Change-Id: Ie17ec3393a7e12e0f27e51b4060aa478a172f612
2014-04-25 20:51:08 +02:00
Bjoern Rabenstein e5dc0421cd Move signature.go and related tests to the model package.
The LabelsToSignature function is now used outside of the prometheus
package, too. Leaving it in the prometheuos package is misleading
design and will lead to circulat import chains soon.

Change-Id: If1ca442d4023b33b138cf79fee68e82ff2a355be
2014-04-25 20:48:16 +02:00
Bjoern Rabenstein 46fc7a3748 Support the new protobuf fields.
- Full support for UNTYPED type.

- Receptive support for timestamp_ms (i.e. the processor can process
  it, but the client library cannot yet create it - which is kind of
  intended as timestamps are meant for other things like federation,
  which will need separate support anyway).

Change-Id: I5913164a80089943d49ad58bf86e465a843ab82b
2014-04-22 15:11:34 +02:00
Bjoern Rabenstein ecac33bed0 Conversion back and forth between MetricFamily protobuf and text format.
The idea here is to always go via the protobufs if dealing with the
text format. That won't always be the most efficient way, but it
avoids the multiplicity of conversion routines required for direct
conversion (e.g. text format -> internal representation in the
Prometheus server). The loss of efficiency is acceptable because the
text format should not be used in high performance (high throughput,
low latency) situations anyway.

In that way, the text format stays perfectly isolated from other parts
of the code. To receive text format, just plug the conversion in
before the code path that normally reads protobufs. Correspondingly,
for sending text format, simply replace the WriteDelimited call by a
text.Create call.

Nevertheless, the conversion code itself is optimized for efficiency
and minimized memory churn (which was one of the reason for handcoding
the parser and not using a lexer/parser code generation tool).

Change-Id: Iee45ffe8aa421a844225d13a1f859becd8a3b066
2014-04-17 16:28:13 +02:00
Matt T. Proud e782194166 Fix lock semantics on Summary#Reset.
This erroneously used the read lock as opposed to the write lock.

Change-Id: Ib127f8c117a516709eff9fd927603879501089b4
2014-04-15 01:49:28 +02:00
Matt T. Proud 7efd34a6f8 Optimize fingerprinting and metric locks.
These are all simple changes we should have caught a long time ago:

1. The hashing mechanism for fingerprint label sets should have not
   allocated new objects for the actual hashing---at least not
   egregiously.  This simplifies the hash writing by just byte-
   dumping the string stream into the hasher.

2. The hashing mechanism within the scope of a metric does not care
   about the value of the label keys themselves but only of the label
   values.  The keys can be dropped from the calculation.

3. The locking mechanism for the metrics should not block on hash
   computation but rather solely on the actual mutation or critical
   section reads.

4. For scalar metrics (i.e., ones with niladic label signatures), we
   should rely on a preallocated map versus requesting a new one
   ad hoc.

This is tested with Go 1.1, so the results may yield other values
for us elsewhere:

BEFORE
BenchmarkLabelValuesToSignatureScalar	500000000	         3.97 ns/op	       0 B/op	       0 allocs/op
BenchmarkLabelValuesToSignatureSingle	 5000000	       714 ns/op	      74 B/op	       4 allocs/op
BenchmarkLabelValuesToSignatureDouble	 1000000	      1153 ns/op	     107 B/op	       5 allocs/op
BenchmarkLabelValuesToSignatureTriple	 1000000	      1588 ns/op	     138 B/op	       6 allocs/op
BenchmarkLabelToSignatureScalar	500000000	         3.91 ns/op	       0 B/op	       0 allocs/op
BenchmarkLabelToSignatureSingle	 2000000	       874 ns/op	      92 B/op	       5 allocs/op
BenchmarkLabelToSignatureDouble	 1000000	      1528 ns/op	     139 B/op	       7 allocs/op
BenchmarkLabelToSignatureTriple	 1000000	      2172 ns/op	     186 B/op	       9 allocs/op

AFTER
BenchmarkLabelValuesToSignatureScalar	500000000	         4.36 ns/op	       0 B/op	       0 allocs/op
BenchmarkLabelValuesToSignatureSingle	 5000000	       378 ns/op	      89 B/op	       4 allocs/op
BenchmarkLabelValuesToSignatureDouble	 5000000	       574 ns/op	     142 B/op	       5 allocs/op
BenchmarkLabelValuesToSignatureTriple	 5000000	       758 ns/op	     186 B/op	       6 allocs/op
BenchmarkLabelToSignatureScalar	500000000	         4.06 ns/op	       0 B/op	       0 allocs/op
BenchmarkLabelToSignatureSingle	 5000000	       472 ns/op	     106 B/op	       5 allocs/op
BenchmarkLabelToSignatureDouble	 2000000	       746 ns/op	     174 B/op	       7 allocs/op
BenchmarkLabelToSignatureTriple	 1000000	      1061 ns/op	     235 B/op	       9 allocs/op

In effect, a single metric mutation operation's lookup overhead will
move from Before::iBenchmarkLabelToSignature to
After::BenchmarkLabelValuesToSignature.  This MINIMALLY reduces
1/2 the overhead.  I would be hesitant in reading the memory
allocation statistics, for this was run with the GC still on and
thusly inaccurate per Go benchmarking documentation.

Before::BenchmarkLabelValuesToSignature never existed, so it is not
of any intrinsic value in itself.  That said, the cases that still
rely on LabelToSignature experience consistently a 1/2 drop in time.

Change-Id: Ifc9e69f718af65a59f5be8117473518233258159
2014-04-14 19:06:09 +02:00
Bjoern Rabenstein b83e1b7cad Remove redundant __name__ label from protobuf output.
Change-Id: I72d5dbccb0325d6edf7abe5bca88dc5a6001029c
2014-04-03 15:18:12 +02:00
Bjoern Rabenstein ee34486fa1 Add a low-level MetricFamily injection hook.
This hook is needed for the upcoming push gateway.

Also remove go vet warnings and add test for Handler().

Change-Id: If6c56676c7a0f10c16b4effae7285903f8267616
2014-04-02 19:41:44 +02:00
Julius Volz bb957bc145 Change internal metric name label to __name__.
This also adds a check that forbids any user-supplied metrics to start
with the reserved label name prefix "__".

Change-Id: I2fe94c740b685ad05c4c670613cf2af7b9e1c1c0
2014-03-14 12:28:25 +01:00
Bernerd Schaefer 29ebb580db Add Reset(map[string]string) to Metric interface
Change-Id: I289cf8796adbd6ff55f23bba7730145329de00e1
2014-02-19 15:18:16 +01:00
Bernerd Schaefer ad41ea8439 Merge "Cache signature of an empty label set" 2013-09-16 12:56:13 +02:00
Bernerd Schaefer 26ad852c94 Cache signature of an empty label set
This is an optimization of labelsToSignature to avoid excess allocations
when the label set is empty.

Change-Id: If2d59bbc3ae6d4457e2ded197b6f4e7c67e6a173
2013-09-11 17:41:07 +02:00
Bernerd Schaefer a9b3602cea Register copies the provided baseLabels
This ensures that you can pass the same base label set into multiple
Register() calls, e.g.:

    labels := map[string]string{"key": "value"}
    prometheus.Register("metric_1", "", labels, ...)
    prometheus.Register("metric_2", "", labels, ...)

Change-Id: I951e5c2ed7844c74eb3716d1bf07126ce558f266
2013-09-11 17:38:00 +02:00
Matt T. Proud 93130ba5c3 Introduce histogram purging support. 2013-07-21 17:45:57 +02:00
Matt T. Proud a10d055c32 Include sample count and sum in Proto output. 2013-07-21 17:45:57 +02:00
Matt T. Proud 624e57d292 Enclose artifact generation process into Makefile.
Completely decouple the build process from Travis and other things we
cannot control.
2013-07-21 17:45:53 +02:00
Matt T. Proud 4956aea5ac Protocol Buffer negotiation support in handler. 2013-07-01 17:14:58 +02:00
Matt T. Proud 10dae5d108 Include relevant server model artifacts.
This commit introduces all relevant server-side artifacts such that the
Result streams can be used by external parties for one-off tools and
such.  This will ultimately better enable us to support additional
wireformats with much more ease.
2013-06-11 11:45:21 +02:00
Matt T. Proud 85899b3f4a Extract core Prometheus value decoders.
Bernerd had suggested extracting the value decoders and bundling them
into the client library.  After some reflection, I tend to agree with
this, since we can start breaking the onion of Prometheus itself and
localize the protocol management into its own scope.

A couple of major changes since moving:

- Protocol 0.0.2 has moved to a struct{} so that our tests can perform
  value matching, which cannot be done against function literals.

- Processing now acquires options to dictate behavioral changes of
  metrics bodies.

- Processing no longer closes the stream, thusly returning this to the
  hands of the caller.

- Process() has been renamed to ProcessSingle to better convey that it
  works on complete message bodies.  This paves the way for better
  streaming payload support that the next API version will offer.
2013-06-10 19:35:41 +02:00
Bernerd Schaefer af56a93a80 Rename test helper files to helpers_test.go
This ensures that these files are properly included only in testing.

[Fixes #10]
2013-05-06 11:13:44 +02:00
Bernerd Schaefer d4ff2cc87a Fix race conditions in metric methods
Methods which expect to use a mutex must be defined for the pointer
value, because mutexes are not copyable.
2013-05-03 16:02:03 +02:00
Bernerd Schaefer f60c783b29 Adhere to telemetry schema 0.0.2
* The schema and version of telemetry data is exposed through the
  Content-Type header instead of through a custom HTTP Header.

See [Prometheus Client Data Exposition Format][1] for more details.

[1]: https://docs.google.com/a/soundcloud.com/document/d/1ZjyKiKxZV83VI9ZKAXRGKaUKK2BIWCT7oiGBKDBpjEY/edit#heading=h.wnviarbnyxcj
2013-04-25 17:43:03 +02:00
Bernerd Schaefer 71dd60e431 Registry and Metrics implement json.Marshaler
* Drop `AsMarshallable()` from the Metric interface. Use
  `json.Marshaler` and `MarshalJSON()`, and leverage JSON struct tags
  where possible.

* Add `MarshalJSON()` to Registry and remove `dumpToWriter`, which
  makes the registry handler much simpler.

In addition to simplifying some of the marshalling behavior, this also
has the nice side effect of cutting down the number of
`map[string]interface{}` instances.
2013-04-19 15:07:24 +02:00
Bernerd Schaefer 3433b798b3 Use raw string literals in tests 2013-04-19 15:04:07 +02:00
Bernerd Schaefer 0b30e065c8 Metrics explicitly implement Metric interface 2013-04-19 15:04:07 +02:00
Bernerd Schaefer 9fccb96989 Remove timer.go and timer_test.go 2013-04-19 14:44:15 +02:00
Matt T. Proud f320d28a6c Rearrange file and package per convention.
WIP - Please review but do not merge.
2013-04-04 15:27:09 +02:00