PHP - RRD rrd_tune() 函式



PHP RRD 的 rrd_tune() 函式用於修改現有 RRD 的屬性。成功時返回 true,失敗時返回 false。

語法

以下是 PHP RRD rrd_tune() 函式的語法:

bool rrd_tune(string $filename, array $options)

引數

以下是 rrd_tune() 函式的引數:

  • $filename − 要調整的 RRD 檔案的路徑。

  • $options − 一個選項陣列,用於選擇要進行的 RRD 檔案更改。

返回值

此函式在成功時返回 TRUE,失敗時返回 FALSE。

PHP 版本

rrd_tune() 函式從 PECL rrd 擴充套件的 0.9.0 版本開始可用。

示例 1

首先,我們將向您展示 PHP RRD rrd_tune() 函式更改給定資料來源的最小值和最大值的示例。

<?php
   // Mention the file name here
   $filename = '/PHP/PhpProjects/example.rrd';
   $options = [
       '--minimum', 'data_source_name:0',
       '--maximum', 'data_source_name:100'
   ];
   
   if (rrd_tune($filename, $options)) {
       echo "RRD file tuned successfully.";
   } else {
       echo "Failed to tune RRD file.";
   }
?>

輸出

以上程式碼將產生類似以下的結果:

RRD file tuned successfully.

示例 2

在下面的 PHP 程式碼中,我們將使用 rrd_tune() 函式並更改允許在資料來源的兩次更新之間經過的最大時間量。

<?php
   // Mention the file name here
   $filename = '/PHP/PhpProjects/example.rrd';
   $options = [
       '--heartbeat', 'data_source_name:600'
   ];
   
   if (rrd_tune($filename, $options)) {
       echo "Maximum amount of time has changed successfully.";
   } else {
       echo "Failed to change maximum amount of time.";
   }
?> 

輸出

執行上述程式後,它將生成以下輸出:

Maximum amount of time has changed successfully.

示例 3

現在,以下程式碼使用 rrd_tune() 函式將新的資料來源新增到 RRD 檔案中。

<?php
   // Mention the file name here
   $filename = '/PHP/PhpProjects/example.rrd';
   $options = [
       '--add-ds', 'new_data_source:GAUGE:600:0:U'
   ];
   
   if (rrd_tune($filename, $options)) {
       echo "New data source has been added successfully.";
   } else {
       echo "Failed to add new data source.";
   }
?> 

輸出

這將建立以下輸出:

New data source has been added successfully.

示例 4

在以下示例中,我們使用 rrd_tune() 函式從 RRD 檔案中刪除現有的資料來源。

<?php
   // Mention the file name here
   $filename = '/PHP/PhpProjects/example.rrd';
   $options = [
       '--remove-ds', 'data_source_name'
   ];
   
   if (rrd_tune($filename, $options)) {
       echo "Data source has been removed successfully.";
   } else {
       echo "Failed to remove data source.";
   }
?> 

輸出

執行上述程式時,它將產生以下輸出:

Data source has been removed successfully.

重要說明

以上示例展示了 rrd_tune() 函式的主要用例,包括新增、刪除和更改當前資料來源。

php_function_reference.htm
廣告