Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wuriyanto48/jvm-stash
Logstash Client library for Java Virtual Machine
https://github.com/wuriyanto48/jvm-stash
elastic elasticsearch elk elk-stack java kibana logstash-client
Last synced: 4 days ago
JSON representation
Logstash Client library for Java Virtual Machine
- Host: GitHub
- URL: https://github.com/wuriyanto48/jvm-stash
- Owner: wuriyanto48
- License: mit
- Created: 2020-05-01T18:40:11.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-11-16T09:22:16.000Z (about 2 years ago)
- Last Synced: 2024-11-19T13:51:41.199Z (about 2 months ago)
- Topics: elastic, elasticsearch, elk, elk-stack, java, kibana, logstash-client
- Language: Java
- Homepage:
- Size: 35.2 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## JVM Stash
Logstash Client for Java Virtual Machine>##### Note (If you use TLS)
> You should convert your server certificate into PKCS12 format.```shell
$ openssl pkcs12 -export -inkey your_server.key -in your_server.crt -out server.p12
```### Install
```xmlcom.wuriyanto
jvm-stash
1.0```
### Usage
#### Basic
```java
Stash stash = new Stash.Builder()
.setHost("localhost")
.setPort(5000)
.build();try {
stash.connect();
} catch (StashException e) {
System.out.println(e.getMessage());
System.exit(1);
}stash.write("hello logstash".getBytes())
try {
stash.close();
} catch (IOException e) {
System.out.println(e.getMessage());
System.exit(1);
}
```#### TLS Connection
Assumed you already enable `ssl` config inside `logstash.conf`
```config
input {
tcp {
port => 5000
ssl_enable => true
ssl_cert => "/etc/server.crt"
ssl_key => "/etc/server.key"
ssl_verify => false
}
}
```Let's write some code again
```java
InputStream keyStore = null;try {
keyStore = new FileInputStream("/path/to/your/server.p12");
} catch (Exception e) {
System.out.println(e.getMessage());
System.exit(1);
}Stash stash = new Stash.Builder()
.setHost("localhost")
.setPort(5000)
// makesure set to true
.setSecure(true)
.setKeyStoreIs(keyStore)
.setKeyStorePassword("damn12345")
.build();try {
stash.connect();
} catch (StashException e) {
System.out.println(e.getMessage());
System.exit(1);
}stash.write("hello logstash".getBytes())
try {
stash.close();
} catch (IOException e) {
System.out.println(e.getMessage());
System.exit(1);
}
```#### With Java's standar logging
```java
private static final Logger LOGGER = Logger.getLogger(AppLogger.class.getName());public static void main(String[] args) throws StashException {
InputStream keyStore = null;
try {
keyStore = new FileInputStream("/path/to/your/server.p12");
} catch (Exception e) {
System.out.println(e.getMessage());
System.exit(1);
}
Stash stash = new Stash.Builder()
.setHost("localhost")
.setPort(5000)
// makesure set to true
.setSecure(true)
.setKeyStoreIs(keyStore)
.setKeyStorePassword("damn12345")
.build();
try {
stash.connect();
} catch (StashException e) {
System.out.println(e.getMessage());
System.exit(1);
}
// Set Handler with StashLogHandler
LOGGER.addHandler(new StashLogHandler(stash));
// Use standar log that uses StashLogHandler
LOGGER.log(Level.INFO, "hello");
try {
stash.close();
} catch (IOException e) {
System.out.println(e.getMessage());
System.exit(1);
}
```#### Spring Boot Integration
https://github.com/wuriyanto48/spring-boot-starter-jvmstash