In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly talks about "what are the data types of java prometheus". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what are the data types of java prometheus"?
I. brief introduction
Prometheus saves all the collected sample data in the in-memory database in the form of time series (time-series), and saves it on the hard disk regularly. Each sample in the time series consists of the following three parts.
Indicator (metric): composed of metric name and labelsets describing the characteristics of the current sample, reference format such as {=,...};, where the naming rule of metric name is: apply the beginning of the name _ monitoring object _ numerical type _ unit
Timestamp: a time cut accurate to milliseconds
Sample value (value): the floating-point type data of an float64 represents the current sample value.
II. Four data types of Prometheus
2.1 Counter (counter type)
Metrics of type Counter work in the same way as counters, increasing rather than decreasing (unless the system is reset). Counter is generally used to accumulate values, such as recording the number of requests, tasks completed, and errors. There are two main methods for counter:
/ / add the counter value to 1.Inc () / / add the specified value to the countervalue, if you specify the value
< 0会panic.Add(float64) 在Prometheus自定义的metrics监控中,Counter的使用可以参考如下: public class PrometheusMetricsInterceptor extends HandlerInterceptorAdapter { static final Counter requestCounter = Counter.build() .name("io_namespace_http_requests_total").labelNames("path", "method", "code") //metric name建议使用_total结尾 .help("Total requests.").register(); @Override public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { String requestURI = request.getRequestURI(); String method = request.getMethod(); int status = response.getStatus(); requestCounter.labels(requestURI, method, String.valueOf(status)).inc(); //调用inc()函数,每次请求发生时计数+1 super.afterCompletion(request, response, handler, ex); }} Counter类型数据可以让用户方便的了解事件产生的速率的变化,在PromQL内置的相关操作函数可以提供相应的分析,比如以HTTP应用请求量来进行说明: //通过rate()函数获取HTTP请求量的增长率rate(http_requests_total[5m])//查询当前系统中,访问量前10的HTTP地址topk(10, http_requests_total) 1 2 3 4 2.2 Gauge(仪表盘类型) Gauge是可增可减的指标类,可以用于反应当前应用的状态。比如在监控主机时,主机当前的内容大小(node_memory_MemFree),可用内存大小(node_memory_MemAvailable)。或者时容器当前的cpu使用率,内存使用率。 Gauge指标对象主要包含两个方法inc()以及dec(),用户添加或者减少计数。 在Prometheus自定义的metrics监控中,Gauge的使用可以参考如下: public class PrometheusMetricsInterceptor extends HandlerInterceptorAdapter {...省略的代码static final Gauge inprogressRequests = Gauge.build() .name("io_namespace_http_inprogress_requests").labelNames("path", "method", "code") .help("Inprogress requests.").register();@Overridepublic boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { ...省略的代码 inprogressRequests.labels(requestURI, method, String.valueOf(status)).inc();// 计数器+1 return super.preHandle(request, response, handler);}@Overridepublic void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { ...省略的代码 inprogressRequests.labels(requestURI, method, String.valueOf(status)).dec();// 计数器-1 super.afterCompletion(request, response, handler, ex);}} 对于Gauge类型的监控指标,通过PromQL内置函数delta()可以获取样本在一段时间内的变化情况,比如: dalta(cpu_temp_celsius{host="zeus"}[2h]) //计算CPU温度在两小时内的差异predict_linear(node_filesystem_free{job="node"}[1h], 4*3600) //预测系统磁盘空间在4小时之后的剩余情况 2.3 Histogram(直方图类型) Histogram 由 < basename>_ bucket {le= "
< upper inclusive bound>"}
< basename>_ bucket {le= "+ Inf"}
< basename>Composed of _ sum,_count, it is mainly used to sample data within a period of time (usually request duration or response size), and can count its specified interval and total. Usually, the data it collects is shown as a histogram.
In the metrics monitoring customized by Prometheus, the use of Histgram can be referred to as follows:
Take the request response time requests_latency_seconds as an example, for example, when we need to record the number of times that the http request response time corresponds to the number of times in the distribution range {0.005meme 0.01rec 0.025je 0.05rep 0.075je 0.25g 0.5g 0.5ml 0.75 g / m 0.5min 0.75}
Public class PrometheusMetricsInterceptor extends HandlerInterceptorAdapter {static final Histogram requestLatencyHistogram = Histogram.build (). LabelNames ("path", "method", "code") .name ("io_namespace_http_requests_latency_seconds_histogram"). Help ("Request latency in seconds.") .register (); private Histogram.Timer histogramRequestTimer; @ Override public boolean preHandle (HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {. The omitted code histogramRequestTimer = requestLatencyHistogram.labels (requestURI, method, String.valueOf (status)). StartTimer ();. The omitted code} @ Override public void afterCompletion (HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {... The omitted code histogramRequestTimer.observeDuration ();... Omitted code}
one
two
three
four
When using Histogram constructor to create Histogram monitoring metrics, the default buckets range is {0.005MagneO1re0.025reparated0.075LetWord (double) .50.5were0.5were0.5were1were2.5were7.5for10}. If you want to modify the default buckets, you can use .buckets (double … Bukets) overwrite.
Histogram automatically creates three metrics, which are:
The total number of events that occurred, basename_count.
# actual meaning: currently, there are 2 http requests io_namespace_http_requests_latency_seconds_histogram_count {path= "/", method= "GET", code= "200",} 2.0
The sum of the values generated by all events, basename_sum.
# practical meaning: the total response time of the two http requests that occurred is 13.10767080300001 seconds io_namespace_http_requests_latency_seconds_histogram_sum {path= "/", method= "GET", code= "200",} 13.107670803000001
one
two
The number of times the value generated by the event is distributed in bucket, basename_bucket {le= "contains"}
2.4 Summary (summary type)
The Summary type is similar to the Histogram type, which is determined by the
< basename>{quantile= "
< φ>"}
< basename>_ sum
< basename>Composed of _ count, which is mainly used to represent the results of data sampling over a period of time (usually request duration or response size). It stores quantile data directly rather than calculated based on statistical intervals. Compared with Histogram, Summary has the following differences:
All contain
< basename>_ sum and
< basename>_ count
Histogram needs to pass through
< basename>_ bucket calculates quantile, while Summary stores the value of quantile directly.
In the metrics monitoring customized by Prometheus, the use of Summary can be referred to as follows:
Public class PrometheusMetricsInterceptor extends HandlerInterceptorAdapter {static final Summary requestLatency = Summary.build () .name ("io_namespace_http_requests_latency_seconds_summary") .Quan tile (0.5,0.05) .quantile (0.9,0.01) .labelNames ("path", "method", "code") .help ("Request latency in seconds.") .register () Override public boolean preHandle (HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {... The omitted code requestTimer = requestLatency.labels (requestURI, method, String.valueOf (status)). StartTimer ();. The omitted code} @ Override public void afterCompletion (HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {... The omitted code requestTimer.observeDuration ();... Omitted code}}
The data contained in the Summary type metric is as follows:
The total number of events that occurred
# meaning: the total number of current http requests is 12 io_namespace_http_requests_latency_seconds_summary_count {path= "/", method= "GET", code= "200",} 12.0
The sum of the values generated by the event
# meaning: the total response time of these 12 http requests is 51.029495508sio_namespace_http_requests_latency_seconds_summary_sum {path= "/", method= "GET", code= "200",} 51.029495508
one
two
The distribution of values generated by the event
# meaning: the median response time of these 12 http requests is 3.052404983sio_namespace_http_requests_latency_seconds_summary {path= "/", method= "GET", code= "200", quantile=" 0.5 ",} 3.05240498": the quartile of response time of these 12 http requests is 8.003261666sio_namespace_http_requests_latency_seconds_summary {path= "/", method= "GET", code= "200", quantile=" 0.9 ",} 8.003261666 to this point. I believe that you have a deeper understanding of "what are the data types of java prometheus?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.