-
Notifications
You must be signed in to change notification settings - Fork 100
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
WIP: Implement Prometheus statser #355
Closed
Closed
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
01c6b02
Setup a barebone http server with the prometheus handler
6e54078
Create prom statser file and create the the Prometheus Statser embede…
110e0c5
Create skeleton methods from the statser interface for prom statser
fa95d00
Implement all methods for prom statser
d629631
Create prom statser in createStatser
a05c8e1
Add statser as an argument to NewHttpServer and the respective funcs …
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package web | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"log" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/client_golang/prometheus/promhttp" | ||
) | ||
|
||
// TODO: now I have setup the Prometheus metric objects, how do I integrate with gostatsd internal metrics measuring | ||
// tools? How do I run this file, and start writing some tests for this. Need to adhere to the project testing styles. | ||
func start() { | ||
counter := prometheus.NewCounter( | ||
prometheus.CounterOpts{ | ||
Namespace: "gostatsd", | ||
Name: "HTTP requests counter", | ||
Help: "An internal counter, reset on flush. It currently measure HTTP metrics such as http.forwarder.invalid, http.incoming etc.", | ||
}) | ||
|
||
// gauges | ||
gaugeFlush := prometheus.NewGauge( | ||
prometheus.GaugeOpts{ | ||
Namespace: "gostatsd", | ||
Name: "gauge (flush)", | ||
Help: "A value sent as a gauge with the value reset / calculated / sampled every flush interval", | ||
}) | ||
|
||
gaugeTime := prometheus.NewGauge( | ||
prometheus.GaugeOpts{ | ||
Namespace: "gostatsd", | ||
Name: "gauge (time)", | ||
Help: "A single duration measured in milliseconds and sent as a gauge", | ||
}) | ||
|
||
gaugeCumulative := prometheus.NewGauge( | ||
prometheus.GaugeOpts{ | ||
Namespace: "gostatsd", | ||
Name: "gauge (cumulative)", | ||
Help: "An internal counter sent as a gauge with the value never resetting", | ||
}) | ||
|
||
gaugeSparse := prometheus.NewGauge( | ||
prometheus.GaugeOpts{ | ||
Namespace: "gostatsd", | ||
Name: "gauge (sparse)", | ||
Help: "The same as a cumulative gauge, but data is only sent on change", | ||
}) | ||
|
||
http.Handle("/metrics", promhttp.Handler()) | ||
|
||
prometheus.MustRegister(counter) | ||
|
||
prometheus.MustRegister(gaugeFlush) | ||
prometheus.MustRegister(gaugeTime) | ||
prometheus.MustRegister(gaugeCumulative) | ||
prometheus.MustRegister(gaugeSparse) | ||
|
||
port := 8080 | ||
|
||
log.Printf("Listening on port: %d\n", port) | ||
|
||
log.Fatal(http.ListenAndServe(fmt.Sprintf("%d", port), nil)) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The expected interface is a
stats.Statser
(https://github.com/atlassian/gostatsd/blob/master/pkg/stats/statser.go), and you can embed astats.flushNotifier
to take care of theRegisterFlush
andNotifyFlush
calls.You'll likely need to lazily create metrics on-demand and store them in a map - gostatsd doesn't have any arbitrary metrics, so you don't need to worry about removing things from the map. The map can be protected with an RWMutex, since after warmup, it will be very rare (if ever), that additional metrics are created.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, there's basically no testing of the actual Statsers. There is a bit for
pkg/web
, but it's acceptable to just make sure you get a 200 return code when it's expected.