More work on example Ansible playbooks.

This commit is contained in:
Mark Nellemann 2021-08-24 14:21:56 +02:00
parent e2b478a1c2
commit 84f36163b6
7 changed files with 175 additions and 38 deletions

3
doc/ansible/README.md Normal file
View File

@ -0,0 +1,3 @@
# Example Ansible Playbooks
For installing on AIX and RPM-based Linux.

View File

@ -1,48 +1,63 @@
---
#
# Example ansible playbook for installation of sysmon client on AIX.
# More information at: https://bitbucket.org/mnellemann/sysmon
#
# ansible-galaxy collection install community.general
# ansible-playbook -i aixhost, -k -u root sysmon-client.yml
# ansible-playbook -i aixhost, -u root sysmon-client-aix.yml
#
# NOTE: Ensure correct timezone and time
- name: "Install / Configure sysmon client and plugins"
- name: "Install Sysmon Client and Plugins on AIX"
hosts: all
gather_facts: yes
vars:
client_download_url: https://bitbucket.org/mnellemann/sysmon/downloads/sysmon-client-0.0.5-1.noarch.rpm
plugins_download_url: https://bitbucket.org/mnellemann/sysmon/downloads/sysmon-plugins-0.0.5-1.noarch.rpm
server_url: http://sysmon-server:9925/metrics
client_hostname: myaix
tasks:
- name: Download sysmon-client
get_url:
url: "{{ client_download_url }}"
dest: /opt/sysmon-client.rpm
- name: Download sysmon-plugins
get_url:
url: "{{ plugins_download_url }}"
dest: /opt/sysmon-plugins.rpm
- name: Sysmon Client | Ensure hostname resolves
ansible.builtin.lineinfile:
path: /etc/hosts
state: present
line: "127.0.1.1 {{ ansible_hostname }}"
- name: Install sysmon-client (if /opt/sysmon/client does not exist)
ansible.builtin.command: /usr/bin/rpm -i --ignoreos /opt/sysmon-client.rpm
args:
creates: /opt/sysmon/client
- name: Sysmon Client | Copy sysmon-client.rpm
ansible.builtin.copy:
src: "{{ item }}"
dest: /opt/sysmon-client.rpm
with_fileglob:
- ../../client/build/distributions/sysmon-client-*.noarch.rpm
- name: Install sysmon-plugins (if /opt/sysmon/plugins does not exist)
ansible.builtin.command: /usr/bin/rpm -i --ignoreos /opt/sysmon-plugins.rpm
args:
creates: /opt/sysmon/plugins
- name: Sysmon Client | Copy sysmon-plugins.rpm
ansible.builtin.copy:
src: "{{ item }}"
dest: /opt/sysmon-plugins.rpm
with_fileglob:
- ../../plugins/build/distributions/sysmon-plugins-*.noarch.rpm
- name: Create inittab entry for sysmon-client
community.general.aix_inittab:
name: sysmon
runlevel: '2'
action: respawn
command: env JAVA_HOME=/usr/java8_64 /opt/sysmon/client/bin/client -s {{ server_url }} -n {{ client_hostname }} >/tmp/sysmon.log 2>&1
state: present
become: yes
- name: Sysmon Client | Install sysmon-client.rpm
ansible.builtin.command: /usr/bin/rpm -i --ignoreos /opt/sysmon-client.rpm
args:
creates: /opt/sysmon/client
- name: Sysmon Client | Install sysmon-plugins.rpm
ansible.builtin.command: /usr/bin/rpm -i --ignoreos /opt/sysmon-plugins.rpm
args:
creates: /opt/sysmon/plugins
- name: Sysmon Client | Create inittab entry for sysmon-client
community.general.aix_inittab:
name: sysmon
runlevel: '2'
action: respawn
command: env JAVA_HOME=/usr/java8_64 /opt/sysmon/client/bin/client -s {{ server_url }} >/tmp/sysmon.log 2>&1
state: present
become: yes
notify:
- reload inittab
handlers:
- name: reload inittab
command: init q

View File

