Exemple #1
0
func ExampleHistogram() {
	temps := prometheus.NewHistogram(prometheus.HistogramOpts{
		Name:    "pond_temperature_celsius",
		Help:    "The temperature of the frog pond.", // Sorry, we can't measure how badly it smells.
		Buckets: prometheus.LinearBuckets(20, 5, 5),  // 5 buckets, each 5 centigrade wide.
	})

	// Simulate some observations.
	for i := 0; i < 1000; i++ {
		temps.Observe(30 + math.Floor(120*math.Sin(float64(i)*0.1))/10)
	}

	// Just for demonstration, let's check the state of the histogram by
	// (ab)using its Write method (which is usually only used by Prometheus
	// internally).
	metric := &dto.Metric{}
	temps.Write(metric)
	fmt.Println(proto.MarshalTextString(metric))

	// Output:
	// histogram: <
	//   sample_count: 1000
	//   sample_sum: 29969.50000000001
	//   bucket: <
	//     cumulative_count: 192
	//     upper_bound: 20
	//   >
	//   bucket: <
	//     cumulative_count: 366
	//     upper_bound: 25
	//   >
	//   bucket: <
	//     cumulative_count: 501
	//     upper_bound: 30
	//   >
	//   bucket: <
	//     cumulative_count: 638
	//     upper_bound: 35
	//   >
	//   bucket: <
	//     cumulative_count: 816
	//     upper_bound: 40
	//   >
	// >
}
Exemple #2
0
func main() {

	router := routers.NewRouter()
	var port string
	fmt.Printf("len(os.Args) = %d ", len(os.Args))

	if len(os.Args) <= 1 {
		fmt.Println("Please speficy the port or use default port 8090")
		port = "8090"
	} else {
		port = os.Args[1]
	}
	fmt.Printf("port = %s", port)

	// histogram
	temps := prometheus.NewHistogram(prometheus.HistogramOpts{
		Name:    "pond_temperature_celsius",
		Help:    "The temperature of the frog pond.", // Sorry, we can't measure how badly it smells.
		Buckets: prometheus.LinearBuckets(20, 5, 5),  // 5 buckets, each 5 centigrade wide.
	})

	// Simulate some observations.
	for i := 0; i < 1000; i++ {
		temps.Observe(30 + math.Floor(120*math.Sin(float64(i)*0.1))/10)
	}

	// Just for demonstration, let's check the state of the histogram by
	// (ab)using its Write method (which is usually only used by Prometheus
	// internally).
	metric := &dto.Metric{}
	temps.Write(metric)
	fmt.Println(proto.MarshalTextString(metric))

	router.Handle("/metrics", prometheus.Handler())

	//log.Fatal(http.ListenAndServe(":8090", router))
	log.Fatal(http.ListenAndServe(":"+port, router))

}
Exemple #3
0
// limitations under the License.

package tidb

import (
	"github.com/prometheus/client_golang/prometheus"
)

var (
	sessionExecuteParseDuration = prometheus.NewHistogram(
		prometheus.HistogramOpts{
			Namespace: "tidb",
			Subsystem: "server",
			Name:      "session_execute_parse_duration",
			Help:      "Bucketed histogram of processing time (s) in parse SQL.",
			Buckets:   prometheus.LinearBuckets(0.00004, 0.00001, 13),
		})
	sessionExecuteCompileDuration = prometheus.NewHistogram(
		prometheus.HistogramOpts{
			Namespace: "tidb",
			Subsystem: "server",
			Name:      "session_execute_compile_duration",
			Help:      "Bucketed histogram of processing time (s) in query optimize.",
			Buckets:   prometheus.LinearBuckets(0.00004, 0.00001, 13),
		})
	sessionExecuteRunDuration = prometheus.NewHistogram(
		prometheus.HistogramOpts{
			Namespace: "tidb",
			Subsystem: "server",
			Name:      "session_execute_run_duration",
			Help:      "Bucketed histogram of processing time (s) in running executor.",
Exemple #4
0
// initMetrics initialises a new metrics instance.
// This is deliberately not exposed but is useful for testing.
func initMetrics(url string, frequency, timeout time.Duration, customLabels map[string]string) *metrics {
	u, err := user.Current()
	if err != nil {
		log.Warning("Can't determine current user name for metrics")
		u = &user.User{Username: "******"}
	}
	constLabels := prometheus.Labels{
		"user": u.Username,
		"arch": runtime.GOOS + "_" + runtime.GOARCH,
	}
	for k, v := range customLabels {
		constLabels[k] = deriveLabelValue(v)
	}

	m = &metrics{
		url:      url,
		stopChan: make(chan bool),
		timeout:  timeout,
	}

	// Count of builds for each target.
	m.buildCounter = prometheus.NewCounterVec(prometheus.CounterOpts{
		Name:        "build_counts",
		Help:        "Count of number of times each target is built",
		ConstLabels: constLabels,
	}, []string{"success", "incremental"})

	// Count of cache hits for each target
	m.cacheCounter = prometheus.NewCounterVec(prometheus.CounterOpts{
		Name:        "cache_hits",
		Help:        "Count of number of times we successfully retrieve from the cache",
		ConstLabels: constLabels,
	}, []string{"hit"})

	// Count of test runs for each target
	m.testCounter = prometheus.NewCounterVec(prometheus.CounterOpts{
		Name:        "test_runs",
		Help:        "Count of number of times we run each test",
		ConstLabels: constLabels,
	}, []string{"pass"})

	// Build durations for each target
	m.buildHistogram = prometheus.NewHistogramVec(prometheus.HistogramOpts{
		Name:        "build_durations_histogram",
		Help:        "Durations of individual build targets",
		Buckets:     prometheus.LinearBuckets(0, 0.1, 100),
		ConstLabels: constLabels,
	}, []string{})

	// Cache retrieval durations for each target
	m.cacheHistogram = prometheus.NewHistogramVec(prometheus.HistogramOpts{
		Name:        "cache_durations_histogram",
		Help:        "Durations to retrieve artifacts from the cache",
		Buckets:     prometheus.LinearBuckets(0, 0.1, 100),
		ConstLabels: constLabels,
	}, []string{})

	// Test durations for each target
	m.testHistogram = prometheus.NewHistogramVec(prometheus.HistogramOpts{
		Name:        "test_durations_histogram",
		Help:        "Durations to run tests",
		Buckets:     prometheus.LinearBuckets(0, 1, 100),
		ConstLabels: constLabels,
	}, []string{})

	go m.keepPushing(frequency)

	return m
}
Exemple #5
0
		Name:      "unique_lurking_agents",
		Subsystem: "presence",
		Help:      "Number of unique, lurking agents in the presence table.",
	})

	uniqueWebAgentCount = prometheus.NewGauge(prometheus.GaugeOpts{
		Name:      "unique_web_agents",
		Subsystem: "presence",
		Help:      "Number of unique agents using the web client in the presence table.",
	})

	sessionsPerAgent = prometheus.NewHistogram(prometheus.HistogramOpts{
		Name:      "sessions_per_agent",
		Subsystem: "presence",
		Help:      "Number of simultaneous live sessions for each active agent.",
		Buckets:   prometheus.LinearBuckets(0, 1, 10),
	})
)

