Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add probe_http_uncompressed_body_length metric #535

Merged

Conversation

strangeman
Copy link
Contributor

Partial solution for #337

I think this is a suitable solution for cases "we need to monitor the size of very important page and alert when it dramatically changed". I just get the size of the response body (which transparently decompressed by http.Response) and expose it.

Page with disabled compression:

http://localhost:9115/probe?target=example.com&module=http_2xx

# HELP probe_http_content_length Length of http content response
# TYPE probe_http_content_length gauge
probe_http_content_length 1270
# HELP probe_http_uncompressed_body_length Length of uncompressed response body
# TYPE probe_http_uncompressed_body_length gauge
probe_http_uncompressed_body_length 1270

Page with enabled compression:

http://localhost:9115/probe?target=github.com&module=http_2xx

# HELP probe_http_content_length Length of http content response
# TYPE probe_http_content_length gauge
probe_http_content_length -1

# HELP probe_http_uncompressed_body_length Length of uncompressed response body
# TYPE probe_http_uncompressed_body_length gauge
probe_http_uncompressed_body_length 134683

Nonexistent site:

http://localhost:9115/probe?target=notexistent.site&module=http_2xx

# HELP probe_http_content_length Length of http content response
# TYPE probe_http_content_length gauge
probe_http_content_length 0

# HELP probe_http_uncompressed_body_length Length of uncompressed response body
# TYPE probe_http_uncompressed_body_length gauge
probe_http_uncompressed_body_length 0

# HELP probe_success Displays whether or not the probe was a success
# TYPE probe_success gauge
probe_success 0

@strangeman strangeman force-pushed the uncompressed-body-length branch from d2b3437 to a0fbbc4 Compare October 7, 2019 05:43
prober/http.go Outdated
@@ -406,7 +412,8 @@ func ProbeHTTP(ctx context.Context, target string, module config.Module, registr
}

if resp != nil && !requestErrored {
_, err = io.Copy(ioutil.Discard, resp.Body)
buf := &bytes.Buffer{}
respBodyBytes, err = io.Copy(buf, resp.Body)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not keep using ioutil.Discard?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. I misunderstood the documentation.

@strangeman strangeman force-pushed the uncompressed-body-length branch 2 times, most recently from a1e6afe to 88c56f1 Compare October 8, 2019 01:13
@strangeman strangeman force-pushed the uncompressed-body-length branch from 88c56f1 to 363c9d8 Compare October 8, 2019 01:15
@brian-brazil brian-brazil merged commit e745ebb into prometheus:master Oct 8, 2019
@brian-brazil
Copy link
Contributor

Thanks!

@strangeman strangeman deleted the uncompressed-body-length branch October 8, 2019 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants