-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Sanjula Ganepola <Sanjula.Ganepola@ibm.com>
- Loading branch information
1 parent
a981da3
commit 71587bc
Showing
21 changed files
with
205 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "java", | ||
"name": "Run Manzan", | ||
"request": "launch", | ||
"mainClass": "com.github.theprez.manzan.ManzanMainApp", | ||
"projectName": "manzan", | ||
"args": "--configdir=${workspaceFolder}/config" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
camel/src/main/java/com/github/theprez/manzan/routes/dest/GrafanaLokiDestination.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package com.github.theprez.manzan.routes.dest; | ||
|
||
import java.sql.Timestamp; | ||
|
||
import com.github.theprez.manzan.ManzanEventType; | ||
import com.github.theprez.manzan.routes.ManzanRoute; | ||
|
||
import pl.mjaron.tinyloki.ILogStream; | ||
import pl.mjaron.tinyloki.Labels; | ||
import pl.mjaron.tinyloki.LogController; | ||
import pl.mjaron.tinyloki.StreamBuilder; | ||
import pl.mjaron.tinyloki.TinyLoki; | ||
|
||
public class GrafanaLokiDestination extends ManzanRoute { | ||
private final LogController logController; | ||
private final static String endpoint = "/loki/api/v1/push"; | ||
private final static String appLabelName = "app"; | ||
private final static String appLabelValue = "manzan"; | ||
|
||
public GrafanaLokiDestination(final String _name, final String _url, final String _username, final String _password, | ||
final String _format) { | ||
super(_name); | ||
|
||
logController = TinyLoki | ||
.withUrl(_url + endpoint) | ||
.withBasicAuth(_username, _password) | ||
.start(); | ||
|
||
Runtime.getRuntime().addShutdownHook(new Thread() { | ||
@Override | ||
public void run() { | ||
try { | ||
logController | ||
.softStop() | ||
.hardStop(); | ||
} catch (final Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
//@formatter:off | ||
@Override | ||
public void configure() { | ||
from(getInUri()) | ||
.routeId(m_name).process(exchange -> { | ||
final ManzanEventType type = (ManzanEventType) exchange.getIn().getHeader(EVENT_TYPE); | ||
if(ManzanEventType.WATCH_MSG == type) { | ||
StreamBuilder builder = logController | ||
.stream() | ||
.l(appLabelName, appLabelValue) | ||
.l(Labels.LEVEL, ((Integer) get(exchange, MSG_SEVERITY)) > SEVERITY_LIMIT ? Labels.FATAL : Labels.INFO) | ||
.l(SESSION_ID, getWatchName(exchange)); | ||
|
||
String[] keys = { | ||
MSG_MESSAGE_ID, | ||
MSG_MESSAGE_TYPE, | ||
MSG_SEVERITY, | ||
JOB, | ||
MSG_SENDING_USRPRF, | ||
MSG_SENDING_PROGRAM_NAME, | ||
MSG_SENDING_MODULE_NAME, | ||
MSG_SENDING_PROCEDURE_NAME | ||
}; | ||
|
||
for (String key: keys) { | ||
String value = getString(exchange, key); | ||
if(!value.equals("")) { | ||
builder.l(key, value); | ||
} | ||
} | ||
|
||
ILogStream stream = builder.build(); | ||
stream.log(Timestamp.valueOf(getString(exchange, MSG_MESSAGE_TIMESTAMP)).getTime(), getBody(exchange, String.class)); | ||
} else { | ||
throw new RuntimeException("Grafana Loki route doesn't know how to process type "+type); | ||
} | ||
}); | ||
} | ||
//@formatter:on | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Grafana Loki | ||
|
||
This example shows how to use `loki` as a destination for a `watch` data source. | ||
|
||
## Configuration | ||
|
||
Be sure to have read up on [Manzan configuration](/config/index.md) to understand where these files exist on your system. | ||
|
||
### `data.ini` | ||
|
||
```ini | ||
type=watch | ||
id=sanjula | ||
destinations=loki_out | ||
format=$MESSAGE_ID$ (severity $SEVERITY$): $MESSAGE$ | ||
strwch=WCHMSG((*ALL)) WCHMSGQ((*HSTLOG)) | ||
``` | ||
|
||
### `dests.ini` | ||
|
||
```ini | ||
[loki_out] | ||
type=loki | ||
url=<loki_url> | ||
username=<loki_username> | ||
password=<loki_password> | ||
``` | ||
|
||
## Result | ||
|
||
<div style="text-align: center; margin: 20px;"> | ||
<img src="../../images/grafanaLoki1.png" alt="Grafana Loki 1" style="box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); border-radius: 8px; max-width: 100%; display: block; margin-bottom: 20px;"> | ||
<img src="../../images/grafanaLoki2.png" alt="Grafana Loki 2" style="box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); border-radius: 8px; max-width: 100%;"> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.