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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IML Open Source
icinga-checks
Commits
57150384
Commit
57150384
authored
1 year ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
ph.toUnit - added 3rd param
parent
3a6765ea
Branches
Branches containing commit
No related tags found
1 merge request
!143
netio shows network speed 2 digits after "."
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
inc_pluginfunctions
+22
-12
22 additions, 12 deletions
inc_pluginfunctions
with
22 additions
and
12 deletions
inc_pluginfunctions
+
22
−
12
View file @
57150384
...
@@ -27,16 +27,17 @@
...
@@ -27,16 +27,17 @@
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
# 2016-09-23 added getOS
# 2016-09-23 added getOS
# 2019-10-29 added setExitcode
# 2019-10-29 added setExitcode
# 2020-03-05 v1.2 <axel.hahn@iml.unibe.ch> switch to ph.* helper functions
# 2020-03-05 v1.2 <axel.hahn@iml.unibe.ch> switch to ph.* helper functions
# 2020-09-01 v1.3 <axel.hahn@iml.unibe.ch> added ph.hasParamoption
# 2020-09-01 v1.3 <axel.hahn@iml.unibe.ch> added ph.hasParamoption
# 2022-08-31 v1.4 <axel.hahn@iml.unibe.ch> shellfix corrections
# 2022-08-31 v1.4 <axel.hahn@iml.unibe.ch> shellfix corrections
# 2022-10-25 v1.5 <axel.hahn@iml.unibe.ch> handle empty value in ph.perfadd
# 2022-10-25 v1.5 <axel.hahn@iml.unibe.ch> handle empty value in ph.perfadd
# 2023-01-30 v1.6 <axel.hahn@unibe.ch> check performance params 5+6 and show a warning if missing
# 2023-01-30 v1.6 <axel.hahn@unibe.ch> check performance params 5+6 and show a warning if missing
# 2023-02-16 v1.7 <axel.hahn@unibe.ch> adding a generic min and max value did not really help
# 2023-02-16 v1.7 <axel.hahn@unibe.ch> adding a generic min and max value did not really help
# 2023-04-24 v1.8 <axel.hahn@unibe.ch> fix unit conversion
# 2023-04-24 v1.8 <axel.hahn@unibe.ch> fix unit conversion
# 2023-05-05 v1.9 <axel.hahn@unibe.ch> user specific counter directory
# 2023-05-05 v1.9 <axel.hahn@unibe.ch> user specific counter directory
# 2023-05-17 v1.10 <axel.hahn@unibe.ch> ph.getOS searches in os-release first
# 2023-05-17 v1.10 <axel.hahn@unibe.ch> ph.getOS searches in os-release first
# 2023-06-22 v1.11 <axel.hahn@unibe.ch> fix ph.toUnit with float values; shell fixes
# 2023-06-22 v1.11 <axel.hahn@unibe.ch> fix ph.toUnit with float values; shell fixes
# 2023-08-24 v1.12 <axel.hahn@unibe.ch> toUnit got 3rd param for count of digits after "."
# ======================================================================
# ======================================================================
...
@@ -293,15 +294,24 @@ function ph._getExp(){
...
@@ -293,15 +294,24 @@ function ph._getExp(){
#
#
# param string value with optional single letter for unit, i.e. 12M
# param string value with optional single letter for unit, i.e. 12M
# param char target unit
# param char target unit
# param integer count of digits after "."; default: none (=integer value)
function
ph.toUnit
(){
function
ph.toUnit
(){
local
_value
=
$1
local
_value
=
$1
local
_unit
=
$2
local
_unit
=
$2
local
_digits
=
${
3
:-
0
}
local
_multiply
;
_multiply
=
$(
ph._getExp
"
$_value
"
)
local
_multiply
;
_multiply
=
$(
ph._getExp
"
$_value
"
)
local
_divisor
;
_divisor
=
$(
ph._getExp
"
$_unit
"
)
local
_divisor
;
_divisor
=
$(
ph._getExp
"
$_unit
"
)
# echo "DEBUG ... $_divisor .. $_multiply"
local
_bc
echo
"
$(
echo
"
$_value
"
|
tr
-d
"[:alpha:]"
)
*
${
_multiply
}
/
$_divisor
"
| bc
_bc
=
"bc"
local
_dots
test
$_digits
-gt
0
&&
_dots
=
$(
yes
"."
|
head
-
$_digits
|
tr
-d
"
\n
"
)
test
$_digits
-gt
0
&&
_bc+
=
" -l | grep -o '.*
\\
.
${
_dots
}
'"
echo
"
$(
echo
"
$_value
"
|
tr
-d
"[:alpha:]"
)
*
${
_multiply
}
/
$_divisor
"
|
eval
"
$_bc
"
|
sed
"s#^
\.
#0.#"
}
}
...
...
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