Skip to content

Commit 65503f5

Browse files
authored
Fix Docker Instructions in Readme (#185)
1 parent f736d4a commit 65503f5

File tree

1 file changed

+120
-45
lines changed

1 file changed

+120
-45
lines changed

README.md

+120-45
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
11
# script_exporter
22

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.
410

511
## Building and running
612

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:
817

918
```sh
1019
git clone https://github.com/ricoberger/script_exporter.git
1120
cd script_exporter
1221
make build
1322
```
1423

15-
An example configuration can be found in the [examples](./examples) folder. To use this configuration run the following command:
24+
An example configuration can be found in the [examples](./examples) folder. To
25+
use this configuration run the following command:
1626

1727
```sh
1828
./bin/script_exporter -config.file ./examples/config.yaml
@@ -21,19 +31,29 @@ An example configuration can be found in the [examples](./examples) folder. To u
2131
To run the examples via Docker the following commands can be used:
2232

2333
```sh
24-
docker build -f ./Dockerfile -t ghcr.io/ricoberger/script_exporter:dev .
25-
docker run --rm -it --name script_exporter -p 9469:9469 -v $(pwd)/examples:/examples ghcr.io/ricoberger/script_exporter:dev -config.file /examples/config.yaml
34+
docker build -f ./Dockerfile -t ghcr.io/ricoberger/script_exporter:main .
35+
docker run --rm -it --name script_exporter -p 9469:9469 -v $(pwd)/examples:/examples ghcr.io/ricoberger/script_exporter:main -config.file /examples/config.yaml
2636
```
2737

28-
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&params=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&params=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:
40+
41+
- [test](http://localhost:9469/probe?script=test&prefix=test): Invalid values
42+
which are returned by the script are omitted.
43+
- [ping](http://localhost:9469/probe?script=ping&prefix=test&params=target&target=example.com):
44+
Pings the specified address in the `target` parameter and returns if it was
45+
successful or not.
46+
- [helloworld](http://localhost:9469/probe?script=helloworld): Returns the
47+
specified argument in `args` as label.
48+
- [showtimeout](http://localhost:9469/probe?script=showtimeout&timeout=37):
49+
Reports whether or not the script is being run with a timeout from Prometheus,
50+
and what it is.
51+
- [docker](http://localhost:9469/probe?script=docker): Example using
52+
`docker exec` to return the number of files in a Docker container.
53+
- [args](http://localhost:9469/probe?script=args&params=arg3,arg4&arg3=test3&arg4=test4):
54+
Pass arguments to the script via the configuration file.
55+
- [metrics](http://localhost:9469/metrics): Shows internal metrics from the
56+
script exporter.
3757

3858
You can also deploy the script_exporter to Kubernetes via Helm:
3959

@@ -43,7 +63,8 @@ helm upgrade --install script-exporter oci://ghcr.io/ricoberger/charts/script-ex
4363

4464
## Usage and configuration
4565

46-
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.
4768

4869
```txt
4970
Usage of ./bin/script_exporter:
@@ -69,7 +90,8 @@ Usage of ./bin/script_exporter:
6990
Address to listen on for web interface and telemetry. (default ":9469")
7091
```
7192

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.
7395

7496
```yaml
7597
tls:
@@ -123,11 +145,20 @@ scripts_configs:
123145
- <string>
124146
```
125147
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`.
127154

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.
129159

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.
131162

132163
Example: set proxy env vars for test_env script
133164

@@ -140,8 +171,8 @@ scripts:
140171
https_proxy: http://proxy.example.com:3128
141172
```
142173

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:
145176

146177
```shell
147178
# Error: output stream redirection (>) is a shell construction
@@ -159,41 +190,80 @@ For example:
159190
/bin/bash /usr/local/bin/bar.sh
160191
```
161192

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.
174236

175237
## Prometheus configuration
176238

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{}`.
178245

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.
180250

181251
Example config:
182252

183253
```yaml
184254
scrape_configs:
185-
- job_name: 'script_test'
255+
- job_name: "script_test"
186256
metrics_path: /probe
187257
params:
188258
script: [test]
189259
prefix: [script]
190260
static_configs:
191261
- targets:
192-
- 127.0.0.1
262+
- 127.0.0.1
193263
relabel_configs:
194264
- target_label: script
195265
replacement: test
196-
- job_name: 'script_ping'
266+
- job_name: "script_ping"
197267
scrape_interval: 1m
198268
scrape_timeout: 30s
199269
metrics_path: /probe
@@ -204,7 +274,7 @@ scrape_configs:
204274
output: [ignore]
205275
static_configs:
206276
- targets:
207-
- example.com
277+
- example.com
208278
relabel_configs:
209279
- source_labels: [__address__]
210280
target_label: __param_target
@@ -215,26 +285,31 @@ scrape_configs:
215285
- source_labels: [__param_target]
216286
target_label: instance
217287
218-
- job_name: 'script_exporter'
288+
- job_name: "script_exporter"
219289
metrics_path: /metrics
220290
static_configs:
221291
- targets:
222-
- 127.0.0.1:9469
292+
- 127.0.0.1:9469
223293
```
224294

225295
Optionally, HTTP service discovery can be configured like this:
226296

227297
```yaml
228298
- job_name: "exported-scripts"
229299
http_sd_configs:
230-
- url: http://prometheus-script-exporter:9469/discovery
300+
- url: http://prometheus-script-exporter:9469/discovery
231301
```
232302

233-
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.
234305

235306
## Breaking changes
236307

237308
Changes from version 1.3.0:
238309

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
315+
always run directly.

0 commit comments

Comments
 (0)