@@ -83,7 +83,7 @@ To create a simple counter:
83
83
84
84
``` scala
85
85
scala> val totalRequests = Counter (metric " total_requests " , " Total requests" ).labels()
86
- totalRequests: org.lyranthe.prometheus.client.internal. counter.Counter0 = Counter (MetricName (total_requests))()
86
+ totalRequests: org.lyranthe.prometheus.client.counter.Counter0 = Counter (MetricName (total_requests))()
87
87
```
88
88
89
89
The resulting counter has a metric name ` total_requests ` , a help message with the contents,
@@ -102,7 +102,7 @@ the `.labels` method:
102
102
103
103
``` scala
104
104
scala> val totalErrors = Counter (metric " total_errors " , " Total errors" ).labels(label " code " )
105
- totalErrors: org.lyranthe.prometheus.client.internal. counter.Counter1 = Counter1 (MetricName (total_errors),Total errors,List (LabelName (code)))
105
+ totalErrors: org.lyranthe.prometheus.client.counter.Counter1 = Counter1 (MetricName (total_errors),Total errors,List (LabelName (code)))
106
106
```
107
107
108
108
To increment a counter with an error code of "404", one might
@@ -119,7 +119,7 @@ number of values when using this counter:
119
119
120
120
``` scala
121
121
scala> totalErrors.labelValues(" 404" , " /path" ).inc()
122
- <console >: 17 : error : too many arguments for method labelValues : (labelValue1 : String )org.lyranthe.prometheus.client.internal. counter.LabelledCounter
122
+ <console >: 17 : error : too many arguments for method labelValues : (labelValue1 : String )org.lyranthe.prometheus.client.counter.LabelledCounter
123
123
totalErrors.labelValues(" 404" , " /path" ).inc()
124
124
^
125
125
```
@@ -134,30 +134,36 @@ You can create a registry with a default implementation with:
134
134
135
135
``` scala
136
136
scala> implicit val defaultRegistry = DefaultRegistry ()
137
- defaultRegistry: org.lyranthe.prometheus.client.DefaultRegistry =
137
+ defaultRegistry: org.lyranthe.prometheus.client.DefaultRegistry = org.lyranthe.prometheus.client. DefaultRegistry @ 252a4792
138
138
```
139
139
140
140
``` scala
141
141
scala> implicit val histogramBuckets = HistogramBuckets (1 , 2 , 5 , 10 , 20 , 50 , 100 )
142
142
histogramBuckets: org.lyranthe.prometheus.client.HistogramBuckets {val buckets : List [Double ]} = HistogramBuckets (1.0 ,2.0 ,5.0 ,10.0 ,20.0 ,50.0 ,100.0 ,Infinity )
143
143
144
144
scala> val activeRequests = Gauge (metric " active_requests " , " Active requests" ).labels().unsafeRegister
145
- activeRequests: org.lyranthe.prometheus.client.internal. gauge.Gauge0 = Counter (MetricName (active_requests))()
145
+ activeRequests: org.lyranthe.prometheus.client.gauge.Gauge0 = Counter (MetricName (active_requests))()
146
146
147
147
scala> val numErrors = Counter (metric " num_errors " , " Total errors" ).labels().unsafeRegister
148
- numErrors: org.lyranthe.prometheus.client.internal. counter.Counter0 = Counter (MetricName (num_errors))()
148
+ numErrors: org.lyranthe.prometheus.client.counter.Counter0 = Counter (MetricName (num_errors))()
149
149
150
150
scala> val requestLatency = Histogram (metric " request_latency " , " Request latency" ).labels(label " path " ).unsafeRegister
151
- requestLatency: org.lyranthe.prometheus.client.internal. histogram.Histogram1 = Histogram1 (MetricName (request_latency),Request latency,List (LabelName (path)),List (1.0 , 2.0 , 5.0 , 10.0 , 20.0 , 50.0 , 100.0 , Infinity ))
151
+ requestLatency: org.lyranthe.prometheus.client.histogram.Histogram1 = Histogram1 (MetricName (request_latency),Request latency,List (LabelName (path)),List (1.0 , 2.0 , 5.0 , 10.0 , 20.0 , 50.0 , 100.0 , Infinity ))
152
152
153
153
scala> activeRequests.set(50 )
154
154
155
155
scala> numErrors.inc
156
156
157
157
scala> requestLatency.labelValues(" /home" ).observe(17 )
158
158
159
- scala> implicitly[Registry ]
160
- res10: org.lyranthe.prometheus.client.Registry =
159
+ scala> implicitly[Registry ].outputText
160
+ res10: String =
161
+ " # HELP active_requests Active requests
162
+ # TYPE active_requests gauge
163
+ active_requests 50.0
164
+ # HELP num_errors Total errors
165
+ # TYPE num_errors counter
166
+ num_errors 1.0
161
167
# HELP request_latency Request latency
162
168
# TYPE request_latency histogram
163
169
request_latency_bucket{le=" 1.0 " ,path=" / home " } 0
@@ -170,12 +176,7 @@ request_latency_bucket{le="100.0",path="/home"} 1
170
176
request_latency_bucket{le= " + Inf " ,path= " / home " } 1
171
177
request_latency_count{path= " / home " } 1
172
178
request_latency_sum{path= " / home " } 17.0
173
- # HELP num_errors Total errors
174
- # TYPE num_errors counter
175
- num_errors 1.0
176
- # HELP active_requests Active requests
177
- # TYPE active_requests gauge
178
- active_requests 50.0
179
+ "
179
180
```
180
181
181
182
## Using with FS2 Task (WIP)
@@ -198,14 +199,14 @@ import org.lyranthe.prometheus.client.fs2_syntax._
198
199
Then the method ` timeSuccess ` can be used to capture the duration of the task (in seconds):
199
200
200
201
``` scala
201
- implicit val registry = DefaultRegistry ()
202
+ implicit val defaultRegistry = DefaultRegistry ()
202
203
```
203
204
``` scala
204
205
scala> implicit val histogramBuckets = HistogramBuckets (0.02 , 0.05 , 0.1 , 0.2 , 0.5 , 1.0 )
205
206
histogramBuckets: org.lyranthe.prometheus.client.HistogramBuckets {val buckets : List [Double ]} = HistogramBuckets (0.02 ,0.05 ,0.1 ,0.2 ,0.5 ,1.0 ,Infinity )
206
207
207
208
scala> val requestLatency = Histogram (metric " request_latency " , " Request latency" ).labels(label " path " ).unsafeRegister
208
- requestLatency: org.lyranthe.prometheus.client.internal. histogram.Histogram1 = Histogram1 (MetricName (request_latency),Request latency,List (LabelName (path)),List (0.02 , 0.05 , 0.1 , 0.2 , 0.5 , 1.0 , Infinity ))
209
+ requestLatency: org.lyranthe.prometheus.client.histogram.Histogram1 = Histogram1 (MetricName (request_latency),Request latency,List (LabelName (path)),List (0.02 , 0.05 , 0.1 , 0.2 , 0.5 , 1.0 , Infinity ))
209
210
210
211
scala> val mySleepyTask = Task .delay(Thread .sleep(scala.util.Random .nextInt(800 )))
211
212
mySleepyTask: fs2.Task [Unit ] = Task
@@ -215,27 +216,28 @@ myTimedSleepyTask: fs2.Task[Unit] = Task
215
216
216
217
scala> for (i <- Range (1 , 10 )) myTimedSleepyTask.unsafeRun
217
218
218
- scala> implicitly[Registry ]
219
- res1: org.lyranthe.prometheus.client. Registry =
220
- # HELP request_latency Request latency
219
+ scala> implicitly[Registry ].outputText
220
+ res1: String =
221
+ " # HELP request_latency Request latency
221
222
# TYPE request_latency histogram
222
223
request_latency_bucket{le=" 0.02 " ,path=" / home " } 0
223
224
request_latency_bucket{le= " 0.05 " ,path=" / home " } 0
224
225
request_latency_bucket{le= " 0.1 " ,path=" / home " } 0
225
- request_latency_bucket{le= " 0.2" ,path= " /home" } 4
226
- request_latency_bucket{le= " 0.5" ,path= " /home" } 6
226
+ request_latency_bucket{le= " 0.2 " ,path=" / home " } 1
227
+ request_latency_bucket{le= " 0.5 " ,path=" / home " } 5
227
228
request_latency_bucket{le= " 1.0 " ,path=" / home " } 9
228
229
request_latency_bucket{le= " + Inf " ,path= " / home " } 9
229
230
request_latency_count{path= " / home " } 9
230
- request_latency_sum{path= " /home" } 3.398811496
231
+ request_latency_sum{path= " / home " } 3.8517136149999995
232
+ "
231
233
```
232
234
233
235
## Exposing JMX Statistics
234
236
235
237
Some JVM statistics can be exposed with:
236
238
237
239
``` scala
238
- implicit val registry = DefaultRegistry ()
240
+ implicit val defaultRegistry = DefaultRegistry ()
239
241
```
240
242
``` scala
241
243
scala> import fs2 ._
@@ -246,34 +248,34 @@ import org.lyranthe.prometheus.client._
246
248
247
249
scala> jmx.unsafeRegister
248
250
249
- scala> println(implicitly[Registry ])
250
- # HELP jvm_threads JVM Thread Information
251
- # TYPE jvm_threads gauge
252
- jvm_threads{type = " non-daemon" } 11.0
253
- jvm_threads{type = " daemon" } 4.0
254
- # HELP jvm_start_time JVM Start Time
255
- # TYPE jvm_start_time gauge
256
- jvm_start_time 1.477244444947E9
251
+ scala> println(implicitly[Registry ].outputText)
252
+ # HELP jvm_classloader JVM Classloader statistics
253
+ # TYPE jvm_classloader gauge
254
+ jvm_classloader{classloader= " loaded" } 15479.0
255
+ jvm_classloader{classloader= " total-loaded" } 15554.0
256
+ jvm_classloader{classloader= " unloaded" } 75.0
257
+ # HELP jvm_gc_stats JVM Garbage Collector Statistics
258
+ # TYPE jvm_gc_stats gauge
259
+ jvm_gc_stats{name= " PS Scavenge" ,type = " count" } 10.0
260
+ jvm_gc_stats{name= " PS Scavenge" ,type = " time" } 0.217
261
+ jvm_gc_stats{name= " PS MarkSweep" ,type = " count" } 5.0
262
+ jvm_gc_stats{name= " PS MarkSweep" ,type = " time" } 0.406
257
263
# HELP jvm_memory_usage JVM Memory Usage
258
264
# TYPE jvm_memory_usage gauge
259
- jvm_memory_usage{region= " heap" ,type = " committed" } 1.038614528E9
265
+ jvm_memory_usage{region= " heap" ,type = " committed" } 1.042808832E9
260
266
jvm_memory_usage{region= " heap" ,type = " init" } 5.36870912E8
261
267
jvm_memory_usage{region= " heap" ,type = " max" } 1.431830528E9
262
- jvm_memory_usage{region= " heap" ,type = " used" } 2.84849344E8
263
- jvm_memory_usage{region= " non-heap" ,type = " committed" } 1.48914176E8
268
+ jvm_memory_usage{region= " heap" ,type = " used" } 4.70523048E8
269
+ jvm_memory_usage{region= " non-heap" ,type = " committed" } 1.67591936E8
264
270
jvm_memory_usage{region= " non-heap" ,type = " init" } 2555904.0
265
271
jvm_memory_usage{region= " non-heap" ,type = " max" } - 1.0
266
- jvm_memory_usage{region= " non-heap" ,type = " used" } 1.47149728E8
267
- # HELP jvm_gc_stats JVM Garbage Collector Statistics
268
- # TYPE jvm_gc_stats gauge
269
- jvm_gc_stats{name= " PS Scavenge" ,type = " count" } 9.0
270
- jvm_gc_stats{name= " PS Scavenge" ,type = " time" } 0.176
271
- jvm_gc_stats{name= " PS MarkSweep" ,type = " count" } 5.0
272
- jvm_gc_stats{name= " PS MarkSweep" ,type = " time" } 0.325
273
- # HELP jvm_classloader JVM Classloader statistics
274
- # TYPE jvm_classloader gauge
275
- jvm_classloader{classloader= " loaded" } 15230.0
276
- jvm_classloader{classloader= " total-loaded" } 15305.0
277
- jvm_classloader{classloader= " unloaded" } 75.0
272
+ jvm_memory_usage{region= " non-heap" ,type = " used" } 1.65366072E8
273
+ # HELP jvm_start_time JVM Start Time
274
+ # TYPE jvm_start_time gauge
275
+ jvm_start_time 1.477262878978E9
276
+ # HELP jvm_threads JVM Thread Information
277
+ # TYPE jvm_threads gauge
278
+ jvm_threads{type = " non-daemon" } 11.0
279
+ jvm_threads{type = " daemon" } 4.0
278
280
279
281
```
0 commit comments