Go application provides an HTTP server for storing and serving Prometheus metrics. The server supports four types of metrics: gauges, counters, histograms, and summaries. Metrics can be stored by sending POST requests to specific endpoints, and they can be accessed via the /metrics
endpoint.
It suppose to be used in a stateless environment where you can't store metrics in memory between requests. This server will store the metrics in memory and expose them in Prometheus format.
This Prometheus Metrics Server is ideal for languages like PHP, which lack persistent memory and shared state between requests
Send order metrics from a PHP e-commerce platform to the server. The server aggregates these metrics, making them available to Prometheus for real-time monitoring and alerts, ensuring efficient metrics management in stateless environments.
- Go 1.22.3 or higher
- Prometheus client library for Go
-
Clone the repository:
git clone https://github.com/synaxz/metrics-server.git cd metrics-server
-
Install dependencies:
go mod tidy
-
Build the application:
go build -o metrics-server
-
Run the application:
./metrics-server
- Endpoint:
/store/gauge
- Method: POST
- Payload:
{ "key": "gauge_metric", "value": 10, "labels": {"env": "prod"}, "help": "Gauge metric", "action": "set" }
- Actions:
set
,inc
,dec
,add
,sub
- Curl Command:
curl -X POST -d '{ "key": "gauge_metric", "value": 10, "labels": {"env": "prod"}, "help": "Gauge metric", "action": "set" }' http://localhost:8080/store/gauge
- Endpoint:
/store/counter
- Method: POST
- Payload:
{ "key": "counter_metric", "value": 1, "labels": {"env": "prod"}, "help": "Counter metric", "action": "inc" }
- Actions:
inc
,add
- Curl Command:
curl -X POST -d '{ "key": "counter_metric", "value": 1, "labels": {"env": "prod"}, "help": "Counter metric", "action": "inc" }' http://localhost:8080/store/counter
- Endpoint:
/store/histogram
- Method: POST
- Payload:
{ "key": "histogram_metric", "value": 10, "labels": {"env": "prod"}, "help": "Histogram metric", "action": "observe" }
- Actions:
observe
- Curl Command:
curl -X POST -d '{ "key": "histogram_metric", "value": 10, "labels": {"env": "prod"}, "help": "Histogram metric", "action": "observe" }' http://localhost:8080/store/histogram
- Endpoint:
/store/summary
- Method: POST
- Payload:
{ "key": "summary_metric", "value": 10, "labels": {"env": "prod"}, "help": "Summary metric", "action": "observe" }
- Actions:
observe
- Curl Command:
curl -X POST -d '{ "key": "summary_metric", "value": 10, "labels": {"env": "prod"}, "help": "Summary metric", "action": "observe" }' http://localhost:8080/store/summary
- Endpoint:
/metrics
- Method: GET
- Description: Returns all stored metrics in Prometheus format.
Open your browser and navigate to http://localhost:8080/metrics
to view all the stored metrics.
Contributions are welcome! Please open an issue or submit a pull request.
This project is licensed under the MIT License.