2018-03-09 07:13:26 +08:00
# HTTP Response Input Plugin
2016-03-31 15:33:28 +08:00
2018-03-09 07:13:26 +08:00
This input plugin checks HTTP/HTTPS connections.
2016-03-31 15:33:28 +08:00
2022-10-27 03:58:36 +08:00
## Global configuration options <!-- @/docs/includes/plugin_config.md -->
In addition to the plugin-specific configuration settings, plugins support
additional global and plugin configuration settings. These settings are used to
modify metrics, tags, and field or create aliases and configure ordering, etc.
See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
2023-01-12 23:55:21 +08:00
[CONFIGURATION.md]: ../../../docs/CONFIGURATION.md#plugins
2022-10-27 03:58:36 +08:00
2023-02-03 00:31:23 +08:00
## Secret-store support
This plugin supports secrets from secret-stores for the `username` and
`password` option.
See the [secret-store documentation][SECRETSTORE] for more details on how
to use them.
[SECRETSTORE]: ../../../docs/CONFIGURATION.md#secret-store-secrets
2021-11-25 02:56:55 +08:00
## Configuration
2016-03-31 15:33:28 +08:00
2022-05-24 21:49:47 +08:00
```toml @sample .conf
2016-05-23 20:33:43 +08:00
# HTTP/HTTPS request given an address a method and a timeout
2016-03-31 15:33:28 +08:00
[[inputs.http_response]]
2019-06-15 03:03:44 +08:00
## List of urls to query.
# urls = ["http://localhost"]
2022-08-10 00:57:31 +08:00
## Set http_proxy.
## Telegraf uses the system wide proxy settings if it's is not set.
2018-03-31 02:10:49 +08:00
# http_proxy = "http://localhost:8888"
2016-04-07 09:57:49 +08:00
## Set response_timeout (default 5 seconds)
2017-08-16 02:50:08 +08:00
# response_timeout = "5s"
2016-03-31 19:06:47 +08:00
## HTTP Request Method
2017-08-16 02:50:08 +08:00
# method = "GET"
2016-03-31 18:18:19 +08:00
## Whether to follow redirects from the server (defaults to false)
2017-08-16 02:50:08 +08:00
# follow_redirects = false
2020-08-11 03:52:38 +08:00
## Optional file with Bearer token
## file content is added as an Authorization header
# bearer_token = "/path/to/file"
## Optional HTTP Basic Auth Credentials
# username = "username"
# password = "pa$$word"
2016-03-31 19:06:47 +08:00
## Optional HTTP Request Body
2016-05-23 20:33:43 +08:00
# body = '''
# {'fake':'data'}
# '''
2016-05-25 19:41:21 +08:00
2023-10-30 16:06:22 +08:00
## Optional HTTP Request Body Form
## Key value pairs to encode and set at URL form. Can be used with the POST
## method + application/x-www-form-urlencoded content type to replicate the
## POSTFORM method.
# body_form = { "key": "value" }
2020-10-14 23:12:41 +08:00
## Optional name of the field that will contain the body of the response.
2022-08-10 00:57:31 +08:00
## By default it is set to an empty String indicating that the body's
## content won't be added
2020-06-09 06:29:34 +08:00
# response_body_field = ''
## Maximum allowed HTTP response body size in bytes.
## 0 means to use the default of 32MiB.
2022-08-10 00:57:31 +08:00
## If the response body size exceeds this limit a "body_read_error" will
## be raised.
2020-06-09 06:29:34 +08:00
# response_body_max_size = "32MiB"
2019-01-08 03:25:08 +08:00
## Optional substring or regex match in body of the response (case sensitive)
2017-08-16 02:50:08 +08:00
# response_string_match = "\"service_status\": \"up\""
# response_string_match = "ok"
# response_string_match = "\".*_status\".?:.?\"up\""
2017-02-01 22:21:08 +08:00
2020-10-17 01:40:17 +08:00
## Expected response status code.
2022-08-10 00:57:31 +08:00
## The status code of the response is compared to this value. If they match,
## the field "response_status_code_match" will be 1, otherwise it will be 0.
## If the expected status code is 0, the check is disabled and the field
## won't be added.
2020-10-17 01:40:17 +08:00
# response_status_code = 0
2018-05-05 07:33:23 +08:00
## Optional TLS Config
# tls_ca = "/etc/telegraf/ca.pem"
# tls_cert = "/etc/telegraf/cert.pem"
# tls_key = "/etc/telegraf/key.pem"
## Use TLS but skip chain & host verification
2016-05-25 19:41:21 +08:00
# insecure_skip_verify = false
2020-12-24 03:39:43 +08:00
## Use the given name as the SNI server name on each URL
# tls_server_name = ""
2022-12-07 11:09:58 +08:00
## TLS renegotiation method, choose from "never", "once", "freely"
# tls_renegotiation_method = "never"
2017-08-16 02:50:08 +08:00
## HTTP Request Headers (all values must be strings)
# [inputs.http_response.headers]
# Host = "github.com"
2019-06-20 04:40:53 +08:00
2020-06-09 06:29:34 +08:00
## Optional setting to map response http headers into tags
2022-08-10 00:57:31 +08:00
## If the http header is not present on the request, no corresponding tag will
## be added. If multiple instances of the http header are present, only the
## first value will be used.
2020-05-27 06:52:13 +08:00
# http_header_tags = {"HTTP_HEADER" = "TAG_NAME"}
2019-06-20 04:40:53 +08:00
## Interface to use when dialing an address
# interface = "eth0"
2016-03-31 15:33:28 +08:00
```
2021-11-25 02:56:55 +08:00
## Metrics
2016-03-31 15:33:28 +08:00
- http_response
2018-03-09 07:13:26 +08:00
- tags:
- server (target URL)
- method (request method)
- status_code (response status code)
- result ([see below](#result--result_code))
- fields:
- response_time (float, seconds)
2019-08-17 06:45:20 +08:00
- content_length (int, response body length)
2019-01-08 03:25:08 +08:00
- response_string_match (int, 0 = mismatch / body read error, 1 = match)
2020-10-17 01:40:17 +08:00
- response_status_code_match (int, 0 = mismatch, 1 = match)
2018-03-09 07:13:26 +08:00
- http_response_code (int, response status code)
2022-08-10 00:57:31 +08:00
- result_type (string, deprecated in 1.6: use `result` tag and
`result_code` field)
2018-03-09 07:13:26 +08:00
- result_code (int, [see below ](#result--result_code ))
2021-11-25 02:56:55 +08:00
### `result` / `result_code`
2018-03-09 06:55:59 +08:00
2022-06-08 05:37:08 +08:00
Upon finishing polling the target server, the plugin registers the result of the
operation in the `result` tag, and adds a numeric field called `result_code`
corresponding with that tag value.
2018-03-09 06:55:59 +08:00
2022-06-08 05:37:08 +08:00
This tag is used to expose network and plugin errors. HTTP errors are considered
a successful connection.
2018-03-09 06:55:59 +08:00
2020-10-17 01:40:17 +08:00
|Tag value |Corresponding field value|Description|
2024-01-30 02:25:03 +08:00
|------------------------------|-------------------------|-----------|
2020-10-17 01:40:17 +08:00
|success | 0 |The HTTP request completed, even if the HTTP code represents an error|
|response_string_mismatch | 1 |The option `response_string_match` was used, and the body of the response didn't match the regex. HTTP errors with content in their body (like 4xx, 5xx) will trigger this error|
|body_read_error | 2 |The option `response_string_match` was used, but the plugin wasn't able to read the body of the response. Responses with empty bodies (like 3xx, HEAD, etc) will trigger this error. Or the option `response_body_field` was used and the content of the response body was not a valid utf-8. Or the size of the body of the response exceeded the `response_body_max_size` |
|connection_failed | 3 |Catch all for any network error not specifically handled by the plugin|
|timeout | 4 |The plugin timed out while awaiting the HTTP connection to complete|
|dns_error | 5 |There was a DNS error while attempting to connect to the host|
|response_status_code_mismatch | 6 |The option `response_status_code_match` was used, and the status code of the response didn't match the value.|
2018-03-09 06:55:59 +08:00
2021-11-25 02:56:55 +08:00
## Example Output
2016-03-31 15:33:28 +08:00
2023-04-04 19:43:49 +08:00
```text
2019-08-17 06:45:20 +08:00
http_response,method=GET,result=success,server=http://github.com,status_code=200 content_length=87878i,http_response_code=200i,response_time=0.937655534,result_code=0i,result_type="success" 1565839598000000000
2016-03-31 15:33:28 +08:00
```