Skip to content

Commit c0126ce

Browse files
committed
Refactor OTLPMetricsClient to use aggregations
1 parent e92aedc commit c0126ce

8 files changed

Lines changed: 133 additions & 95 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ This module requires the frontend module:
88

99
- https://github.com/NETWAYS/icingaweb2-module-perfdatagraphs
1010

11+
## Known Issues
12+
13+
> too_many_buckets_exception
14+
15+
Lower the `max_data_points` so that less buckets are calculated or reduce the number of metrics being fetched via the `metrics_include/exclude` settings.
16+
1117
## Installation Requirements
1218

1319
* PHP version ≥ 8.0

application/forms/PerfdataGraphsElasticsearchConfigForm.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,18 @@ public function createElements(array $formData)
7373
'description' => t('Skip the TLS verification'),
7474
'label' => t('Skip the TLS verification')
7575
]);
76+
77+
$this->addElement('number', 'elasticsearch_api_max_data_points', [
78+
'label' => t('The maximum numbers of datapoints each series returns'),
79+
'description' => t(' '),
80+
'description' => t(
81+
'The maximum numbers of datapoints each series returns.'
82+
. ' The module will use an aggregations query to downsample to this number.'
83+
. ' You can disable aggregation by setting this to 0.'
84+
),
85+
'required' => false,
86+
'placeholder' => 5000,
87+
]);
7688
}
7789

7890
public function addSubmitButton()
@@ -160,10 +172,7 @@ public static function validateFormData($form): array
160172
$password = $form->getValue('elasticsearch_api_password', '');
161173
$index = $form->getValue('elasticsearch_api_index', 'icinga2');
162174
$tlsVerify = (bool) $form->getValue('elasticsearch_api_tls_insecure', false);
163-
164-
// TODO: Not yet implemented
165-
$maxDataPoints = 10000;
166-
// $maxDataPoints = $form->getValue('elasticsearch_max_data_points', 10000);
175+
$maxDataPoints = (int) $form->getValue('elasticsearch_api_max_data_points', 10000);
167176

168177
$writer = $form->getValue('elasticsearch_icinga_writer', '');
169178

library/Perfdatagraphselasticsearch/Client/BaseClient.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,14 @@
2222
abstract class BaseClient
2323
{
2424
protected Transport $transport;
25-
26-
// TODO: Currently unused
2725
protected int $maxDataPoints;
2826

2927
/**
3028
* parseDuration parses the duration string from the frontend
3129
* into something we can use with the API (from parameter).
3230
*
3331
* @param string $duration ISO8601 Duration
34-
* @param string $now current time (used in testing)
32+
* @param DateTime $now current time (used in testing)
3533
* @return string
3634
*/
3735
public function parseDuration(\DateTime $now, string $duration): string

library/Perfdatagraphselasticsearch/Client/ESInterface.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ public function fetchMetrics(
1919
bool $isHostCheck,
2020
array $includeMetrics,
2121
array $excludeMetrics,
22+
int $checkInterval
2223
): PerfdataResponse;
2324
}

library/Perfdatagraphselasticsearch/Client/ElasticsearchClient.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
use Icinga\Application\Logger;
1414
use Icinga\Util\Json;
1515

16-
use GuzzleHttp\Client;
16+
use DateTime;
1717
use Exception;
18+
use GuzzleHttp\Client;
1819

1920
/**
2021
* ElasticsearchClient is used with with Icinga2 ElasticsearchWriter
@@ -63,7 +64,7 @@ public static function fromConfig(Config $moduleConfig = null): ESInterface
6364
'api_url' => 'http://localhost:9200',
6465
'api_index' => 'icinga2',
6566
'api_timeout' => 10,
66-
'api_max_data_points' => 10000,
67+
'api_max_data_points' => 5000,
6768
'api_username' => '',
6869
'api_password' => '',
6970
'api_tls_insecure' => false,
@@ -83,11 +84,11 @@ public static function fromConfig(Config $moduleConfig = null): ESInterface
8384
$baseURI = rtrim($moduleConfig->get('elasticsearch', 'api_url', $default['api_url']), '/');
8485
$index = rtrim($moduleConfig->get('elasticsearch', 'api_index', $default['api_index']), 'icinga2');
8586
$timeout = (int) $moduleConfig->get('elasticsearch', 'api_timeout', $default['api_timeout']);
86-
$maxDataPoints = (int) $moduleConfig->get('elasticsearch', 'api_max_data_points', $default['api_max_data_points']);
8787
$username = $moduleConfig->get('elasticsearch', 'api_username', $default['api_username']);
8888
$password = $moduleConfig->get('elasticsearch', 'api_password', $default['api_password']);
8989
// Hint: We use a "skip TLS" logic in the UI, but Guzzle uses "verify TLS"
9090
$tlsVerify = !(bool) $moduleConfig->get('elasticsearch', 'api_tls_insecure', $default['api_tls_insecure']);
91+
$maxDataPoints = (int) $moduleConfig->get('elasticsearch', 'api_max_data_points', $default['api_max_data_points']);
9192

9293
return new static($baseURI, $username, $password, $maxDataPoints, $timeout, $tlsVerify, $index);
9394
}
@@ -126,7 +127,11 @@ public function fetchMetrics(
126127
bool $isHostCheck,
127128
array $includeMetrics,
128129
array $excludeMetrics,
130+
int $checkInterval = 0
129131
): PerfdataResponse {
132+
$now = new DateTime();
133+
$from = $this->parseDuration($now, $from);
134+
130135
$params = [
131136
'size' => 2000,
132137
'sort' => '@timestamp:asc',

0 commit comments

Comments
 (0)