- Built my first metric exporter using Go and Prometheus.
- Created a simple HTTP server that exposes metrics to count the number of requests made to the
/ping
endpoint. - The server runs on port 8090 and the metrics can be viewed at
localhost:8090/metrics
. - The metrics can be filtered and viewed in Prometheus at
localhost:9090/
. - I created a dashboard using Grafana for
ping request count
- Added an alert manager to raise an alert when the ping exceeds beyond 5 and configured a webhook receiver for that.
-
Clone this repository, using the following command:
git clone https://github.com/0xt3j4s/prometheus-http.git cd prometheus-http
-
Build the server
go build server.go
-
Run the server
./server
-
To check if the server is running, open the following URL in your browser: http://localhost:8090/ping and then poggers.
-
To view the metrics, open the following URL in your browser: http://localhost:8090/metrics.
-
Run prometheus using the following command:
prometheus --config.file=prometheus.yml
-
Visit http://localhost:9090/ and then plot a graph using the expression
ping_request_count
over the last 1 minute (or any other duration). -
Run the Alert Manager using the following command:
alertmanager --config.file=alertmanager.yml
-
Visit
localhost:9093/
[Alert Manager] and click on theAlerts
tab to view the alert.
-
The following output is displayed when the server is running:
- In the terminal:
Server is listening on port 8090...
- In the browser:
-
The following output is displayed when the metrics are viewed:
- In the browser:
-
The following graph can be viewed in Prometheus:
- Visit
localhost:9090/
and plot a graph after entering the expressionping_request_count
over the last 1 minute (or any other duration):
- Visit
-
The following dashboard can be viewed in Grafana:
- Visit
localhost:3000/
and login with the credentialsadmin:admin
and then import the dashboardping_request_count.json
from thedashboards
folder:
- Visit
-
The following alert with status
FIRING
can be viewed in the webhook receiver. -
The alert can be also be viewed in the Alert Manager:
-
Visit
localhost:9093/
[Alert Manager] and click on theAlerts
tab to view the alert:
If you found it useful to get started with Prometheus, please consider giving it a star (⭐).
Contributions are welcome! If you find any issues or have suggestions for improvement, please create an issue or submit a pull request.
- Create a Fork
- Clone your fork
- Create a new branch
- Make your changes
- Commit and push
- Create a pull request
This project is licensed under the MIT License. See the LICENSE file for details.