first commit

This commit is contained in:
2024-08-22 14:05:05 +09:00
commit 1ab0d83941
34 changed files with 4083 additions and 0 deletions

1
grafana-docker/php-example/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
vendor/

View File

@@ -0,0 +1,6 @@
{
"require": {
"league/statsd": "^1.5",
"ext-pcntl": "*"
}
}

79
grafana-docker/php-example/composer.lock generated Normal file
View File

@@ -0,0 +1,79 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "54a6353042ab1f33202309a7a67786a2",
"packages": [
{
"name": "league/statsd",
"version": "1.5.0",
"source": {
"type": "git",
"url": "https://github.com/thephpleague/statsd.git",
"reference": "c6290ef6c7528b7b739b26ce6aedf81ee6a4a2ac"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/thephpleague/statsd/zipball/c6290ef6c7528b7b739b26ce6aedf81ee6a4a2ac",
"reference": "c6290ef6c7528b7b739b26ce6aedf81ee6a4a2ac",
"shasum": ""
},
"require-dev": {
"phpunit/phpunit": "^5.7 || ^6.5"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"League\\StatsD\\Laravel5\\Provider\\StatsdServiceProvider"
],
"aliases": {
"Statsd": "League\\StatsD\\Laravel5\\Facade\\StatsdFacade"
}
}
},
"autoload": {
"psr-4": {
"League\\StatsD\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Marc Qualie",
"email": "marc@marcqualie.com",
"homepage": "http://marcqualie.com",
"role": "Developer"
}
],
"description": "A simple library for working with StatsD in PHP.",
"homepage": "https://github.com/thephpleague/statsd",
"keywords": [
"graphite",
"library",
"statsd"
],
"support": {
"issues": "https://github.com/thephpleague/statsd/issues",
"source": "https://github.com/thephpleague/statsd/tree/1.5.0"
},
"time": "2018-10-09T16:02:46+00:00"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": {
"ext-pcntl": "*"
},
"platform-dev": [],
"plugin-api-version": "2.1.0"
}

View File

@@ -0,0 +1,48 @@
<?php
declare(strict_types=1);
require __DIR__ . '/vendor/autoload.php';
$statsd = new League\StatsD\Client();
$statsd->configure([
'host' => '127.0.0.1',
'port' => 8125,
'namespace' => 'performance'
]);
$ops = 0;
$requestsSent = 0;
$startTime = microtime(true);
pcntl_async_signals(true);
pcntl_signal(SIGINT, static function () use (&$ops, $startTime, &$requestsSent) {
$runtime = microtime(true) - $startTime;
$opsPerSecond = $ops / $runtime;
$requestsPerSecond = $requestsSent / $runtime;
echo PHP_EOL;
echo "Runtime:\t${runtime} Seconds\n";
echo "Ops:\t\t${ops} \n";
echo "Ops/s:\t\t${opsPerSecond} \n";
echo "Requests Sent:\t${requestsSent} \n";
echo "Requests/s:\t${requestsPerSecond} \n";
echo "Killed by Ctrl+C\n";
exit(0);
});
echo "Sending Random metrics. Use Ctrl+C to stop.\n";
while (true) {
$time = random_int(100, 400);
$types = ['search', 'book', 'login', 'login'];
$type = $types[random_int(0 , 3)];
$delta = random_int(1, 5);
$statsd->increment('request.successful.count,type=' . $type, $delta);
$statsd->timing('request.successful.time,type=' . $type, $time);
$requestsSent += $delta;
++$ops;
usleep(random_int(5, 55) * 1000);
echo '.';
}