Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
icinga-checks
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
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IML Open Source
icinga-checks
Commits
1605cfd1
Commit
1605cfd1
authored
2 years ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Plain Diff
Merge branch '6010-check-pqsql' into 'master'
6010 check pqsql See merge request
!97
parents
dc009afc
496371b8
No related branches found
No related tags found
1 merge request
!97
6010 check pqsql
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
check_psqlserver
+18
-9
18 additions, 9 deletions
check_psqlserver
with
18 additions
and
9 deletions
check_psqlserver
+
18
−
9
View file @
1605cfd1
...
@@ -16,12 +16,13 @@
...
@@ -16,12 +16,13 @@
# 2023-06-07 v0.2 <axel.hahn@unibe.ch>
# 2023-06-07 v0.2 <axel.hahn@unibe.ch>
# 2023-06-08 v0.3 <axel.hahn@unibe.ch> show unknown if database connection fails
# 2023-06-08 v0.3 <axel.hahn@unibe.ch> show unknown if database connection fails
# 2023-06-08 v0.4 <axel.hahn@unibe.ch> get summary for cronflicts and problems
# 2023-06-08 v0.4 <axel.hahn@unibe.ch> get summary for cronflicts and problems
# 2023-06-09 v0.5 <axel.hahn@unibe.ch> deltaunit can be set as parameter
# ======================================================================
# ======================================================================
.
$(
dirname
$0
)
/inc_pluginfunctions
.
$(
dirname
$0
)
/inc_pluginfunctions
self_APPNAME
=
$(
basename
$0
|
tr
[
:lower:]
[
:upper:]
)
self_APPNAME
=
$(
basename
$0
|
tr
[
:lower:]
[
:upper:]
)
self_APPVERSION
=
0.
2
self_APPVERSION
=
0.
5
# --- other vars...
# --- other vars...
cfgfile
=
/etc/icingaclient/.psql.conf
cfgfile
=
/etc/icingaclient/.psql.conf
...
@@ -142,13 +143,15 @@ EOH
...
@@ -142,13 +143,15 @@ EOH
# render incremental counters from integer results of a given sql query
# render incremental counters from integer results of a given sql query
# global string out output of check
# global string out output of check
# param string database query
# param string database query
# param string time unit; one of sec|min; default: sec
function
renderCounters
(){
function
renderCounters
(){
local
_query
;
_query
=
"
$1
"
local
_query
;
_query
=
"
$1
"
local
_sDeltaUnit
;
_sDeltaUnit
=
${
2
:-
sec
}
local
_out
;
_out
=
$(
psql
-c
"
${
_query
}
"
2>&1
)
||
_queryFailed
local
_out
;
_out
=
$(
psql
-c
"
${
_query
}
"
2>&1
)
||
_queryFailed
local
_iCounter
;
typeset
-i
_iCounter
=
0
local
_iCounter
;
typeset
-i
_iCounter
=
0
local
_header
;
_header
=
$(
echo
"
${
_out
}
"
|
head
-1
|
tr
-d
' '
)
local
_header
;
_header
=
$(
echo
"
${
_out
}
"
|
head
-1
|
tr
-d
' '
)
local
_data
;
_data
=
$(
echo
"
${
_out
}
"
|
head
-3
|
tail
-1
|
tr
-d
' '
)
local
_data
;
_data
=
$(
echo
"
${
_out
}
"
|
head
-3
|
tail
-1
|
tr
-d
' '
)
local
_sDeltaUnit
;
_sDeltaUnit
=
sec
local
_iSpeed
;
typeset
-i
_iSpeed
=
0
local
_iSpeed
;
typeset
-i
_iSpeed
=
0
local
_sStoreid
;
_sStoreid
=
$(
md5sum
<<<
"
${
_query
}
"
|
awk
'{ print $1 }'
)
local
_sStoreid
;
_sStoreid
=
$(
md5sum
<<<
"
${
_query
}
"
|
awk
'{ print $1 }'
)
local
_iValue
;
typeset
-i
_iValue
local
_iValue
;
typeset
-i
_iValue
...
@@ -229,7 +232,11 @@ case "${sMode}" in
...
@@ -229,7 +232,11 @@ case "${sMode}" in
typeset
-i
iQOther
;
iQOther
=
$iQTotal
-
$iQActive
-
$iQIdle
-
$iQFastpath
typeset
-i
iQOther
;
iQOther
=
$iQTotal
-
$iQActive
-
$iQIdle
-
$iQFastpath
descr
=
"Running total:
$iQTotal
... active:
$iQActive
idle:
$iQIdle
fastpath:
$iQFastpath
other:
$iQOther
"
descr
=
"Running total:
$iQTotal
... active:
$iQActive
idle:
$iQIdle
fastpath:
$iQFastpath
other:
$iQOther
"
out
=
$(
grep
"^.[a-z]"
<<<
"
${
_out
}
"
|
cut
-c
1-150 |
tr
'|'
':'
)
typeset
-i
iMax
;
iMax
=
20
out
=
$(
grep
"^.[a-z]"
<<<
"
${
_out
}
"
|
cut
-c
1-150 |
tr
'|'
':'
|
head
-
${
iMax
}
)
if
[
${
iQTotal
}
-gt
${
iMax
}
]
;
then
out+
=
"
${
NL
}
(showing
${
iMax
}
of
${
iQTotal
}
lines)
${
NL
}
"
fi
ph.perfadd
"running-total"
"
${
iQTotal
}
"
ph.perfadd
"running-total"
"
${
iQTotal
}
"
ph.perfadd
"running-active"
"
${
iQActive
}
"
ph.perfadd
"running-active"
"
${
iQActive
}
"
ph.perfadd
"running-idle"
"
${
iQIdle
}
"
ph.perfadd
"running-idle"
"
${
iQIdle
}
"
...
@@ -238,6 +245,7 @@ case "${sMode}" in
...
@@ -238,6 +245,7 @@ case "${sMode}" in
;;
;;
"conflicts"
)
"conflicts"
)
deltaunit
=
min
descr
=
"Detected conflicts (from pg_stat_database_conflicts)"
descr
=
"Detected conflicts (from pg_stat_database_conflicts)"
renderCounters
"select
\
renderCounters
"select
\
sum(confl_tablespace) as confl_tablespace,
\
sum(confl_tablespace) as confl_tablespace,
\
...
@@ -245,14 +253,14 @@ case "${sMode}" in
...
@@ -245,14 +253,14 @@ case "${sMode}" in
sum(confl_snapshot) as confl_snapshot,
\
sum(confl_snapshot) as confl_snapshot,
\
sum(confl_bufferpin) as confl_bufferpin,
\
sum(confl_bufferpin) as confl_bufferpin,
\
sum(confl_deadlock) as confl_deadlock
\
sum(confl_deadlock) as confl_deadlock
\
from pg_stat_database_conflicts "
from pg_stat_database_conflicts "
"
${
deltaunit
}
"
# sum of 7th column (with delta per sec)
# sum of 7th column (with delta per sec)
typeset
-i
iTotal
;
iTotal
=
$(
echo
"
$out
"
|
awk
'{ sum+=$7} END { print sum;}'
)
typeset
-i
iTotal
;
iTotal
=
$(
echo
"
$out
"
|
awk
'{ sum+=$7} END { print sum;}'
)
if
[
$iTotal
-gt
0
]
;
then
if
[
$iTotal
-gt
0
]
;
then
ph.setStatus
"
warning
"
ph.setStatus
"
critical
"
fi
fi
descr+
=
" - currently
$iTotal
per
sec
"
descr+
=
" - currently
$iTotal
per
${
deltaunit
}
"
;;
;;
"dbrows"
)
"dbrows"
)
...
@@ -275,6 +283,7 @@ case "${sMode}" in
...
@@ -275,6 +283,7 @@ case "${sMode}" in
;;
;;
"problems"
)
"problems"
)
deltaunit
=
min
descr
=
"Problems and troublemakers (from pg_stat_database)"
descr
=
"Problems and troublemakers (from pg_stat_database)"
renderCounters
"select
\
renderCounters
"select
\
sum(conflicts) as conflicts,
\
sum(conflicts) as conflicts,
\
...
@@ -282,14 +291,14 @@ case "${sMode}" in
...
@@ -282,14 +291,14 @@ case "${sMode}" in
sum(checksum_failures) as checksumfailures,
\
sum(checksum_failures) as checksumfailures,
\
sum(temp_files) as temp_files,
\
sum(temp_files) as temp_files,
\
sum(temp_bytes) as temp_bytes
\
sum(temp_bytes) as temp_bytes
\
from pg_stat_database "
from pg_stat_database
"
"
${
deltaunit
}
"
# sum of 7th column (with delta per sec)
# sum of 7th column (with delta per sec)
typeset
-i
iTotal
;
iTotal
=
$(
echo
"
$out
"
|
awk
'{ sum+=$7} END { print sum;}'
)
typeset
-i
iTotal
;
iTotal
=
$(
echo
"
$out
"
|
awk
'{ sum+=$7} END { print sum;}'
)
if
[
$iTotal
-gt
0
]
;
then
if
[
$iTotal
-gt
0
]
;
then
ph.setStatus
"
warning
"
ph.setStatus
"
critical
"
fi
fi
descr+
=
" - currently
$iTotal
per
sec
"
descr+
=
" - currently
$iTotal
per
${
deltaunit
}
"
;;
;;
"replication"
)
"replication"
)
...
...
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