@ -0,0 +1,61 @@
---
#
# Example ansible playbook for installation of sysmon client on Linux (RPM based).
# More information at: https://bitbucket.org/mnellemann/sysmon
#
# ansible-playbook -i linuxhost, -u root sysmon-client-linux.yml
#
# NOTE: Ensure correct timezone and time
- name: "Install Sysmon Client and Plugins on Linux (RPM based)"
hosts: all
gather_facts: no
vars:
server_url: http://sysmon-server:9925/metrics
tasks:
- name: Sysmon Client | Copy sysmon-client.rpm
ansible.builtin.copy:
src: "{{ item }}"
dest: /opt/sysmon-client.rpm
with_fileglob:
- ../../client/build/distributions/sysmon-client-*.noarch.rpm
- name: Sysmon Client | Copy sysmon-plugins.rpm
ansible.builtin.copy:
src: "{{ item }}"
dest: /opt/sysmon-plugins.rpm
with_fileglob:
- ../../plugins/build/distributions/sysmon-plugins-*.noarch.rpm
- name: Sysmon Client | Install OpenJDK (headless)
yum:
name: "java-11-openjdk-headless"
state: present
- name: Sysmon Client | Install sysmon-client.rpm
yum:
name: /opt/sysmon-client.rpm
state: present
disable_gpg_check: true
- name: Sysmon Plugins | Install sysmon-plugins.rpm
yum:
name: /opt/sysmon-plugins.rpm
state: present
disable_gpg_check: true
- name: Sysmon Client | Create service file
template: src=sysmon-client.service.j2 dest=/lib/systemd/system/sysmon-client.service mode=644
notify:
- reload systemctl
- name: Sysmon Client | Start service
service: name=sysmon-client.service state=started enabled=yes
handlers:
- name: reload systemctl
command: systemctl daemon-reload

View File

@ -0,0 +1,10 @@
[Unit]
Description=Sysmon Client Service
[Service]
TimeoutStartSec=3
Restart=always
ExecStart=/opt/sysmon/client/bin/client -s {{server_url}}
[Install]
WantedBy=default.target

View File

@ -1,15 +1,13 @@
---
#
# Example ansible playbook for timezone and NTP setup on AIX.
# A reboot is required for the timezone change.
#
# ansible-galaxy collection install community.general
# ansible-playbook -i aixhost, -k -u root timezone-aix.yml
# ansible-playbook -i aixhost, -u root timezone-aix.yml
#
- name: "Install / Configure sysmon client and plugins"
- name: "Timezone and NTP on AIX"
hosts: all
gather_facts: yes
gather_facts: no
vars:
timezone: Europe/Copenhagen
ntp_server: dk.pool.ntp.org
@ -23,7 +21,7 @@
replace: "TZ={{ timezone }}"
- name: Update time from NTP server
ansible.builtin.command: /usr/sbin/ntpdate {{ ntp_server }}
ansible.builtin.command: "env TZ={{ timezone }} /usr/sbin/ntpdate {{ ntp_server }}"
- name: Create cron entry for updating time periodically
ansible.builtin.cron:

View File

@ -56,7 +56,7 @@ public class AixProcessorExtension implements MetricExtension {
Map<String, String> tagsMap = null;
Map<String, Object> fieldsMap = null;
try (InputStream buf = PluginHelper.executeCommand("lparstat 1 1")) {
try (InputStream buf = PluginHelper.executeCommand("lparstat 5 1")) {
AixProcessorStat processorStat = processCommandOutput(buf);
tagsMap = processorStat.getTags();
fieldsMap = processorStat.getFields();

View File

@ -1,14 +1,22 @@
package sysmon.plugins.os_ibmi;
import com.ibm.as400.access.*;
import org.pf4j.Extension;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sysmon.shared.MetricExtension;
import sysmon.shared.MetricResult;
import java.io.IOException;
// Disable for now...
//@Extension
public class TestExtension implements MetricExtension {
private static final Logger log = LoggerFactory.getLogger(TestExtension.class);
private AS400 as400;
private SystemStatus systemStatus;
@Override
public boolean isSupported() {
@ -19,6 +27,21 @@ public class TestExtension implements MetricExtension {
System.err.println("OS Arch: " + osArch);
System.err.println("OS Name: " + osName);
try {
//as400 = new AS400("localhost", "CURRENT");
as400 = new AS400("10.32.64.142");
systemStatus = new SystemStatus(as400);
} catch (Exception exception) {
log.error(exception.getMessage());
}
if(as400.isLocal()) {
log.info("as400 isLocal() true");
} else {
log.info("as400 isLocal() FALSE");
}
return true;
}
@ -39,6 +62,33 @@ public class TestExtension implements MetricExtension {
@Override
public MetricResult getMetrics() {
if(systemStatus == null) {
log.warn("getMetrics() - no system or status");
return null;
}
try {
int jobsInSystem = systemStatus.getJobsInSystem();
log.info("Jobs In System: " + jobsInSystem);
int batchJobsRunning = systemStatus.getBatchJobsRunning();
log.info("Batch Jobs Running: " + batchJobsRunning);
int activeThreads = systemStatus.getActiveThreadsInSystem();
log.info("Active Threads: " + activeThreads);
int activeJobs = systemStatus.getActiveJobsInSystem();
log.info("Active Jobs: " + activeJobs);
int onlineUsers = systemStatus.getUsersCurrentSignedOn();
log.info("Online Users: " + onlineUsers);
} catch (AS400SecurityException | ErrorCompletingRequestException | InterruptedException | IOException | ObjectDoesNotExistException e) {
log.error(e.getMessage());
e.printStackTrace();
}
return null;
}
}