mirror of
https://github.com/mainflux/mainflux.git
synced 2025-05-01 13:48:56 +08:00

* Use normalizer as stream source Renamed 'writer' service to 'normalizer' and dropped Cassandra facilities from it. Extracted the common dependencies to 'mainflux' package for easier sharing. Fixed the API docs and unified environment variables. Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Use docker build arguments to specify build Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Remove cassandra libraries Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Update go-kit version to 0.6.0 Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Fix manager configuration Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Refactor docker-compose Merged individual compose files and dropped external links. Remove CoAP container since it is not referenced from NginX config at the moment. Update port mapping in compose and nginx.conf. Dropped bin scripts. Updated service documentation. Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Drop content-type check Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Implement users data access layer in PostgreSQL Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Bump version to 0.1.0 Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Use go-kit logger everywhere (except CoAP) Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Improve factory methods naming Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Implement clients data access layer on PostgreSQL Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Make tests stateless All tests are refactored to use map-based table-driven tests. No cross-tests dependencies is present anymore. Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Remove gitignore Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Fix nginx proxying Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Mark client-user FK explicit Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Update API documentation Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Update channel model Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Add channel PostgreSQL repository tests Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Implement PostgreSQL channels DAO Replaced update queries with raw SQL. Explicitly defined M2M table due to difficulties of ensuring the referential integrity through GORM. Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Expose connection endpoints Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Fix swagger docs and remove DB logging Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Fix nested query remarks Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Add unique indices Signed-off-by: Dejan Mijic <dejan@mainflux.com>
98 lines
4.6 KiB
Go
98 lines
4.6 KiB
Go
// Package metrics provides a framework for application instrumentation. It's
|
|
// primarily designed to help you get started with good and robust
|
|
// instrumentation, and to help you migrate from a less-capable system like
|
|
// Graphite to a more-capable system like Prometheus. If your organization has
|
|
// already standardized on an instrumentation system like Prometheus, and has no
|
|
// plans to change, it may make sense to use that system's instrumentation
|
|
// library directly.
|
|
//
|
|
// This package provides three core metric abstractions (Counter, Gauge, and
|
|
// Histogram) and implementations for almost all common instrumentation
|
|
// backends. Each metric has an observation method (Add, Set, or Observe,
|
|
// respectively) used to record values, and a With method to "scope" the
|
|
// observation by various parameters. For example, you might have a Histogram to
|
|
// record request durations, parameterized by the method that's being called.
|
|
//
|
|
// var requestDuration metrics.Histogram
|
|
// // ...
|
|
// requestDuration.With("method", "MyMethod").Observe(time.Since(begin))
|
|
//
|
|
// This allows a single high-level metrics object (requestDuration) to work with
|
|
// many code paths somewhat dynamically. The concept of With is fully supported
|
|
// in some backends like Prometheus, and not supported in other backends like
|
|
// Graphite. So, With may be a no-op, depending on the concrete implementation
|
|
// you choose. Please check the implementation to know for sure. For
|
|
// implementations that don't provide With, it's necessary to fully parameterize
|
|
// each metric in the metric name, e.g.
|
|
//
|
|
// // Statsd
|
|
// c := statsd.NewCounter("request_duration_MyMethod_200")
|
|
// c.Add(1)
|
|
//
|
|
// // Prometheus
|
|
// c := prometheus.NewCounter(stdprometheus.CounterOpts{
|
|
// Name: "request_duration",
|
|
// ...
|
|
// }, []string{"method", "status_code"})
|
|
// c.With("method", "MyMethod", "status_code", strconv.Itoa(code)).Add(1)
|
|
//
|
|
// Usage
|
|
//
|
|
// Metrics are dependencies, and should be passed to the components that need
|
|
// them in the same way you'd construct and pass a database handle, or reference
|
|
// to another component. Metrics should *not* be created in the global scope.
|
|
// Instead, instantiate metrics in your func main, using whichever concrete
|
|
// implementation is appropriate for your organization.
|
|
//
|
|
// latency := prometheus.NewSummaryFrom(stdprometheus.SummaryOpts{
|
|
// Namespace: "myteam",
|
|
// Subsystem: "foosvc",
|
|
// Name: "request_latency_seconds",
|
|
// Help: "Incoming request latency in seconds.",
|
|
// }, []string{"method", "status_code"})
|
|
//
|
|
// Write your components to take the metrics they will use as parameters to
|
|
// their constructors. Use the interface types, not the concrete types. That is,
|
|
//
|
|
// // NewAPI takes metrics.Histogram, not *prometheus.Summary
|
|
// func NewAPI(s Store, logger log.Logger, latency metrics.Histogram) *API {
|
|
// // ...
|
|
// }
|
|
//
|
|
// func (a *API) ServeFoo(w http.ResponseWriter, r *http.Request) {
|
|
// begin := time.Now()
|
|
// // ...
|
|
// a.latency.Observe(time.Since(begin).Seconds())
|
|
// }
|
|
//
|
|
// Finally, pass the metrics as dependencies when building your object graph.
|
|
// This should happen in func main, not in the global scope.
|
|
//
|
|
// api := NewAPI(store, logger, latency)
|
|
// http.ListenAndServe("/", api)
|
|
//
|
|
// Note that metrics are "write-only" interfaces.
|
|
//
|
|
// Implementation details
|
|
//
|
|
// All metrics are safe for concurrent use. Considerable design influence has
|
|
// been taken from https://github.com/codahale/metrics and
|
|
// https://prometheus.io.
|
|
//
|
|
// Each telemetry system has different semantics for label values, push vs.
|
|
// pull, support for histograms, etc. These properties influence the design of
|
|
// their respective packages. This table attempts to summarize the key points of
|
|
// distinction.
|
|
//
|
|
// SYSTEM DIM COUNTERS GAUGES HISTOGRAMS
|
|
// dogstatsd n batch, push-aggregate batch, push-aggregate native, batch, push-each
|
|
// statsd 1 batch, push-aggregate batch, push-aggregate native, batch, push-each
|
|
// graphite 1 batch, push-aggregate batch, push-aggregate synthetic, batch, push-aggregate
|
|
// expvar 1 atomic atomic synthetic, batch, in-place expose
|
|
// influx n custom custom custom
|
|
// prometheus n native native native
|
|
// pcp 1 native native native
|
|
// cloudwatch n batch push-aggregate batch push-aggregate synthetic, batch, push-aggregate
|
|
//
|
|
package metrics
|