Merged in development (pull request #5)

Development work merged in.
This commit is contained in:
Mark Nellemann 2021-08-24 12:28:14 +00:00
commit 436a490ecb
18 changed files with 252 additions and 29 deletions

View file

@ -5,7 +5,7 @@ subprojects {
maven { url("https://plugins.gradle.org/m2/") }
}
dependencies {
classpath 'org.redline-rpm:redline:1.2.9'
classpath 'org.redline-rpm:redline:1.2.10'
}
}

View file

@ -5,7 +5,7 @@ plugins {
id "com.github.johnrengelman.shadow" version "7.0.0"
id "net.nemerosa.versioning" version "2.14.0"
id "nebula.ospackage" version "8.5.6"
id "nebula.ospackage" version "8.6.1"
}
dependencies {

View file

@ -82,4 +82,5 @@ public class ClientRouteBuilder extends RouteBuilder {
}
}

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

@ -0,0 +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, -u root sysmon-client-aix.yml
#
# NOTE: Ensure correct timezone and time
- name: "Install Sysmon Client and Plugins on AIX"
hosts: all
gather_facts: yes
vars:
server_url: http://sysmon-server:9925/metrics
tasks:
- name: Sysmon Client | Ensure hostname resolves
ansible.builtin.lineinfile:
path: /etc/hosts
state: present
line: "127.0.1.1 {{ ansible_hostname }}"
- 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 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

@ -0,0 +1,33 @@
---
#
# Example ansible playbook for timezone and NTP setup on AIX.
#
# ansible-playbook -i aixhost, -u root timezone-aix.yml
#
- name: "Timezone and NTP on AIX"
hosts: all
gather_facts: no
vars:
timezone: Europe/Copenhagen
ntp_server: dk.pool.ntp.org
tasks:
- name: Configure timezone
ansible.builtin.replace:
path: /etc/environment
regexp: '^TZ=(.*)$'
replace: "TZ={{ timezone }}"
- name: Update time from NTP server
ansible.builtin.command: "env TZ={{ timezone }} /usr/sbin/ntpdate {{ ntp_server }}"
- name: Create cron entry for updating time periodically
ansible.builtin.cron:
name: ntpdate
weekday: "*"
minute: "1"
hour: "*"
user: root
job: "/usr/sbin/ntpdate {{ ntp_server }}"

View file

@ -1,6 +1,6 @@
version=0.0.5
version=0.0.6
pf4jVersion=3.6.0
slf4jVersion=1.7.30
camelVersion=3.10.0
slf4jVersion=1.7.32
camelVersion=3.11.0
picocliVersion=4.6.1
oshiVersion=5.7.5
oshiVersion=5.8.1

View file

@ -1,7 +1,7 @@
import org.redline_rpm.header.Os
plugins {
id "nebula.ospackage" version "8.5.6"
id "nebula.ospackage" version "8.6.1"
}

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,7 +1,5 @@
pluginId=sysmon-base
pluginClass=sysmon.plugins.os_base.BasePlugin
pluginVersion=0.0.1
pluginProvider=System Monitor
pluginDependencies=
pluginDescription=Base OS metrics where supported.

View file

@ -1,6 +1,4 @@
pluginId=sysmon-ibmi
pluginClass=sysmon.plugins.os_ibmi.IbmIPlugin
pluginVersion=0.0.1
pluginProvider=System Monitor
pluginDependencies=
pluginDescription=Collects IBM-i OS metrics.

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;
}
}

View file

