Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mevdschee/php-observability
High frequency logging in PHP and aggregating into metrics using Go
https://github.com/mevdschee/php-observability
logging metrics observability php prometheus
Last synced: 3 months ago
JSON representation
High frequency logging in PHP and aggregating into metrics using Go
- Host: GitHub
- URL: https://github.com/mevdschee/php-observability
- Owner: mevdschee
- License: mit
- Created: 2024-09-17T09:14:25.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-10-30T01:22:51.000Z (4 months ago)
- Last Synced: 2024-10-30T03:53:51.355Z (4 months ago)
- Topics: logging, metrics, observability, php, prometheus
- Language: Go
- Homepage:
- Size: 51.8 KB
- Stars: 6
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# php-observability
A code base to showcase high frequency logging in PHP and aggregating into metrics using Go. Read the blog post:
[https://tqdev.com/2024-high-frequency-metrics-in-php-using-tcp-sockets](https://tqdev.com/2024-high-frequency-metrics-in-php-using-tcp-sockets)
and
[https://tqdev.com/2024-distributed-metrics-in-php-using-go-and-gob](https://tqdev.com/2024-distributed-metrics-in-php-using-go-and-gob)
### Requirements
- PHP 8 or higher (see special PHP 5/7 compatible version)
- Go 1.22 build environment### Usage
To run the server:
go run .
In bash run:
for run in {1..100}; do php writer.php & done
And to stop:
killall php
Now observe the metrics:
http://localhost:8080/
NB: The metrics are Prometheus compatible and follow the [OpenMetrics specification](https://github.com/OpenObservability/OpenMetrics/).
The metrics are also served in the Gob binary format on:
http://localhost:9999/
This endpoint can be scraped by other tools such as [metrics-db-importer](https://github.com/mevdschee/metrics-db-importer) or this tool itself to aggregate the metrics of multiple nodes (using the "-scrape" parameter).
### Example metrics
Here is an example of published metrics:
# HELP database_calls_seconds A summary of the database calls.
# TYPE database_calls_seconds summary
database_calls_seconds_count{file="src/Controller/UserController.php@L123"} 6630
database_calls_seconds_sum{file="src/Controller/UserController.php@L123"} 947.142
# HELP database_calls_total_seconds A histogram of the database calls.
# TYPE database_calls_total_seconds histogram
database_calls_total_seconds_bucket{le="0.005"} 0
database_calls_total_seconds_bucket{le="0.01"} 0
database_calls_total_seconds_bucket{le="0.025"} 0
database_calls_total_seconds_bucket{le="0.05"} 0
database_calls_total_seconds_bucket{le="0.1"} 0
database_calls_total_seconds_bucket{le="0.25"} 6630
database_calls_total_seconds_bucket{le="0.5"} 6630
database_calls_total_seconds_bucket{le="1"} 6630
database_calls_total_seconds_bucket{le="2.5"} 6630
database_calls_total_seconds_bucket{le="5"} 6630
database_calls_total_seconds_bucket{le="10"} 6630
database_calls_total_seconds_bucket{le="+Inf"} 6630
database_calls_total_seconds_sum 947.142
database_calls_total_seconds_count 6630Enjoy!