Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
aix-pm
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
Gerhard Gonter
aix-pm
Commits
eaf9ccd3
Commit
eaf9ccd3
authored
3 years ago
by
Gerhard Gonter
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' of gitlab.phaidra.org:gg/aix-pm
parents
b371cbb6
0fc11228
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
modules/util/Util/Monitoring.pm
+70
-28
70 additions, 28 deletions
modules/util/Util/Monitoring.pm
modules/util/Util/Processes.pm
+47
-0
47 additions, 0 deletions
modules/util/Util/Processes.pm
with
117 additions
and
28 deletions
modules/util/Util/Monitoring.pm
+
70
−
28
View file @
eaf9ccd3
...
...
@@ -120,8 +120,8 @@ sub read_config
my
$mon_cfg
=
Util::JSON::
read_json_file
(
$cfg_fnm
);
# print "mon_cfg: ", Dumper ($mon_cfg);
$obj
->
{
'
mon_cfg
'
}
=
$mon_cfg
;
$obj
->
{
'
cfg_fnm
'
}
=
$cfg_fnm
;
$obj
->
{
mon_cfg
}
=
$mon_cfg
;
$obj
->
{
cfg_fnm
}
=
$cfg_fnm
;
# TODO: add mtime for update to work...
# BEGIN connect to MongoDB collection
...
...
@@ -158,7 +158,34 @@ sub read_config
1
;
}
=head setup_ref
sub
get_collection
{
my
$self
=
shift
;
my
$name
=
shift
;
my
$col_handle
=
'
_
'
.
$name
;
return
$self
->
{
$col_handle
}
if
(
exists
(
$self
->
{
$col_handle
}));
my
$mon_cfg
=
$self
->
{
mon_cfg
};
my
$paf
=
$mon_cfg
->
{'
AgentDB
'};
my
$col_name
=
setup_default_collection
(
$paf
,
$name
);
my
$mdb
=
$self
->
{
_mdb
};
my
$col
=
$mdb
->
get_collection
(
$col_name
);
$self
->
{
$col_handle
}
=
$col
;
$col
;
}
sub
get_config
{
my
$obj
=
shift
;
my
$what
=
shift
;
my
$res
=
$obj
->
{
mon_cfg
}
->
{
$what
};
$res
;
}
=head2 setup_ref
BEGIN access special settings
...
...
@@ -176,7 +203,7 @@ sub setup_ref
$obj
->
{'
_auto_increment
'}
=
\
@ai
;
my
$fs_list
=
$obj
->
{'
mon_cfg
'}
->
{'
filesystems
'};
foreach
my
$fs
(
@$fs_list
)
{
my
$mp
=
$fs
->
{'
mount_point
'};
...
...
@@ -189,6 +216,14 @@ sub setup_ref
$ref
;
}
=head1 PAF methods
=head2 $mon->event({...})
register an event
=cut
sub
event
{
my
$mon
=
shift
;
...
...
@@ -198,6 +233,37 @@ sub event
my
$event_id
=
$events
->
insert
(
$ev
);
}
=head2 $mon->message({...})
send a message
=cut
sub
send_message
{
my
$mon
=
shift
;
my
$message
=
shift
;
my
$priority
=
shift
||
'
low
';
my
$msg_cnt
=
0
;
my
$c_msg
=
$mon
->
{
_messages
};
my
$notify
=
$mon
->
{
mon_cfg
}
->
{
notify
};
if
(
defined
(
$c_msg
)
&&
defined
(
$notify
))
{
my
@notify
=
(
ref
(
$notify
)
eq
'
ARRAY
')
?
@$notify
:
$notify
;
my
$now
=
time
();
foreach
my
$to
(
@notify
)
{
$c_msg
->
insert
({
message
=>
$message
,
to
=>
$to
,
priority
=>
$priority
,
state
=>
'
new
',
'
e
'
=>
$now
,
'
ts
'
=>
DateTime
->
from_epoch
('
epoch
'
=>
$now
),});
$msg_cnt
;
}
}
$mon
->
{
_events
}
->
insert
({
event
=>
'
messages
',
message
=>
$message
,
priority
=>
$priority
,
count
=>
$msg_cnt
});
}
=head1 FILE SYSTEM METHODS
=cut
...
...
@@ -307,30 +373,6 @@ sub get_machine
$mon
->
{
_machine
};
}
sub
send_message
{
my
$mon
=
shift
;
my
$message
=
shift
;
my
$priority
=
shift
||
'
low
';
my
$msg_cnt
=
0
;
my
$c_msg
=
$mon
->
{
_messages
};
my
$notify
=
$mon
->
{
mon_cfg
}
->
{
notify
};
if
(
defined
(
$c_msg
)
&&
defined
(
$notify
))
{
my
@notify
=
(
ref
(
$notify
)
eq
'
ARRAY
')
?
@$notify
:
$notify
;
my
$now
=
time
();
foreach
my
$to
(
@notify
)
{
$c_msg
->
insert
({
message
=>
$message
,
to
=>
$to
,
priority
=>
$priority
,
state
=>
'
new
',
'
e
'
=>
$now
,
'
ts
'
=>
DateTime
->
from_epoch
('
epoch
'
=>
$now
),});
$msg_cnt
;
}
}
$mon
->
{
_events
}
->
insert
({
event
=>
'
messages
',
message
=>
$message
,
priority
=>
$priority
,
count
=>
$msg_cnt
});
}
=head1 SETUP FUNCTIONS
=head2 $col= setup_default_collecton ($name)
...
...
This diff is collapsed.
Click to expand it.
modules/util/Util/Processes.pm
0 → 100644
+
47
−
0
View file @
eaf9ccd3
=head1 NAME
Util::Processes
=head1 DESCRIPTION
Deal with Unix processes
=cut
package
Util::
processes
;
sub
psauxww
{
my
@cmd
=
qw(ps auxww)
;
open
(
PS
,
'
-|
',
@cmd
)
or
die
;
my
$columns
=
<
PS
>
;
chop
(
$columns
);
my
@columns
=
split
('
',
$columns
);
my
$column_count
=
0
;
my
%columns
=
map
{
$_
=>
$column_count
++
}
@columns
;
# print __LINE__, " columns: ", main::Dumper(\@columns);
# print __LINE__, " column_count=[$column_count]\n";
my
@processes
;
while
(
<
PS
>
)
{
chop
;
# print __LINE__, " _=[$_]\n";
my
@f
=
split
('
',
$_
,
$column_count
);
my
%f
=
map
{
$_
=>
shift
(
@f
)
}
@columns
;
# print __LINE__, " proc: ", main::Dumper(\%f);
push
(
@processes
,
\
%f
);
}
close
(
PS
);
my
$proc
=
{
columns
=>
\
@columns
,
processes
=>
\
@processes
,
};
$proc
;
}
1
;
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