1
+# yamllint disable rule:line-length
2
meta:
3
plugin_name: python.d.plugin
4
module_name: go_expvar
5
monitored_instance:
6
name: Go applications
6
- link: ''
7
+ link: "https://pkg.go.dev/expvar"
8
categories:
8
- - data-collection.apm
9
- icon_filename: 'go.png'
9
+ - data-collection.apm
10
+ icon_filename: "go.png"
11
related_resources:
12
integrations:
13
list: []
14
info_provided_to_referring_integrations:
14
- description: ''
15
- keywords: []
15
+ description: ""
16
+ keywords:
17
+ - go
18
+ - expvar
19
+ - application
20
most_popular: false
21
overview:
22
data_collection:
19
- metrics_description: 'Monitor Go applications performance for optimal Go language software operations. Monitor runtime statistics, garbage collection, and memory usage to enhance Go application performance.'
20
- method_description: ''
23
+ metrics_description: "This collector monitors Go applications that expose their metrics with the use of the `expvar` package from the Go standard library. It produces charts for Go runtime memory statistics and optionally any number of custom charts."
24
+ method_description: "It connects via http to gather the metrics exposed via the `expvar` package."
25
supported_platforms:
26
include: []
27
exclude: []
28
multi_instance: true
29
additional_permissions:
26
- description: ''
30
+ description: ""
31
default_behavior:
32
auto_detection:
29
- description: ''
33
+ description: ""
34
limits:
31
- description: ''
35
+ description: ""
36
performance_impact:
33
- description: ''
37
+ description: ""
38
setup:
39
prerequisites:
36
- list: []
40
+ list:
41
+ - title: "Sample `expvar` usage in a Go application"
42
+ description: |
43
+ The `expvar` package exposes metrics over HTTP and is very easy to use.
44
+ Consider this minimal sample below:
45
+
46
+ ```go
47
+ package main
48
+
49
+ import (
50
+ _ "expvar"
51
+ "net/http"
52
+ )
53
+
54
+ func main() {
55
+ http.ListenAndServe("127.0.0.1:8080", nil)
56
+ }
57
+ ```
58
+
59
+ When imported this way, the `expvar` package registers a HTTP handler at `/debug/vars` that
60
+ exposes Go runtime's memory statistics in JSON format. You can inspect the output by opening
61
+ the URL in your browser (or by using `wget` or `curl`).
62
+
63
+ Sample output:
64
+
65
+ ```json
66
+ {
67
+ "cmdline": ["./expvar-demo-binary"],
68
+ "memstats": {"Alloc":630856,"TotalAlloc":630856,"Sys":3346432,"Lookups":27, <omitted for brevity>}
69
+ }
70
+ ```
71
+
72
+ You can of course expose and monitor your own variables as well.
73
+ Here is a sample Go application that exposes a few custom variables:
74
+
75
+ ```go
76
+ package main
77
+
78
+ import (
79
+ "expvar"
80
+ "net/http"
81
+ "runtime"
82
+ "time"
83
+ )
84
+
85
+ func main() {
86
+
87
+ tick := time.NewTicker(1 * time.Second)
88
+ num_go := expvar.NewInt("runtime.goroutines")
89
+ counters := expvar.NewMap("counters")
90
+ counters.Set("cnt1", new(expvar.Int))
91
+ counters.Set("cnt2", new(expvar.Float))
92
+
93
+ go http.ListenAndServe(":8080", nil)
94
+
95
+ for {
96
+ select {
97
+ case <- tick.C:
98
+ num_go.Set(int64(runtime.NumGoroutine()))
99
+ counters.Add("cnt1", 1)
100
+ counters.AddFloat("cnt2", 1.452)
101
+ }
102
+ }
103
+ }
104
+ ```
105
+
106
+ Apart from the runtime memory stats, this application publishes two counters and the
107
+ number of currently running Goroutines and updates these stats every second.
108
configuration:
109
file:
39
- name: ''
40
- description: ''
110
+ name: python.d/go_expvar.conf
111
options:
42
- description: ''
112
+ description: |
113
+ There are 2 sections:
114
+
115
+ * Global variables
116
+ * One or more JOBS that can define multiple different instances to monitor.
117
+
118
+ The following options can be defined globally: priority, penalty, autodetection_retry, update_every, but can also be defined per JOB to override the global values.
119
+
120
+ Additionally, the following collapsed table contains all the options that can be configured inside a JOB definition.
121
+
122
+ Every configuration JOB starts with a `job_name` value which will appear in the dashboard, unless a `name` parameter is specified. Each JOB can be used to monitor a different Go application.
123
folding:
44
- title: ''
124
+ title: "Config options"
125
enabled: true
46
- list: []
126
+ list:
127
+ - name: update_every
128
+ description: Sets the default data collection frequency.
129
+ default_value: 5
130
+ required: false
131
+ - name: priority
132
+ description: Controls the order of charts at the netdata dashboard.
133
+ default_value: 60000
134
+ required: false
135
+ - name: autodetection_retry
136
+ description: Sets the job re-check interval in seconds.
137
+ default_value: 0
138
+ required: false
139
+ - name: penalty
140
+ description: Indicates whether to apply penalty to update_every in case of failures.
141
+ default_value: yes
142
+ required: false
143
+ - name: name
144
+ description: Job name. This value will overwrite the `job_name` value. JOBS with the same name are mutually exclusive. Only one of them will be allowed running at any time. This allows autodetection to try several alternatives and pick the one that works.
145
+ default_value: ""
146
+ required: false
147
+ - name: url
148
+ description: the URL and port of the expvar endpoint. Please include the whole path of the endpoint, as the expvar handler can be installed in a non-standard location.
149
+ default_value: ""
150
+ required: true
151
+ - name: user
152
+ description: If the URL is password protected, this is the username to use.
153
+ default_value: ""
154
+ required: false
155
+ - name: pass
156
+ description: If the URL is password protected, this is the password to use.
157
+ default_value: ""
158
+ required: false
159
+ - name: collect_memstats
160
+ description: Enables charts for Go runtime's memory statistics.
161
+ default_value: ""
162
+ required: false
163
+ - name: extra_charts
164
+ description: Defines extra data/charts to monitor, please see the example below.
165
+ default_value: ""
166
+ required: false
167
examples:
168
folding:
49
- enabled: true
50
- title: ''
51
- list: []
169
+ enabled: false
170
+ title: "Config"
171
+ list:
172
+ - name: Monitor a Go app1 application
173
+ description: |
174
+ The example below sets a configuration for a Go application, called `app1`. Besides the `memstats`, the application also exposes two counters and the number of currently running Goroutines and updates these stats every second.
175
+
176
+ The `go_expvar` collector can monitor these as well with the use of the `extra_charts` configuration variable.
177
+
178
+ The `extra_charts` variable is a YaML list of Netdata chart definitions.
179
+ Each chart definition has the following keys:
180
+
181
+ ```
182
+ id: Netdata chart ID
183
+ options: a key-value mapping of chart options
184
+ lines: a list of line definitions
185
+ ```
186
+
187
+ **Note: please do not use dots in the chart or line ID field.
188
+ See [this issue](https://github.com/netdata/netdata/pull/1902#issuecomment-284494195) for explanation.**
189
+
190
+ Please see these two links to the official Netdata documentation for more information about the values:
191
+
192
+ - [External plugins - charts](https://github.com/netdata/netdata/blob/master/collectors/plugins.d/README.md#chart)
193
+ - [Chart variables](https://github.com/netdata/netdata/blob/master/collectors/python.d.plugin/README.md#global-variables-order-and-chart)
194
+
195
+ **Line definitions**
196
+
197
+ Each chart can define multiple lines (dimensions).
198
+ A line definition is a key-value mapping of line options.
199
+ Each line can have the following options:
200
+
201
+ ```
202
+ # mandatory
203
+ expvar_key: the name of the expvar as present in the JSON output of /debug/vars endpoint
204
+ expvar_type: value type; supported are "float" or "int"
205
+ id: the id of this line/dimension in Netdata
206
+
207
+ # optional - Netdata defaults are used if these options are not defined
208
+ name: ''
209
+ algorithm: absolute
210
+ multiplier: 1
211
+ divisor: 100 if expvar_type == float, 1 if expvar_type == int
212
+ hidden: False
213
+ ```
214
+
215
+ Please see the following link for more information about the options and their default values:
216
+ [External plugins - dimensions](https://github.com/netdata/netdata/blob/master/collectors/plugins.d/README.md#dimension)
217
+
218
+ Apart from top-level expvars, this plugin can also parse expvars stored in a multi-level map;
219
+ All dicts in the resulting JSON document are then flattened to one level.
220
+ Expvar names are joined together with '.' when flattening.
221
+
222
+ Example:
223
+
224
+ ```
225
+ {
226
+ "counters": {"cnt1": 1042, "cnt2": 1512.9839999999983},
227
+ "runtime.goroutines": 5
228
+ }
229
+ ```
230
+
231
+ In the above case, the exported variables will be available under `runtime.goroutines`,
232
+ `counters.cnt1` and `counters.cnt2` expvar_keys. If the flattening results in a key collision,
233
+ the first defined key wins and all subsequent keys with the same name are ignored.
234
+ config: |
235
+ app1:
236
+ name : 'app1'
237
+ url : 'http://127.0.0.1:8080/debug/vars'
238
+ collect_memstats: true
239
+ extra_charts:
240
+ - id: "runtime_goroutines"
241
+ options:
242
+ name: num_goroutines
243
+ title: "runtime: number of goroutines"
244
+ units: goroutines
245
+ family: runtime
246
+ context: expvar.runtime.goroutines
247
+ chart_type: line
248
+ lines:
249
+ - {expvar_key: 'runtime.goroutines', expvar_type: int, id: runtime_goroutines}
250
+ - id: "foo_counters"
251
+ options:
252
+ name: counters
253
+ title: "some random counters"
254
+ units: awesomeness
255
+ family: counters
256
+ context: expvar.foo.counters
257
+ chart_type: line
258
+ lines:
259
+ - {expvar_key: 'counters.cnt1', expvar_type: int, id: counters_cnt1}
260
+ - {expvar_key: 'counters.cnt2', expvar_type: float, id: counters_cnt2}
261
troubleshooting:
262
problems:
263
list: []
269
description: ""
270
availability: []
271
scopes:
63
- - name: global
64
- description: ""
65
- labels: []
66
- metrics:
67
- - name: expvar.memstats.heap
68
- description: 'memory: size of heap memory structures'
69
- unit: "KiB"
70
- chart_type: line
71
- dimensions:
72
- - name: alloc
73
- - name: inuse
74
- - name: expvar.memstats.stack
75
- description: 'memory: size of stack memory structures'
76
- unit: "KiB"
77
- chart_type: line
78
- dimensions:
79
- - name: inuse
80
- - name: expvar.memstats.mspan
81
- description: 'memory: size of mspan memory structures'
82
- unit: "KiB"
83
- chart_type: line
84
- dimensions:
85
- - name: inuse
86
- - name: expvar.memstats.mcache
87
- description: 'memory: size of mcache memory structures'
88
- unit: "KiB"
89
- chart_type: line
90
- dimensions:
91
- - name: inuse
92
- - name: expvar.memstats.live_objects
93
- description: 'memory: number of live objects'
94
- unit: "objects"
95
- chart_type: line
96
- dimensions:
97
- - name: live
98
- - name: expvar.memstats.sys
99
- description: 'memory: size of reserved virtual address space'
100
- unit: "KiB"
101
- chart_type: line
102
- dimensions:
103
- - name: sys
104
- - name: expvar.memstats.gc_pauses
105
- description: 'memory: average duration of GC pauses'
106
- unit: "ns"
107
- chart_type: line
108
- dimensions:
109
- - name: avg
272
+ - name: global
273
+ description: "These metrics refer to the entire monitored application."
274
+ labels: []
275
+ metrics:
276
+ - name: expvar.memstats.heap
277
+ description: "memory: size of heap memory structures"
278
+ unit: "KiB"
279
+ chart_type: line
280
+ dimensions:
281
+ - name: alloc
282
+ - name: inuse
283
+ - name: expvar.memstats.stack
284
+ description: "memory: size of stack memory structures"
285
+ unit: "KiB"
286
+ chart_type: line
287
+ dimensions:
288
+ - name: inuse
289
+ - name: expvar.memstats.mspan
290
+ description: "memory: size of mspan memory structures"
291
+ unit: "KiB"
292
+ chart_type: line
293
+ dimensions:
294
+ - name: inuse
295
+ - name: expvar.memstats.mcache
296
+ description: "memory: size of mcache memory structures"
297
+ unit: "KiB"
298
+ chart_type: line
299
+ dimensions:
300
+ - name: inuse
301
+ - name: expvar.memstats.live_objects
302
+ description: "memory: number of live objects"
303
+ unit: "objects"
304
+ chart_type: line
305
+ dimensions:
306
+ - name: live
307
+ - name: expvar.memstats.sys
308
+ description: "memory: size of reserved virtual address space"
309
+ unit: "KiB"
310
+ chart_type: line
311
+ dimensions:
312
+ - name: sys
313
+ - name: expvar.memstats.gc_pauses
314
+ description: "memory: average duration of GC pauses"
315
+ unit: "ns"
316
+ chart_type: line
317
+ dimensions:
318
+ - name: avg