func init() {
	prometheus.MustRegister(rowCount)
	prometheus.MustRegister(activeRowCount)
	prometheus.MustRegister(activeRowCountPerRoom)
	prometheus.MustRegister(lurkingRowCount)
	prometheus.MustRegister(lurkingRowCountPerRoom)
	prometheus.MustRegister(uniqueAgentCount)
	prometheus.MustRegister(uniqueLurkingAgentCount)
	prometheus.MustRegister(uniqueWebAgentCount)
	prometheus.MustRegister(sessionsPerAgent)
}
		[]string{"service_name", "status_code", "client_ip"},
	)

	serviceMaxUseTime = prometheus.NewCounterVec(
		prometheus.CounterOpts{
			Name: "service_max_use_time",
			Help: "service max use time",
		},
		[]string{"service_name", "status_code", "client_ip"},
	)

	serviceUseTimeDistributions = prometheus.NewHistogramVec(
		prometheus.HistogramOpts{
			Name:    "service_use_time_distributions",
			Help:    "service use time distributions",
			Buckets: prometheus.LinearBuckets(0, 100000, 11),
		},
		[]string{"service_name", "status_code"},
	)

	serviceAnalyseResults = make(map[string]*data.AnalyseResult)
)

func init() {
	prometheus.MustRegister(serviceReqCountCollector)
	prometheus.MustRegister(serviceReqAvgUseTime)
	prometheus.MustRegister(serviceMaxUseTime)
	prometheus.MustRegister(serviceUseTimeDistributions)
}

func resetCollector() {
Exemple #7
0
	rpcDurations = prometheus.NewSummaryVec(
		prometheus.SummaryOpts{
			Name:       "rpc_durations_seconds",
			Help:       "RPC latency distributions.",
			Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
		},
		[]string{"service"},
	)
	// The same as above, but now as a histogram, and only for the normal
	// distribution. The buckets are targeted to the parameters of the
	// normal distribution, with 20 buckets centered on the mean, each
	// half-sigma wide.
	rpcDurationsHistogram = prometheus.NewHistogram(prometheus.HistogramOpts{
		Name:    "rpc_durations_histogram_seconds",
		Help:    "RPC latency distributions.",
		Buckets: prometheus.LinearBuckets(*normMean-5**normDomain, .5**normDomain, 20),
	})
)

func init() {
	// Register the summary and the histogram with Prometheus's default registry.
	prometheus.MustRegister(rpcDurations)
	prometheus.MustRegister(rpcDurationsHistogram)
}

func main() {
	flag.Parse()

	start := time.Now()

	oscillationFactor := func() float64 {
// See the License for the specific language governing permissions and
// limitations under the License.

package prometheus_test

import (
	"math/rand"
	"time"

	"github.com/prometheus/client_golang/prometheus"
)

var (
	requestDuration = prometheus.NewHistogram(prometheus.HistogramOpts{
		Name:    "example_request_duration_seconds",
		Help:    "Histogram for the runtime of a simple example function.",
		Buckets: prometheus.LinearBuckets(0.01, 0.01, 10),
	})
)

func ExampleTimer() {
	// timer times this example function. It uses a Histogram, but a Summary
	// would also work, as both implement Observer. Check out
	// https://prometheus.io/docs/practices/histograms/ for differences.
	timer := prometheus.NewTimer(requestDuration)
	defer timer.ObserveDuration()

	// Do something here that takes time.
	time.Sleep(time.Duration(rand.NormFloat64()*10000+50000) * time.Microsecond)
}