Skip to content

Commit

Permalink
Add license header
Browse files Browse the repository at this point in the history
  • Loading branch information
Bravo27 committed Jan 26, 2022
1 parent 6ccb7c3 commit edb2ad5
Show file tree
Hide file tree
Showing 14 changed files with 192 additions and 90 deletions.
52 changes: 44 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,66 @@
# Lightstreamer Metrics Exporter Adapter Set - Prometheus Integration

This project includes the source code of the Lightstreamer Metrics Exporter Adapter Set. A ready made Adapter Set for fast deployment into
Lightstreamer server an immediate export of numerous metrics for Prometheus monitoring solution out of the box.
This project includes the source code of the Lightstreamer Metrics Exporter Adapter Set.
A ready made Adapter Set for fast deployment into Lightstreamer server an immediate export of numerous metrics for Prometheus monitoring solution out of the box.

This code is designed for Java 8 and greater.

### The Adapter Architecture

This metrics exporter is intended to be run as a Lightsteamer in-proces adapter, exposing a HTTP server and serving metrics of the local JVM.
The code leverages the Prometheus Java Client and include the instrumentation logic into a Metadata Adapter class.
This metrics exporter is intended to be run as a Lightsteamer in-proces adapter, exposing an HTTP server and serving metrics of the local JVM.

![architecture](metrics_exporter_schema.png)

The code leverages the Prometheus Java Client and include the instrumentation logic into a Metadata Adapter class.
A custom collector is implemented to proxy metrics coming from MBeans with a one-to-one mapping between MBean attribute and Prometheus metric.
The format of a metric is something like:

<server_name>_<bean_name>_<attribute_name>{beanpropertyName1="beanPropertyValue1", ...}: value

examples:

```
lightstreamer_Stream_CumulItemUpdates 381.0
lightstreamer_ThreadPool_Throughput{name="EVENTS",} 4.0
lightstreamer_ThreadPool_Throughput{name="PUMP",} 5.997
lightstreamer_ThreadPool_Throughput{name="SNAPSHOT",} 0.0
lightstreamer_DataAdapter_InboundEventFrequency{AdapterSetName="WELCOME",DataAdapterName="CHAT",} 0.0
lightstreamer_DataAdapter_InboundEventFrequency{AdapterSetName="DEMO",DataAdapterName="QUOTE_ADAPTER",} 1.5
```

### Configuration

Metrics will be accessible at `http://localhost:<metrics_port>/` or `http://<hostname>:<metrics_port>/` where <hostname> is the hostanme of the machine and <metrics_port> is a configuration parameter
in the `adapters.xml` file.

