Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
OnGres Inc.
pgio
Commits
bc83e983
Commit
bc83e983
authored
Aug 23, 2018
by
Matteo Melli
Browse files
Show ignored errors only on debug mode
parent
16e70f20
Changes
3
Hide whitespace changes
Inline
Side-by-side
main/src/main/java/com/ongres/pgio/main/Main.java
View file @
bc83e983
...
...
@@ -119,6 +119,8 @@ public class Main {
"Interval in milliseconds to gather stats"
)
.
withRequiredArg
()
.
defaultsTo
(
"3000"
);
parser
.
acceptsAll
(
Lists
.
newArrayList
(
"d"
,
"debug"
),
"Show debug messages"
);
parser
.
acceptsAll
(
Lists
.
newArrayList
(
"s"
,
"show-system"
),
"Print read/write data for the whole system"
);
parser
.
acceptsAll
(
Lists
.
newArrayList
(
"o"
,
"show-other"
),
...
...
@@ -158,6 +160,7 @@ public class Main {
configHelper
.
setIf
(
"show-other"
,
configBuilder:
:
withShowOther
);
configHelper
.
set
(
"group"
,
Main:
:
readGroupConfig
,
configBuilder:
:
appendProcessGroups
);
configHelper
.
setIf
(
"prometheus-format"
,
configBuilder:
:
withPrometheusFormat
);
configHelper
.
setIf
(
"debug"
,
configBuilder:
:
withDebug
);
Config
config
=
configBuilder
.
build
();
...
...
main/src/main/java/com/ongres/pgio/main/config/Config.java
View file @
bc83e983
...
...
@@ -37,11 +37,13 @@ public class Config {
private
final
boolean
showSystem
;
private
final
boolean
showOther
;
private
final
Optional
<
ImmutableList
<
ProcessGroupInfo
>>
processGroups
;
private
final
boolean
debug
;
private
Config
(
Path
dataDir
,
long
interval
,
Optional
<
Integer
>
ppid
,
boolean
prometheusFormat
,
boolean
noPrintHeader
,
boolean
showSystem
,
boolean
showOther
,
Optional
<
ImmutableList
<
ProcessGroupInfo
>>
processGroups
)
{
Optional
<
ImmutableList
<
ProcessGroupInfo
>>
processGroups
,
boolean
debug
)
{
super
();
this
.
dataDir
=
dataDir
;
this
.
interval
=
interval
;
...
...
@@ -51,6 +53,7 @@ public class Config {
this
.
showSystem
=
showSystem
;
this
.
showOther
=
showOther
;
this
.
processGroups
=
processGroups
;
this
.
debug
=
debug
;
}
public
Path
getDataDir
()
{
...
...
@@ -85,6 +88,10 @@ public class Config {
return
processGroups
;
}
public
boolean
isDebug
()
{
return
debug
;
}
public
static
class
Builder
{
private
Path
dataDir
;
private
long
interval
;
...
...
@@ -95,6 +102,7 @@ public class Config {
private
boolean
showOther
;
private
Optional
<
ImmutableList
<
ProcessGroupInfo
>>
processGroups
=
Optional
.
of
(
DefaultPostgresGroups
.
GROUPS
);
private
boolean
debug
;
public
Builder
withDataDir
(
Path
dataDir
)
{
this
.
dataDir
=
dataDir
;
...
...
@@ -146,13 +154,18 @@ public class Config {
return
this
;
}
public
Builder
withDebug
(
boolean
debug
)
{
this
.
debug
=
debug
;
return
this
;
}
public
Config
build
()
{
Preconditions
.
checkArgument
(
dataDir
!=
null
,
"no database directory specified and environment variable PGDATA unset"
);
return
new
Config
(
dataDir
,
interval
,
ppid
,
prometheusFormat
,
noPrintHeader
,
showSystem
,
showOther
,
processGroups
);
processGroups
,
debug
);
}
}
}
main/src/main/java/com/ongres/pgio/main/stats/StatProcessor.java
View file @
bc83e983
...
...
@@ -163,7 +163,7 @@ public class StatProcessor {
if
(
previousStats
.
isPresent
()
&&
previousStats
.
get
().
getStats
().
containsKey
(
pid
))
{
return
Optional
.
of
(
previousStats
.
get
().
getStats
().
get
(
pid
).
getInfo
());
}
else
{
return
logAndE
mptyIfException
(()
->
new
ProcessInfoParser
(
pid
).
parse
(),
return
e
mptyIfException
(()
->
new
ProcessInfoParser
(
pid
).
parse
(),
()
->
"Can not parse process info "
+
pid
+
": "
);
}
}
...
...
@@ -171,24 +171,26 @@ public class StatProcessor {
private
Optional
<
ProcessStat
>
getPreviousOrParseIo
(
Optional
<
StatSnapshot
>
previousStats
,
ProcessInfo
info
)
{
if
(
previousStats
.
isPresent
()
&&
previousStats
.
get
().
getStats
().
containsKey
(
info
.
getPid
()))
{
return
logAndE
mptyIfException
(
return
e
mptyIfException
(
()
->
previousStats
.
get
().
getStats
().
get
(
info
.
getPid
())
.
next
(
new
ProcessIoParser
(
info
.
getPid
()).
parse
()),
()
->
"Can not parse process io "
+
info
.
getPid
()
+
": "
);
}
else
{
return
logAndE
mptyIfException
(
return
e
mptyIfException
(
()
->
new
ProcessStat
(
info
,
new
ProcessIoParser
(
info
.
getPid
()).
parse
()),
()
->
"Can not parse process io "
+
info
.
getPid
()
+
": "
);
}
}
private
<
T
>
Optional
<
T
>
logAndE
mptyIfException
(
private
<
T
>
Optional
<
T
>
e
mptyIfException
(
Callable
<
T
>
callable
,
Supplier
<
String
>
errorPrefix
)
{
try
{
return
Optional
.
of
(
callable
.
call
());
}
catch
(
Throwable
throwable
)
{
err
.
println
(
errorPrefix
.
get
()
+
throwable
.
getMessage
());
throwable
.
printStackTrace
(
err
);
if
(
config
.
isDebug
())
{
err
.
println
(
errorPrefix
.
get
()
+
throwable
.
getMessage
());
throwable
.
printStackTrace
(
err
);
}
return
Optional
.
empty
();
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment