Skip to content

Commit 1d75a2d

Browse files
committed
Add initial Hugo docs to be published on Github pages
Signed-off-by: Fabian Stäber <[email protected]>
1 parent f1cc00a commit 1d75a2d

File tree

255 files changed

+3538
-11
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

255 files changed

+3538
-11
lines changed

docs/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.hugo_build.lock

docs/README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Docs
2+
----
3+
4+
This directory contains [hugo](https://gohugo.io) documentation to be published in Github pages.
5+
6+
Run Locally
7+
-----------
8+
9+
```
10+
hugo server -D
11+
```
12+
13+
This will serve the docs on [http://localhost:1313](http://localhost:1313).
14+
15+
Deploy to Github Pages
16+
----------------------
17+
18+
Changes to the `main` branch will be deployed automatically with Github actions.
19+
20+
Set-up Notes
21+
------------
22+
23+
Here's how the initial `docs/` folder was set up:
24+
25+
```
26+
hugo new site docs
27+
cd docs/
28+
mkdir -p themes/hugo-geekdoc/
29+
curl -L https://github.com/thegeeklab/hugo-geekdoc/releases/download/v0.41.1/hugo-geekdoc.tar.gz | tar -xz -C themes/hugo-geekdoc/ --strip-components=1
30+
```
31+
32+
Create the initial `hugo.toml` file as described in [https://geekdocs.de/usage/getting-started/](https://geekdocs.de/usage/getting-started/).
33+
34+
Update Geekdocs
35+
---------------
36+
37+
The docs use the [Geekdocs](https://geekdocs.de/) theme. The theme is checked in to Github in the `./docs/themes/hugo-geekdoc/` folder. To update [Geekdocs](https://geekdocs.de/), remove the current folder and create a new one with the latest [release](https://github.com/thegeeklab/hugo-geekdoc/releases). There are no local modifications in `./docs/themes/hugo-geekdoc/`.

docs/archetypes/default.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
+++
2+
title = '{{ replace .File.ContentBaseName "-" " " | title }}'
3+
date = {{ .Date }}
4+
draft = true
5+
+++

docs/content/_index.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: "client_java"
3+
---
4+
5+
Brainstorming of potential topics:
6+
7+
* Getting started
8+
* Quickstart
9+
* Metrics Types
10+
* Callbacks
11+
* Native Histograms
12+
* Naming conventions (unit, total, dots)
13+
* Exposition Formats
14+
* How to use the API for high performance applications
15+
* Exporters
16+
* HTTPServer
17+
* Servlet
18+
* Pushgateway
19+
* OpenTelemetry
20+
* Instrumentations
21+
* JVM metrics
22+
* Servlet filter
23+
* OpenTelemetry
24+
* OpenTelemetry exporter
25+
* Combining Prometheus `client_java` with the OpenTelemetry instrumentation agent.
26+
* Trace sampling and Exemplars
27+
* API comparision: OpenTelemetry vs Prometheus
28+
* Performance comparison: OpenTelemetry vs Prometheus
29+
* Examples
30+
* todo: examples directory
31+
* Spring Boot Actuator / Micrometer
32+
* Runtime Configuration
33+
* Backwards Compatibility with Simpleclient
34+
* Requirements (Java 8)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
title: Getting Started
3+
weight: 1
4+
---
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
title: Callbacks
3+
weight: 5
4+
---
5+
6+
The section on [metric types](../metric-types) showed how to use metrics that actively maintain their state.
7+
8+
This section shows how to create callback-based metrics, i.e. metrics that invoke a callback at scrape time to get the current values.
9+
10+
For example, let's assume we have two instances of a `Cache`, a `coldCache` and a `hotCache`. The following implements a callback-based `cache_size_bytes` metric:
11+
12+
```java
13+
Cache coldCache = new Cache();
14+
Cache hotCache = new Cache();
15+
16+
GaugeWithCallback.builder()
17+
.name("cache_size_bytes")
18+
.help("Size of the cache in Bytes.")
19+
.unit(Unit.BYTES)
20+
.labelNames("state")
21+
.callback(callback -> {
22+
callback.call(coldCache.sizeInBytes(), "cold");
23+
callback.call(hotCache.sizeInBytes(), "hot");
24+
})
25+
.register();
26+
```
27+
28+
The resulting text format looks like this:
29+
30+
```
31+
# TYPE cache_size_bytes gauge
32+
# UNIT cache_size_bytes bytes
33+
# HELP cache_size_bytes Size of the cache in Bytes.
34+
cache_size_bytes{state="cold"} 78.0
35+
cache_size_bytes{state="hot"} 83.0
36+
```
37+
38+
Better examples of callback metrics can be found in the `prometheus-metrics-instrumentation-jvm` module.
39+
40+
The available callback metric types are:
41+
42+
* `GaugeWithCallback` for gauges.
43+
* `CounterWithCallback` for counters.
44+
* `SummaryWithCallback` for summaries.
45+
46+
The API for gauges and counters is very similar. For summaries the callback has a few more parameters, because it accepts a count, a sum, and quantiles:
47+
48+
```java
49+
SummaryWithCallback.builder()
50+
.name("example_callback_summary")
51+
.help("help message.")
52+
.labelNames("status")
53+
.callback(callback -> {
54+
callback.call(cache.getCount(), cache.getSum(), Quantiles.EMPTY, "ok");
55+
})
56+
.register();
57+
```
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
---
2+
title: Labels
3+
weight: 3
4+
---
5+
6+
The following shows an example of a Prometheus metric in text format:
7+
8+
```
9+
# HELP payments_total total number of payments
10+
# TYPE payments_total counter
11+
payments_total{status="error",type="paypal"} 1.0
12+
payments_total{status="success",type="credit card"} 3.0
13+
payments_total{status="success",type="paypal"} 2.0
14+
```
15+
16+
The example shows a counter metric named `payments_total` with two labels: `status` and `type`. Each individual data point (each line in text format) is identified by the unique combination of its metric name and its label name/value pairs.
17+
18+
Creating a Metric with Labels
19+
-----------------------------
20+
21+
Labels are supported for all metric types. We are using counters in this example, however the `labelNames()` and `labelValues()` methods are the same for other metric types.
22+
23+
The following code creates the counter above.
24+
25+
```java
26+
Counter counter = Counter.builder()
27+
.name("payments_total")
28+
.help("total number of payments")
29+
.labelNames("type", "status")
30+
.register();
31+
32+
counter.labelValues("credit card", "success").inc(3.0);
33+
counter.labelValues("paypal", "success").inc(2.0);
34+
counter.labelValues("paypal", "error").inc(1.0);
35+
```
36+
37+
The label names have to be specified when the metric is created and cannot change. The label values are created on demand when values are observed.
38+
39+
Creating a Metric without Labels
40+
--------------------------------
41+
42+
Labels are optional. The following example shows a metric without labels:
43+
44+
```java
45+
Counter counter = Counter.builder()
46+
.name("payments_total")
47+
.help("total number of payments")
48+
.register();
49+
50+
counter.inc(3.0);
51+
```
52+
53+
Cardinality Explosion
54+
---------------------
55+
56+
Each combination of label names and values will result in a new data point, i.e. a new line in text format.
57+
Therefore, a good label should have only a small number of possible values.
58+
If you select labels with many possible values, like unique IDs or timestamps, you may end up with an enormous number of data points.
59+
This is called cardinality explosion.
60+
61+
Here's a bad example, don't do this:
62+
63+
```java
64+
Counter loginCount = Counter.builder()
65+
.name("logins_total")
66+
.help("total number of logins")
67+
.labelNames("user_id", "timestamp") // not a good idea, this will result in too many data points
68+
.register();
69+
70+
String userId = UUID.randomUUID().toString();
71+
String timestamp = Long.toString(System.currentTimeMillis());
72+
73+
loginCount.labelValues(userId, timestamp).inc();
74+
```
75+
76+
Initializing Label Values
77+
-------------------------
78+
79+
If you register a metric without labels, it will show up immediately with initial value of zero.
80+
81+
However, metrics with labels only show up after the label values are first used. In the example above
82+
83+
```java
84+
counter.labelValues("paypal", "error").inc();
85+
```
86+
87+
The data point
88+
89+
```
90+
payments_total{status="error",type="paypal"} 1.0
91+
```
92+
93+
will jump from non-existent to value 1.0. You will never see it with value 0.0.
94+
95+
This is usually not an issue. However, if you find this annoying and want to see all possible label values from the start, you can initialize label values with `initLabelValues()` like this:
96+
97+
```java
98+
Counter counter = Counter.builder()
99+
.name("payments_total")
100+
.help("total number of payments")
101+
.labelNames("type", "status")
102+
.register();
103+
104+
counter.initLabelValues("credit card", "success");
105+
counter.initLabelValues("credit card", "error");
106+
counter.initLabelValues("paypal", "success");
107+
counter.initLabelValues("paypal", "error");
108+
```
109+
110+
Now the four combinations will be visible from the start with initial value zero.
111+
112+
```
113+
# HELP payments_total total number of payments
114+
# TYPE payments_total counter
115+
payments_total{status="error",type="credit card"} 0.0
116+
payments_total{status="error",type="paypal"} 0.0
117+
payments_total{status="success",type="credit card"} 0.0
118+
payments_total{status="success",type="paypal"} 0.0
119+
```
120+
121+
Expiring Unused Label Values
122+
----------------------------
123+
124+
There is no automatic expiry of unused label values (yet). Once a set of label values is used, it will remain there forever.
125+
126+
However, you can programmatically remove label values like this:
127+
128+
```java
129+
counter.remove("paypal", "error");
130+
counter.remove("paypal", "success");
131+
```
132+
133+
Const Labels
134+
------------
135+
136+
If you have labels values that never change, you can specify them in the builder as `constLabels()`:
137+
138+
```java
139+
Counter counter = Counter.builder()
140+
.name("payments_total")
141+
.help("total number of payments")
142+
.constLabels(Labels.of("env", "dev"))
143+
.labelNames("type", "status")
144+
.register();
145+
```
146+
147+
However, most use cases for `constLabels()` are better covered by target labels set by the scraping Prometheus server,
148+
or by one specific metric (e.g. a `build_info` or a `machine_role` metric). See also
149+
[target labels, not static scraped labels](https://prometheus.io/docs/instrumenting/writing_exporters/#target-labels-not-static-scraped-labels).

0 commit comments

Comments
 (0)