You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+120-45
Original file line number
Diff line number
Diff line change
@@ -1,18 +1,28 @@
1
1
# script_exporter
2
2
3
-
The script_exporter is a [Prometheus](https://prometheus.io) exporter to execute scripts and collect metrics from the output or the exit status. The scripts to be executed are defined via a configuration file. In the configuration file several scripts can be specified. The script which should be executed is indicated by a parameter in the scrap configuration. The output of the script is captured and is provided for Prometheus. Even if the script does not produce any output, the exit status and the duration of the execution are provided.
3
+
The script_exporter is a [Prometheus](https://prometheus.io) exporter to execute
4
+
scripts and collect metrics from the output or the exit status. The scripts to
5
+
be executed are defined via a configuration file. In the configuration file
6
+
several scripts can be specified. The script which should be executed is
7
+
indicated by a parameter in the scrap configuration. The output of the script is
8
+
captured and is provided for Prometheus. Even if the script does not produce any
9
+
output, the exit status and the duration of the execution are provided.
4
10
5
11
## Building and running
6
12
7
-
To run the script_exporter you can use the one of the binaries from the [release](https://github.com/ricoberger/script_exporter/releases) page or the [Docker image](https://hub.docker.com/r/ricoberger/script_exporter). You can also build the script_exporter by yourself by running the following commands:
13
+
To run the script_exporter you can use the one of the binaries from the
14
+
[release](https://github.com/ricoberger/script_exporter/releases) page or the
15
+
[Docker image](https://hub.docker.com/r/ricoberger/script_exporter). You can
16
+
also build the script_exporter by yourself by running the following commands:
Then visit [http://localhost:9469](http://localhost:9469) in the browser of your choice. There you have access to the following examples:
29
-
30
-
-[test](http://localhost:9469/probe?script=test&prefix=test): Invalid values which are returned by the script are omitted.
31
-
-[ping](http://localhost:9469/probe?script=ping&prefix=test¶ms=target&target=example.com): Pings the specified address in the `target` parameter and returns if it was successful or not.
32
-
-[helloworld](http://localhost:9469/probe?script=helloworld): Returns the specified argument in `args` as label.
33
-
-[showtimeout](http://localhost:9469/probe?script=showtimeout&timeout=37): Reports whether or not the script is being run with a timeout from Prometheus, and what it is.
34
-
-[docker](http://localhost:9469/probe?script=docker): Example using `docker exec` to return the number of files in a Docker container.
35
-
-[args](http://localhost:9469/probe?script=args¶ms=arg3,arg4&arg3=test3&arg4=test4): Pass arguments to the script via the configuration file.
36
-
-[metrics](http://localhost:9469/metrics): Shows internal metrics from the script exporter.
38
+
Then visit [http://localhost:9469](http://localhost:9469) in the browser of your
39
+
choice. There you have access to the following examples:
The script_exporter is configured via a configuration file and command-line flags.
66
+
The script_exporter is configured via a configuration file and command-line
67
+
flags.
47
68
48
69
```txt
49
70
Usage of ./bin/script_exporter:
@@ -69,7 +90,8 @@ Usage of ./bin/script_exporter:
69
90
Address to listen on for web interface and telemetry. (default ":9469")
70
91
```
71
92
72
-
The configuration file is written in YAML format, defined by the scheme described below.
93
+
The configuration file is written in YAML format, defined by the scheme
94
+
described below.
73
95
74
96
```yaml
75
97
tls:
@@ -123,11 +145,20 @@ scripts_configs:
123
145
- <string>
124
146
```
125
147
126
-
The `name` of the script must be a valid Prometheus label value. The `command` string is the script which is executed with all arguments specified in `args`. To add dynamic arguments you can pass the `params` query parameter with a list of query parameters which values should be added as argument. The program will be executed directly, without a shell being invoked, and it is recommended that it be specified by path instead of relying on ``$PATH``.
148
+
The `name` of the script must be a valid Prometheus label value. The `command`
149
+
string is the script which is executed with all arguments specified in `args`.
150
+
To add dynamic arguments you can pass the `params` query parameter with a list
151
+
of query parameters which values should be added as argument. The program will
152
+
be executed directly, without a shell being invoked, and it is recommended that
153
+
it be specified by path instead of relying on `$PATH`.
127
154
128
-
If `sudo` is defined and set to `true`, the command will be executed with privileged (root) permissions by executing the `command` with a pre-fixed `sudo`. Note that you still need to create the relevant sudoers entries, script_exporter will not do this for you.
155
+
If `sudo` is defined and set to `true`, the command will be executed with
156
+
privileged (root) permissions by executing the `command` with a pre-fixed
157
+
`sudo`. Note that you still need to create the relevant sudoers entries,
158
+
script_exporter will not do this for you.
129
159
130
-
The optional `env` key allows to run the script with custom environment variables.
160
+
The optional `env` key allows to run the script with custom environment
161
+
variables.
131
162
132
163
Example: set proxy env vars for test_env script
133
164
@@ -140,8 +171,8 @@ scripts:
140
171
https_proxy: http://proxy.example.com:3128
141
172
```
142
173
143
-
**Note:** because the program is executed directly, shell constructions can't be used.
144
-
For example:
174
+
**Note:** because the program is executed directly, shell constructions can't be
175
+
used. For example:
145
176
146
177
```shell
147
178
# Error: output stream redirection (>) is a shell construction
@@ -159,41 +190,80 @@ For example:
159
190
/bin/bash /usr/local/bin/bar.sh
160
191
```
161
192
162
-
Prometheus will normally provide an indication of its scrape timeout to the script exporter (through a special HTTP header). This information is made available to scripts through the environment variables `$SCRIPT_TIMEOUT` and `$SCRIPT_DEADLINE`. The first is the timeout in seconds (including a fractional part) and the second is the Unix timestamp when the deadline will expire (also including a fractional part). A simple script could implement this timeout by starting with `timeout "$SCRIPT_TIMEOUT" cmd ...`. A more sophisticated program might want to use the deadline time to compute internal timeouts for various operation. If `enforced` is true, `script_exporter` attempts to enforce the timeout by killing the script's main process after the timeout expires. The default is to not enforce timeouts. If `max_timeout` is set for a script, it limits the maximum timeout value that requests can specify; a request that specifies a larger timeout will have the timeout adjusted down to the `max_timeout` value.
163
-
164
-
For testing purposes, the timeout can be specified directly as a URL parameter (`timeout`). If present, the URL parameter takes priority over the Prometheus HTTP header.
165
-
166
-
The `cacheDuration` config can be used to cache the results from an execution of the script for the provided time. The provided duration must be parsable by the [`time.ParseDuration`](https://pkg.go.dev/time#ParseDuration) function. If no cache duration is provided or the provided cache duration can not be parsed, the output of an script will not be cached. It produces the metric `script_use_cache` to track in time when results returned are coming from cache.
167
-
168
-
The `useExpiredCacheOnError` config allow to return expired cache in case of errors. It produces the metric `script_use_expired_cache` for track in time if you are using expired cache, it mean there is something wrong with the script execution.
169
-
170
-
You can fine tune the script discovery options via optional script `discovery`. All these options will go through prometheus configuration where you can change them via relabel mechanism.
171
-
There are `params` to define dynamic script parameters (with reserved keys: `params`, `prefix`, `script` and `timeout`) where only value will be used during script invoking (similar to `args`), `prefix` to define prefix for all script metrics, `scrape_interval` to define how often the script scrape should run and `scrape_timeout` to define the scrape timeout for prometheus (similar to `timeout`).
172
-
173
-
The global `discovery` configures the main discovery parameters. If not defined, the exporter will use `Host:` header from the request to decide how to present a `target` to prometheus.
193
+
Prometheus will normally provide an indication of its scrape timeout to the
194
+
script exporter (through a special HTTP header). This information is made
195
+
available to scripts through the environment variables `$SCRIPT_TIMEOUT` and
196
+
`$SCRIPT_DEADLINE`. The first is the timeout in seconds (including a fractional
197
+
part) and the second is the Unix timestamp when the deadline will expire (also
198
+
including a fractional part). A simple script could implement this timeout by
199
+
starting with `timeout "$SCRIPT_TIMEOUT" cmd ...`. A more sophisticated program
200
+
might want to use the deadline time to compute internal timeouts for various
201
+
operation. If `enforced` is true, `script_exporter` attempts to enforce the
202
+
timeout by killing the script's main process after the timeout expires. The
203
+
default is to not enforce timeouts. If `max_timeout` is set for a script, it
204
+
limits the maximum timeout value that requests can specify; a request that
205
+
specifies a larger timeout will have the timeout adjusted down to the
206
+
`max_timeout`value.
207
+
208
+
For testing purposes, the timeout can be specified directly as a URL parameter
209
+
(`timeout`). If present, the URL parameter takes priority over the Prometheus
210
+
HTTP header.
211
+
212
+
The `cacheDuration` config can be used to cache the results from an execution of
213
+
the script for the provided time. The provided duration must be parsable by the
214
+
[`time.ParseDuration`](https://pkg.go.dev/time#ParseDuration) function. If no
215
+
cache duration is provided or the provided cache duration can not be parsed, the
216
+
output of an script will not be cached. It produces the metric
217
+
`script_use_cache`to track in time when results returned are coming from cache.
218
+
219
+
The `useExpiredCacheOnError` config allow to return expired cache in case of
220
+
errors. It produces the metric `script_use_expired_cache` for track in time if
221
+
you are using expired cache, it mean there is something wrong with the script
222
+
execution.
223
+
224
+
You can fine tune the script discovery options via optional script `discovery`.
225
+
All these options will go through prometheus configuration where you can change
226
+
them via relabel mechanism. There are `params` to define dynamic script
227
+
parameters (with reserved keys: `params`, `prefix`, `script` and `timeout`)
228
+
where only value will be used during script invoking (similar to `args`),
229
+
`prefix`to define prefix for all script metrics, `scrape_interval` to define
230
+
how often the script scrape should run and `scrape_timeout` to define the scrape
231
+
timeout for prometheus (similar to `timeout`).
232
+
233
+
The global `discovery` configures the main discovery parameters. If not defined,
234
+
the exporter will use `Host:` header from the request to decide how to present a
235
+
`target`to prometheus.
174
236
175
237
## Prometheus configuration
176
238
177
-
The script_exporter needs to be passed the script name as a parameter (`script`). You can also pass a custom prefix (`prefix`) which is prepended to metrics names and the names of additional parameters which should be passed to the script (`params` and then additional URL parameters). If the `output` parameter is set to `ignore` then the script_exporter only return `script_success{}`, `script_duration_seconds{}` and `script_exit_code{}`.
239
+
The script_exporter needs to be passed the script name as a parameter
240
+
(`script`). You can also pass a custom prefix (`prefix`) which is prepended to
241
+
metrics names and the names of additional parameters which should be passed to
242
+
the script (`params` and then additional URL parameters). If the `output`
243
+
parameter is set to `ignore` then the script_exporter only return
244
+
`script_success{}`, `script_duration_seconds{}` and `script_exit_code{}`.
178
245
179
-
The `params` parameter is a comma-separated list of additional URL query parameters that will be used to construct the additional list of arguments, in order. The value of each URL query parameter is not parsed or split; it is passed directly to the script as a single argument.
246
+
The `params` parameter is a comma-separated list of additional URL query
247
+
parameters that will be used to construct the additional list of arguments, in
248
+
order. The value of each URL query parameter is not parsed or split; it is
249
+
passed directly to the script as a single argument.
180
250
181
251
Example config:
182
252
183
253
```yaml
184
254
scrape_configs:
185
-
- job_name: 'script_test'
255
+
- job_name: "script_test"
186
256
metrics_path: /probe
187
257
params:
188
258
script: [test]
189
259
prefix: [script]
190
260
static_configs:
191
261
- targets:
192
-
- 127.0.0.1
262
+
- 127.0.0.1
193
263
relabel_configs:
194
264
- target_label: script
195
265
replacement: test
196
-
- job_name: 'script_ping'
266
+
- job_name: "script_ping"
197
267
scrape_interval: 1m
198
268
scrape_timeout: 30s
199
269
metrics_path: /probe
@@ -204,7 +274,7 @@ scrape_configs:
204
274
output: [ignore]
205
275
static_configs:
206
276
- targets:
207
-
- example.com
277
+
- example.com
208
278
relabel_configs:
209
279
- source_labels: [__address__]
210
280
target_label: __param_target
@@ -215,26 +285,31 @@ scrape_configs:
215
285
- source_labels: [__param_target]
216
286
target_label: instance
217
287
218
-
- job_name: 'script_exporter'
288
+
- job_name: "script_exporter"
219
289
metrics_path: /metrics
220
290
static_configs:
221
291
- targets:
222
-
- 127.0.0.1:9469
292
+
- 127.0.0.1:9469
223
293
```
224
294
225
295
Optionally, HTTP service discovery can be configured like this:
This will make prometheus reach to `/discovery` endpoint and collect the targets. Targets are all the scripts configured in the exporter.
303
+
This will make prometheus reach to `/discovery` endpoint and collect the
304
+
targets. Targets are all the scripts configured in the exporter.
234
305
235
306
## Breaking changes
236
307
237
308
Changes from version 1.3.0:
238
309
239
-
- The command line flag ``-web.telemetry-path`` has been removed and its value is now always ``/probe``, which is a change from the previous default of ``/metrics``. The path ``/metrics`` now responds with Prometheus metrics for script_exporter itself.
240
-
- The command line flag ``-config.shell`` has been removed. Programs are now always run directly.
310
+
- The command line flag `-web.telemetry-path` has been removed and its value is
311
+
now always `/probe`, which is a change from the previous default of
312
+
`/metrics`. The path `/metrics` now responds with Prometheus metrics for
313
+
script_exporter itself.
314
+
- The command line flag `-config.shell` has been removed. Programs are now
0 commit comments