|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Typesense\Requests; |
| 6 | + |
| 7 | +use Typesense\Objects\Metric; |
| 8 | +use Typesense\Objects\Stat; |
| 9 | + |
| 10 | +class Cluster extends Request |
| 11 | +{ |
| 12 | + /** |
| 13 | + * Creates a point-in-time snapshot of a Typesense node's state and data in the specified directory. |
| 14 | + * |
| 15 | + * @see https://typesense.org/docs/latest/api/cluster-operations.html#create-snapshot-for-backups |
| 16 | + */ |
| 17 | + public function snapshot(string $path): bool |
| 18 | + { |
| 19 | + $path = sprintf('/operations/snapshot?snapshot_path=%s', $path); |
| 20 | + |
| 21 | + $data = $this->send('POST', $path); |
| 22 | + |
| 23 | + return $data->success; |
| 24 | + } |
| 25 | + |
| 26 | + /** |
| 27 | + * Compacting the on-disk database. |
| 28 | + * |
| 29 | + * @see https://typesense.org/docs/latest/api/cluster-operations.html#compacting-the-on-disk-database |
| 30 | + */ |
| 31 | + public function compact(): bool |
| 32 | + { |
| 33 | + $data = $this->send('POST', '/operations/db/compact'); |
| 34 | + |
| 35 | + return $data->success; |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * Triggers a follower node to initiate the raft voting process, which triggers leader re-election. |
| 40 | + * |
| 41 | + * @see https://typesense.org/docs/latest/api/cluster-operations.html#re-elect-leader |
| 42 | + */ |
| 43 | + public function reElectLeader(): bool |
| 44 | + { |
| 45 | + $data = $this->send('POST', '/operations/vote'); |
| 46 | + |
| 47 | + return $data->success; |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * Enable logging of requests that take over a defined threshold of time. |
| 52 | + * |
| 53 | + * @see https://typesense.org/docs/latest/api/cluster-operations.html#toggle-slow-request-log |
| 54 | + */ |
| 55 | + public function updateSlowRequestLog(int $ms): bool |
| 56 | + { |
| 57 | + $data = $this->send('POST', '/config', [ |
| 58 | + 'log-slow-requests-time-ms' => $ms, |
| 59 | + ]); |
| 60 | + |
| 61 | + return $data->success; |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * Get current RAM, CPU, Disk & Network usage metrics. |
| 66 | + * |
| 67 | + * @see https://typesense.org/docs/latest/api/cluster-operations.html#cluster-metrics |
| 68 | + */ |
| 69 | + public function metrics(): Metric |
| 70 | + { |
| 71 | + $data = $this->send('GET', '/metrics.json'); |
| 72 | + |
| 73 | + return Metric::from($data); |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * Get stats about API endpoints. |
| 78 | + * |
| 79 | + * @see https://typesense.org/docs/latest/api/cluster-operations.html#api-stats |
| 80 | + */ |
| 81 | + public function stats(): Stat |
| 82 | + { |
| 83 | + $data = $this->send('GET', '/stats.json'); |
| 84 | + |
| 85 | + return Stat::from($data); |
| 86 | + } |
| 87 | + |
| 88 | + /** |
| 89 | + * Get health information about a Typesense node. |
| 90 | + * |
| 91 | + * @see https://typesense.org/docs/latest/api/cluster-operations.html#health |
| 92 | + */ |
| 93 | + public function health(): bool |
| 94 | + { |
| 95 | + $data = $this->send('GET', '/health'); |
| 96 | + |
| 97 | + return $data->ok; |
| 98 | + } |
| 99 | +} |
0 commit comments