@ -5,7 +5,7 @@ plugins {
id "com.github.johnrengelman.shadow" version "7.0.0"
id "net.nemerosa.versioning" version "2.14.0"
id "nebula.ospackage" version "8.5.6"
id "nebula.ospackage" version "8.6.1"
}
dependencies {

View file

@ -2,7 +2,9 @@ package sysmon.server;
import org.apache.camel.main.Main;
import org.influxdb.InfluxDB;
import org.influxdb.InfluxDBException;
import org.influxdb.InfluxDBFactory;
import org.influxdb.dto.Query;
import picocli.CommandLine;
import java.io.IOException;
@ -21,8 +23,8 @@ public class Application implements Callable<Integer> {
@CommandLine.Option(names = { "-p", "--influxdb-pass" }, description = "InfluxDB Password (default: ${DEFAULT-VALUE}).", defaultValue = "", paramLabel = "<pass>")
private String influxPass;
//@CommandLine.Option(names = { "-d", "--influxdb-db" }, description = "InfluxDB Database (default: ${DEFAULT-VALUE}).", defaultValue = "", paramLabel = "<name>")
//private String influxName = "sysmon";
@CommandLine.Option(names = { "-d", "--influxdb-db" }, description = "InfluxDB Database (default: ${DEFAULT-VALUE}).", defaultValue = "sysmon", paramLabel = "<db>")
private String influxName;
@CommandLine.Option(names = { "-H", "--server-host" }, description = "Server listening address (default: ${DEFAULT-VALUE}).", paramLabel = "<addr>")
private String listenHost = "0.0.0.0";
@ -42,20 +44,21 @@ public class Application implements Callable<Integer> {
@Override
public Integer call() throws IOException {
InfluxDB influxDB = InfluxDBFactory.connect(influxUrl.toString(), influxUser, influxPass);
/*
Properties properties = new Properties();
properties.put("http.host", listenHost);
properties.put("http.port", listenPort);
*/
InfluxDB influxConnectionBean = InfluxDBFactory.connect(influxUrl.toString(), influxUser, influxPass);
try {
influxDB.query(new Query("CREATE DATABASE " + influxName));
} catch (InfluxDBException e) {
System.err.println(e.getMessage());
return -1;
}*/
Main main = new Main();
main.bind("myInfluxConnection", influxConnectionBean);
main.bind("myInfluxConnection", influxDB);
main.bind("http.host", listenHost);
main.bind("http.port", listenPort);
//main.bind("properties", properties);
main.bind("threads", threads);
//main.bind("influxdb_name", influxName);
main.bind("dbname", influxName);
main.configure().addRoutesBuilder(ServerRouteBuilder.class);
// now keep the application running until the JVM is terminated (ctrl + c or sigterm)

View file

@ -2,6 +2,7 @@ package sysmon.server;
import org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.influxdb.InfluxDbConstants;
import org.apache.camel.model.rest.RestBindingMode;
import org.apache.camel.spi.Registry;
import sysmon.shared.MetricResult;
@ -11,7 +12,9 @@ public class ServerRouteBuilder extends RouteBuilder {
@Override
public void configure() throws Exception {
Registry registry = getContext().getRegistry();
final Registry registry = getContext().getRegistry();
final String dbname = registry.lookupByNameAndType("dbname", String.class);
final Integer threads = registry.lookupByNameAndType("threads", Integer.class);
restConfiguration().component("netty-http")
.bindingMode(RestBindingMode.auto)
@ -38,11 +41,11 @@ public class ServerRouteBuilder extends RouteBuilder {
.to("seda:inbound")
.endRest();
fromF("seda:inbound?concurrentConsumers=%s", registry.lookupByNameAndType("threads", Integer.class))
fromF("seda:inbound?concurrentConsumers=%s", threads)
.log(">>> metric: ${header.hostname} - ${body}")
.doTry()
.process(new MetricResultToPointProcessor())
.toF("influxdb://ref.myInfluxConnection?databaseName=%s&retentionPolicy=autogen", "sysmon")
.toF("influxdb://ref.myInfluxConnection?databaseName=%s&retentionPolicy=autogen", dbname)
.doCatch(Exception.class)
.log("Error storing metric to InfluxDB: ${exception}")
.end();

View file

@ -17,9 +17,9 @@ repositories {
}
dependencies {
testImplementation 'org.codehaus.groovy:groovy:3.0.7'
testImplementation 'org.spockframework:spock-core:2.0-M4-groovy-3.0'
testImplementation 'junit:junit:4.13.1'
testImplementation 'org.codehaus.groovy:groovy:3.0.8'
testImplementation 'org.spockframework:spock-core:2.0-groovy-3.0'
testImplementation 'junit:junit:4.13.2'
testImplementation "org.slf4j:slf4j-api:${slf4jVersion}"
implementation "org.slf4j:slf4j-api:${slf4jVersion}"