Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
miniflux
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
TeDomum
miniflux
Commits
36d3b1e9
Commit
36d3b1e9
authored
3 years ago
by
Frédéric Guillot
Committed by
fguillot
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add database stats to Prometheus exporter
parent
012eb61c
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
metric/metric.go
+72
-0
72 additions, 0 deletions
metric/metric.go
storage/storage.go
+6
-2
6 additions, 2 deletions
storage/storage.go
with
78 additions
and
2 deletions
metric/metric.go
+
72
−
0
View file @
36d3b1e9
...
@@ -78,6 +78,62 @@ var (
...
@@ -78,6 +78,62 @@ var (
},
},
[]
string
{
"status"
},
[]
string
{
"status"
},
)
)
dbOpenConnectionsGauge
=
prometheus
.
NewGauge
(
prometheus
.
GaugeOpts
{
Namespace
:
"miniflux"
,
Name
:
"db_open_connections"
,
Help
:
"The number of established connections both in use and idle"
,
},
)
dbConnectionsInUseGauge
=
prometheus
.
NewGauge
(
prometheus
.
GaugeOpts
{
Namespace
:
"miniflux"
,
Name
:
"db_connections_in_use"
,
Help
:
"The number of connections currently in use"
,
},
)
dbConnectionsIdleGauge
=
prometheus
.
NewGauge
(
prometheus
.
GaugeOpts
{
Namespace
:
"miniflux"
,
Name
:
"db_connections_idle"
,
Help
:
"The number of idle connections"
,
},
)
dbConnectionsWaitCountGauge
=
prometheus
.
NewGauge
(
prometheus
.
GaugeOpts
{
Namespace
:
"miniflux"
,
Name
:
"db_connections_wait_count"
,
Help
:
"The total number of connections waited for"
,
},
)
dbConnectionsMaxIdleClosedGauge
=
prometheus
.
NewGauge
(
prometheus
.
GaugeOpts
{
Namespace
:
"miniflux"
,
Name
:
"db_connections_max_idle_closed"
,
Help
:
"The total number of connections closed due to SetMaxIdleConns"
,
},
)
dbConnectionsMaxIdleTimeClosedGauge
=
prometheus
.
NewGauge
(
prometheus
.
GaugeOpts
{
Namespace
:
"miniflux"
,
Name
:
"db_connections_max_idle_time_closed"
,
Help
:
"The total number of connections closed due to SetConnMaxIdleTime"
,
},
)
dbConnectionsMaxLifetimeClosedGauge
=
prometheus
.
NewGauge
(
prometheus
.
GaugeOpts
{
Namespace
:
"miniflux"
,
Name
:
"db_connections_max_lifetime_closed"
,
Help
:
"The total number of connections closed due to SetConnMaxLifetime"
,
},
)
)
)
// Collector represents a metric collector.
// Collector represents a metric collector.
...
@@ -95,6 +151,13 @@ func NewCollector(store *storage.Storage, refreshInterval int) *Collector {
...
@@ -95,6 +151,13 @@ func NewCollector(store *storage.Storage, refreshInterval int) *Collector {
prometheus
.
MustRegister
(
feedsGauge
)
prometheus
.
MustRegister
(
feedsGauge
)
prometheus
.
MustRegister
(
brokenFeedsGauge
)
prometheus
.
MustRegister
(
brokenFeedsGauge
)
prometheus
.
MustRegister
(
entriesGauge
)
prometheus
.
MustRegister
(
entriesGauge
)
prometheus
.
MustRegister
(
dbOpenConnectionsGauge
)
prometheus
.
MustRegister
(
dbConnectionsInUseGauge
)
prometheus
.
MustRegister
(
dbConnectionsIdleGauge
)
prometheus
.
MustRegister
(
dbConnectionsWaitCountGauge
)
prometheus
.
MustRegister
(
dbConnectionsMaxIdleClosedGauge
)
prometheus
.
MustRegister
(
dbConnectionsMaxIdleTimeClosedGauge
)
prometheus
.
MustRegister
(
dbConnectionsMaxLifetimeClosedGauge
)
return
&
Collector
{
store
,
refreshInterval
}
return
&
Collector
{
store
,
refreshInterval
}
}
}
...
@@ -116,5 +179,14 @@ func (c *Collector) GatherStorageMetrics() {
...
@@ -116,5 +179,14 @@ func (c *Collector) GatherStorageMetrics() {
for
status
,
count
:=
range
entriesCount
{
for
status
,
count
:=
range
entriesCount
{
entriesGauge
.
WithLabelValues
(
status
)
.
Set
(
float64
(
count
))
entriesGauge
.
WithLabelValues
(
status
)
.
Set
(
float64
(
count
))
}
}
dbStats
:=
c
.
store
.
DBStats
()
dbOpenConnectionsGauge
.
Set
(
float64
(
dbStats
.
OpenConnections
))
dbConnectionsInUseGauge
.
Set
(
float64
(
dbStats
.
InUse
))
dbConnectionsIdleGauge
.
Set
(
float64
(
dbStats
.
Idle
))
dbConnectionsWaitCountGauge
.
Set
(
float64
(
dbStats
.
WaitCount
))
dbConnectionsMaxIdleClosedGauge
.
Set
(
float64
(
dbStats
.
MaxIdleClosed
))
dbConnectionsMaxIdleTimeClosedGauge
.
Set
(
float64
(
dbStats
.
MaxIdleTimeClosed
))
dbConnectionsMaxLifetimeClosedGauge
.
Set
(
float64
(
dbStats
.
MaxLifetimeClosed
))
}
}
}
}
This diff is collapsed.
Click to expand it.
storage/storage.go
+
6
−
2
View file @
36d3b1e9
...
@@ -31,6 +31,10 @@ func (s *Storage) DatabaseVersion() string {
...
@@ -31,6 +31,10 @@ func (s *Storage) DatabaseVersion() string {
// Ping checks if the database connection works.
// Ping checks if the database connection works.
func
(
s
*
Storage
)
Ping
()
error
{
func
(
s
*
Storage
)
Ping
()
error
{
_
,
err
:=
s
.
db
.
Exec
(
`SELECT true`
)
return
s
.
db
.
Ping
()
return
err
}
// DBStats returns database statistics.
func
(
s
*
Storage
)
DBStats
()
sql
.
DBStats
{
return
s
.
db
.
Stats
()
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment