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