Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
prometheus_exporter
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
prometheus_exporter
Merge requests
!5
Issue
#3205502
: Add a flood table record metric
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
Issue
#3205502
: Add a flood table record metric
issue/prometheus_exporter-3205502:3205502-add-a-flood
into
8.x-1.x
Overview
0
Commits
1
Pipelines
0
Changes
1
Open
Marcus Deglos
requested to merge
issue/prometheus_exporter-3205502:3205502-add-a-flood
into
8.x-1.x
4 years ago
Overview
0
Commits
1
Pipelines
0
Changes
1
Expand
0
0
Merge request reports
Compare
8.x-1.x
8.x-1.x (HEAD)
and
latest version
latest version
401b3834
1 commit,
4 years ago
1 file
+
93
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
src/Plugin/MetricsCollector/FloodCountCollector.php
0 → 100644
+
93
−
0
Options
<?php
namespace
Drupal\prometheus_exporter\Plugin\MetricsCollector
;
use
Drupal\Core\Database\Connection
;
use
Drupal\Core\Flood\DatabaseBackend
;
use
Drupal\Core\Plugin\ContainerFactoryPluginInterface
;
use
Drupal\prometheus_exporter
\Plugin\BaseMetricsCollector
;
use
PNX\Prometheus\Gauge
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
/**
* Collects metrics for the number of Flood entries.
*
* @MetricsCollector(
* id = "flood_count",
* title = @Translation("Flood count"),
* description = @Translation("Provides metrics for the number of Flood entries.")
* )
*/
class
FloodCountCollector
extends
BaseMetricsCollector
implements
ContainerFactoryPluginInterface
{
/**
* The PDO database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected
$connection
;
/**
* FloodCountCollector constructor.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Database\Connection $connection
* The PDO database connection.
*/
public
function
__construct
(
array
$configuration
,
$plugin_id
,
$plugin_definition
,
Connection
$connection
)
{
parent
::
__construct
(
$configuration
,
$plugin_id
,
$plugin_definition
);
$this
->
connection
=
$connection
;
}
/**
* {@inheritdoc}
*/
public
static
function
create
(
ContainerInterface
$container
,
array
$configuration
,
$plugin_id
,
$plugin_definition
)
{
return
new
static
(
$configuration
,
$plugin_id
,
$plugin_definition
,
$container
->
get
(
'database'
)
);
}
/**
* {@inheritdoc}
*/
public
function
collectMetrics
()
{
$gauge
=
new
Gauge
(
$this
->
getNamespace
(),
'total'
,
$this
->
getDescription
());
foreach
(
$this
->
query
()
as
$event
=>
$count
)
{
$gauge
->
set
(
$count
,
[
'event'
=>
$event
]);
}
$metrics
[]
=
$gauge
;
return
$metrics
;
}
/**
* Query the number of records in the flood table.
*
* @return array
* Associative array of the number of events, keyed by the event type.
*/
protected
function
query
()
{
// The flood table is generated on-demand and may not exist.
if
(
!
$this
->
connection
->
schema
()
->
tableExists
(
DatabaseBackend
::
TABLE_NAME
))
{
return
[];
}
$query
=
$this
->
connection
->
select
(
DatabaseBackend
::
TABLE_NAME
,
'flood'
)
->
fields
(
'flood'
,
[
'event'
])
->
groupBy
(
'event'
);
$query
->
addExpression
(
'count(fid)'
,
'count'
);
return
$query
->
execute
()
->
fetchAllKeyed
(
0
,
1
);
}
}
Loading