Commit Graph

280 Commits

Author SHA1 Message Date
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