Skip to content

Commit

Permalink
weblogic 12.1.2 and 12.2 compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Giraldo authored and Carlos Giraldo committed Dec 5, 2018
1 parent f6a5e57 commit dffea12
Show file tree
Hide file tree
Showing 9 changed files with 254 additions and 46 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,16 @@ Sample configuration file
weblogicbeat:
period: 60s
host: http://localhost:7001
wlsversion : 12.2
username: weblogic
password: welcome1
servername: server1
servernames: ["server1", "server2"]
datasources: ["EssDS", "EDNDataSource"]
applications: ["ESSAPP", "sample-app"]
```
- period: How often an event is sent to the output
- host: Admin host and port
- wlsversion: Weblogic version. Suported versions 12.1.2 or 12.2
- username: Weblogic admin user
- password: Weblogic admin password
- datasources: Array of datasources to monitor
Expand Down Expand Up @@ -95,6 +97,14 @@ mage setup

*I had some issues on my mac with the make setup. I had to create manually a python2 env in build/python-env and install with pip the functools32 dependency. Be careful when using mage clean the build directory is erased and the python-env directory needs to be created again*

```
cd build
rm -rf python-env
virtualenv python-env --python=python2.7
source python-env/bin/activate
pip install functools32
```


### Build

Expand Down
1 change: 1 addition & 0 deletions _meta/beat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ weblogicbeat:
# Defines how often an event is sent to the output
period: 60s
host: http://localhost:7001
wlsversion : 12.1.2
username: weblogic
password: welcome1
servernames: ["server1"]
Expand Down
27 changes: 26 additions & 1 deletion _meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,22 @@
required: true
description: >
PLEASE UPDATE DOCUMENTATION
- name: metric_error
- name: err_server
type: string
required: false
description: >
PLEASE UPDATE DOCUMENTATION
- name: err_metric_type
type: string
required: false
description: >
PLEASE UPDATE DOCUMENTATION
- name: err_metric_error
type: string
required: false
description: >
PLEASE UPDATE DOCUMENTATION
- name: err_metric_body
type: string
required: false
description: >
Expand Down Expand Up @@ -62,6 +77,11 @@
required: false
description: >
PLEASE UPDATE DOCUMENTATION
- name: ds_server
type: string
required: false
description: >
PLEASE UPDATE DOCUMENTATION
- name: ds_state
type: string
required: false
Expand Down Expand Up @@ -102,6 +122,11 @@
required: false
description: >
PLEASE UPDATE DOCUMENTATION
- name: app_server
type: string
required: false
description: >
PLEASE UPDATE DOCUMENTATION
- name: app_state
type: string
required: false
Expand Down
162 changes: 162 additions & 0 deletions beater/weblogic1212.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
package beater

import (
"fmt"
"time"

gabs "github.com/Jeffail/gabs"
"github.com/elastic/beats/libbeat/beat"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/logp"

"github.com/carlgira/weblogicbeat/config"
resty "gopkg.in/resty.v1"
)

// Weblogicbeat configuration.
type Weblogic1212 struct {
bt Weblogicbeat
config config.Config
}

func (wls *Weblogic1212) ServerStatusEvent() {

for _, server_name := range wls.config.ServerNames {
resp_server_status, err_server_status := resty.R().
SetHeader("Accept", "application/json").
SetHeader("X-Requested-By", "weblogicbeat").
SetBasicAuth(wls.config.Username, wls.config.Password).
Get(wls.config.Host + "/management/tenant-monitoring/servers/" + server_name)

if resp_server_status.StatusCode() != 200 {
wls.SendErrorEvent(server_name, "server_status", fmt.Sprintf("%v", err_server_status), fmt.Sprintf("%v", resp_server_status))
continue
}

json_server_status, _ := gabs.ParseJSON([]byte(resp_server_status.String()))
server := json_server_status.Path("body.item").Data().(map[string]interface{})

server_status_event := beat.Event{
Timestamp: time.Now(),
Fields: common.MapStr{
"wb_server": server_name,
"wb_metric_type": "server_status",
"srv_name": server["name"],
"srv_state": server["state"],
"srv_heapFreeCurrent": int(server["heapFreeCurrent"].(float64) / 1000000),
"srv_heapSizeCurrent": int(server["heapSizeCurrent"].(float64) / 1000000),
"srv_heapSizeMax": int(server["heapSizeMax"].(float64) / 1000000),
"srv_health": server["health"],
},
}
wls.bt.client.Publish(server_status_event)
logp.Info("Server status %s - event sent", server_name)
}
}

func (wls *Weblogic1212) DatasourceStatusEvent() {

for _, datasource := range wls.config.Datasources {
resp_ds, error_ds := resty.R().
SetHeader("Accept", "application/json").
SetHeader("X-Requested-By", "weblogicbeat").
SetBasicAuth(wls.config.Username, wls.config.Password).
Get(wls.config.Host + "/management/tenant-monitoring/datasources/" + datasource)

if resp_ds.StatusCode() != 200 {
wls.SendErrorEvent(datasource, "datasource_status", fmt.Sprintf("%v", error_ds), fmt.Sprintf("%v", resp_ds))
continue
}

json_ds_status, _ := gabs.ParseJSON([]byte(resp_ds.String()))
dsinfo, _ := json_ds_status.Path("body.item.instances").Children()

for _, child := range dsinfo {
ds := child.Data().(map[string]interface{})

if !stringInSlice(ds["server"].(string), wls.config.ServerNames) {
continue
}

datasource_status_event := beat.Event{
Timestamp: time.Now(),
Fields: common.MapStr{
"wb_server": ds["server"],
"wb_metric_type": "datasource_status",
"ds_server": ds["server"],
"ds_name": datasource,
"ds_state": ds["state"],
"ds_enabled": ds["enabled"],
"ds_activeConnectionsCurrentCount": ds["activeConnectionsCurrentCount"],
"ds_connectionsTotalCount": ds["connectionsTotalCount"],
"ds_activeConnectionsAverageCount": ds["activeConnectionsAverageCount"],
},
}
wls.bt.client.Publish(datasource_status_event)
logp.Info("Datasource status %s - event sent", ds["server"])
}
}

}

func (wls *Weblogic1212) ApplicationStatusEvent() {

for _, application := range wls.config.Applications {
resp_app, err_app := resty.R().
SetHeader("Accept", "application/json").
SetHeader("X-Requested-By", "weblogicbeat").
SetBasicAuth(wls.config.Username, wls.config.Password).
Get(wls.config.Host + "/management/tenant-monitoring/applications/" + application)

if resp_app.StatusCode() != 200 {
wls.SendErrorEvent(application, "application_status", fmt.Sprintf("%v", err_app), fmt.Sprintf("%v", resp_app))
continue
}

json_application_status, _ := gabs.ParseJSON([]byte(resp_app.String()))
appinfo := json_application_status.Path("body.item").Data().(map[string]interface{})

for _, server_name := range wls.config.ServerNames {
application_status_event := beat.Event{
Timestamp: time.Now(),
Fields: common.MapStr{
"wb_server": server_name,
"wb_metric_type": "application_status",
"app_server": server_name,
"app_name": application,
"app_componentName": application,
"app_state": appinfo["state"],
"app_health": appinfo["health"],
},
}
wls.bt.client.Publish(application_status_event)
logp.Info("Application status %s - event sent", server_name)
}
}
}

func (wls *Weblogic1212) ThreadStatusEvent() {
}

func (wls *Weblogic1212) SendErrorEvent(serverName string, metricType string, err string, body string) {
error_event := beat.Event{
Timestamp: time.Now(),
Fields: common.MapStr{
"err_server": serverName,
"err_metric_type": metricType,
"err_metric_error": err,
"err_metric_body": body,
},
}
wls.bt.client.Publish(error_event)
logp.Info("Error : %s", err)
}

func stringInSlice(a string, list []string) bool {
for _, b := range list {
if b == a {
return true
}
}
return false
}
36 changes: 20 additions & 16 deletions beater/weblogic122.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ func (wls *Weblogic122) ServerStatusEvent() {
SetBasicAuth(wls.config.Username, wls.config.Password).
Get(wls.config.Host + "/management/weblogic/latest/domainRuntime/serverRuntimes/" + server_name + "?links=none&fields=name,state,healthState")

if err_server_status != nil {
wls.SendErrorEvent(server_name, "server_status", fmt.Sprintf("%v", err_server_status))
if resp_server_status.StatusCode() != 200 {
wls.SendErrorEvent(server_name, "server_status", fmt.Sprintf("%v", err_server_status), fmt.Sprintf("%v", resp_server_status))
continue
}

Expand All @@ -43,8 +43,8 @@ func (wls *Weblogic122) ServerStatusEvent() {
SetBasicAuth(wls.config.Username, wls.config.Password).
Get(wls.config.Host + "/management/weblogic/latest/domainRuntime/serverRuntimes/" + server_name + "/JVMRuntime?links=none&fields=heapSizeCurrent,heapFreeCurrent,heapFreePercent,heapSizeMax")

if err_server_jvm != nil {
wls.SendErrorEvent(server_name, "server_status", fmt.Sprintf("%v", err_server_jvm))
if resp_server_jvm.StatusCode() != 200 {
wls.SendErrorEvent(server_name, "server_status", fmt.Sprintf("%v", err_server_jvm), fmt.Sprintf("%v", resp_server_jvm))
continue
}

Expand Down Expand Up @@ -80,8 +80,8 @@ func (wls *Weblogic122) DatasourceStatusEvent() {
SetBasicAuth(wls.config.Username, wls.config.Password).
Get(wls.config.Host + "/management/weblogic/latest/domainRuntime/serverRuntimes/" + server_name + "/JDBCServiceRuntime/JDBCDataSourceRuntimeMBeans/" + datasource + "?links=none&fields=activeConnectionsCurrentCount,activeConnectionsAverageCount,connectionsTotalCount,enabled,state,name")

if error_ds != nil {
wls.SendErrorEvent(server_name, "datasource_status", fmt.Sprintf("%v", error_ds))
if resp_ds.StatusCode() != 200 {
wls.SendErrorEvent(server_name, "datasource_status", fmt.Sprintf("%v", error_ds), fmt.Sprintf("%v", resp_ds))
continue
}

Expand All @@ -105,6 +105,7 @@ func (wls *Weblogic122) DatasourceStatusEvent() {
Fields: common.MapStr{
"wb_server": server_name,
"wb_metric_type": "datasource_status",
"ds_server": server_name,
"ds_name": datasource,
"ds_state": dsinfo["state"],
"ds_enabled": dsinfo["enabled"],
Expand All @@ -130,8 +131,8 @@ func (wls *Weblogic122) ApplicationStatusEvent() {
SetBasicAuth(wls.config.Username, wls.config.Password).
Get(wls.config.Host + "/management/weblogic/latest/domainRuntime/serverRuntimes/" + server_name + "/applicationRuntimes/" + application + "?links=none&fields=name,healthState")

if err_app != nil {
wls.SendErrorEvent(server_name, "application_status", fmt.Sprintf("%v", err_app))
if resp_app.StatusCode() != 200 {
wls.SendErrorEvent(server_name, "application_status", fmt.Sprintf("%v", err_app), fmt.Sprintf("%v", resp_app))
continue
}

Expand All @@ -145,8 +146,8 @@ func (wls *Weblogic122) ApplicationStatusEvent() {
SetBasicAuth(wls.config.Username, wls.config.Password).
Get(wls.config.Host + "/management/weblogic/latest/domainRuntime/serverRuntimes/" + server_name + "/applicationRuntimes/" + application + "/componentRuntimes?fields=openSessionsCurrentCount,sessionsOpenedTotalCount,openSessionsHighCount,applicationIdentifier,status,componentName&links=none")

if err_app_comp != nil {
wls.SendErrorEvent(server_name, "application_status", fmt.Sprintf("%v", err_app_comp))
if resp_app_comp.StatusCode() != 200 {
wls.SendErrorEvent(server_name, "application_status", fmt.Sprintf("%v", err_app_comp), fmt.Sprintf("%v", resp_app_comp))
continue
}

Expand All @@ -161,6 +162,7 @@ func (wls *Weblogic122) ApplicationStatusEvent() {
Fields: common.MapStr{
"wb_server": server_name,
"wb_metric_type": "application_status",
"app_server": server_name,
"app_name": application,
"app_componentName": comp["componentName"],
"app_state": comp["status"],
Expand All @@ -186,8 +188,8 @@ func (wls *Weblogic122) ThreadStatusEvent() {
SetBasicAuth(wls.config.Username, wls.config.Password).
Get(wls.config.Host + "/management/weblogic/latest/domainRuntime/serverRuntimes/" + server_name + "/threadPoolRuntime?links=none&fields=overloadRejectedRequestsCount,pendingUserRequestCount,executeThreadTotalCount,healthState,stuckThreadCount,throughput,hoggingThreadCount")

if err_thread_status != nil {
wls.SendErrorEvent(server_name, "thread_status", fmt.Sprintf("%v", err_thread_status))
if resp_thread_status.StatusCode() != 200 {
wls.SendErrorEvent(server_name, "thread_status", fmt.Sprintf("%v", err_thread_status), fmt.Sprintf("%v", resp_thread_status))
continue
}

Expand All @@ -200,6 +202,7 @@ func (wls *Weblogic122) ThreadStatusEvent() {
Fields: common.MapStr{
"wb_server": server_name,
"wb_metric_type": "thread_status",
"th_server": server_name,
"th_overloadRejectedRequestsCount": threads["overloadRejectedRequestsCount"],
"th_pendingUserRequestCount": threads["pendingUserRequestCount"],
"th_executeThreadTotalCount": threads["executeThreadTotalCount"],
Expand All @@ -215,13 +218,14 @@ func (wls *Weblogic122) ThreadStatusEvent() {
}
}

func (wls *Weblogic122) SendErrorEvent(serverName string, metricType string, err string) {
func (wls *Weblogic122) SendErrorEvent(serverName string, metricType string, err string, body string) {
error_event := beat.Event{
Timestamp: time.Now(),
Fields: common.MapStr{
"server": serverName,
"metric_type": metricType,
"metric_error": err,
"err_server": serverName,
"err_metric_type": metricType,
"err_metric_error": err,
"err_metric_body": body,
},
}
wls.bt.client.Publish(error_event)
Expand Down
Loading

0 comments on commit dffea12

Please sign in to comment.