## Other GitHub projects using this library
Only a subset of [all attributes available from JMX](https://sdk.lightstreamer.com/ls-jmx-sdk/5.6.0/api/index.html) are considered for export.
Currently the filtering criteria are hard-coded in the enum MBeanFilter, but it is planned to implement the possibility of configure these criteria through the 'adapters.xml' configuration file.

## Install

To install the *Lightstreamer Metrics Exporter Adapter Set* in your local Lightstreamer Server: get the `deploy.zip` file of the [latest release](), unzip it, and copy the `metrics_exporter` folder into the `adapters` folder of your Lightstreamer Server installation.
A Lightstreamer Server reboot is needed.


## Build

To build your own version of `lightstreamer-utility-metricsexporter-adapter-0.1.0` instead of using the one provided in the `deploy.zip` file from the [Install]() section above, you have two options:
either use [Maven](https://maven.apache.org/) (or other build tools) to take care of dependencies and building (recommended) or gather the necessary jars yourself and build it manually.
For the sake of simplicity only the Maven case is detailed here.

### Maven

You can easily build and run this application using Maven through the pom.xml file located in the root folder of this project. As an alternative, you can use an alternative build tool (e.g. Gradle, Ivy, etc.) by converting the provided pom.xml file.

- [Lightstreamer - Reusable Metadata Adapters - Java Remote Adapter ](https://github.com/Lightstreamer/Lightstreamer-example-ReusableMetadata-adapter-java-remote)
Assuming Maven is installed and available in your path you can build the demo by running
```sh
mvn install dependency:copy-dependencies
```

## Support

For questions and support please use the [Official Forum](https://forums.lightstreamer.com/). The issue list of this page is **exclusively**
for bug reports and feature requests.
For questions and support please use the [Official Forum](https://forums.lightstreamer.com/).
The issue list of this page is **exclusively** for bug reports and feature requests.

## License

Expand Down
Binary file modified metrics_exporter_schema.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
/*
* Copyright (c) Lightstreamer Srl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.lightstreamer.utility;

import java.io.File;
Expand Down
21 changes: 17 additions & 4 deletions src/main/java/com/lightstreamer/utility/NTDDataAdapter.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
/*
* Copyright (c) Lightstreamer Srl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.lightstreamer.utility;

import java.io.File;
Expand All @@ -10,19 +23,19 @@
import com.lightstreamer.interfaces.data.ItemEventListener;
import com.lightstreamer.interfaces.data.SubscriptionException;


public class NTDDataAdapter implements DataProvider {

private volatile ItemEventListener listener;


public void subscribe(String itemName, boolean needsIterator)
throws SubscriptionException {
// ...
return ;
throw new SubscriptionException("This Data Adapter not support any subscription");
}

public void unsubscribe(String itemName) {
// ...
// Should never happen
return ;
}

Expand All @@ -32,7 +45,7 @@ public boolean isSnapshotAvailable(String itemName) {

@Override
public void init(Map params, File configDir) throws DataProviderException {
// ...
// Nothing to do

return ;
}
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/lightstreamer/utility/metrics/Metrics.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
/*
* Copyright (c) Lightstreamer Srl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.lightstreamer.utility.metrics;

import com.lightstreamer.utility.metrics.jmx.JMXMetricsCollector;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
/*
* Copyright (c) Lightstreamer Srl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.lightstreamer.utility.metrics;

import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
/*
* Copyright (c) Lightstreamer Srl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.lightstreamer.utility.metrics.jmx;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
/*
* Copyright (c) Lightstreamer Srl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.lightstreamer.utility.metrics.jmx;

import javax.management.ObjectName;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
/*
* Copyright (c) Lightstreamer Srl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.lightstreamer.utility.metrics.jmx;

import static java.util.function.Predicate.not;
Expand Down Expand Up @@ -288,26 +301,10 @@ private void inititalize() {

fut = checkRegisterDelayedThreadPoolIfAny.scheduleAtFixedRate(() -> {
try {
// log.info("New re-check of DelayedThreadPoolIfAny");
// testRegisterDelayedThreadPool();
log.debug("Starting metrics exporter initialization...");

try {

// servers/0/com.lightstreamer/Server/type%3DServer/attributes/Status/
/*
Hashtable<String, String> props2 = new Hashtable<String, String>();
props2.put("type","Server");
ObjectName on3 = new ObjectName("com.lightstreamer", props2);
MBeanInfo mBeanInfo = serverConnection.getMBeanInfo(on3);
log.debug("Server MBean: ", mBeanInfo);
Arrays.asList(mBeanInfo.getAttributes())
.stream()
.peek(m -> {
log.debug("Collected attribute: {}.{}", on3, m.getName());
});*/

Server serv = serverConnection.getProxy("com.lightstreamer:type=Server", Server.class);

log.info("Lightstreamer Server Status: {}", serv.getStatus());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
/*
* Copyright (c) Lightstreamer Srl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.lightstreamer.utility.metrics.jmx;

import java.util.stream.Stream;
Expand Down

This file was deleted.

13 changes: 13 additions & 0 deletions src/main/java/com/lightstreamer/utility/metrics/jmx/Resource.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
/*
* Copyright (c) Lightstreamer Srl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.lightstreamer.utility.metrics.jmx;

import java.util.Map;
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/lightstreamer/utility/metrics/jmx/Server.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
/*
* Copyright (c) Lightstreamer Srl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.lightstreamer.utility.metrics.jmx;

public interface Server {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
/*
* Copyright (c) Lightstreamer Srl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.lightstreamer.utility.metrics.jmx;

import java.util.List;
Expand Down

0 comments on commit edb2ad5

Please sign in to comment.