-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
205 additions
and
57 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
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,86 @@ | ||
[[customizing]] | ||
== Customizing == | ||
|
||
[[customizing-notifiers]] | ||
=== Custom Notifiers === | ||
|
||
You can add your own Notifiers by adding Spring Beans which implement the `Notifier` interface, at best by extending | ||
`AbstractEventNotifier` or `AbstractStatusChangeNotifier` | ||
|
||
[source,java,indent=0] | ||
---- | ||
include::{samples-dir}/spring-boot-admin-sample-servlet/src/main/java/de/codecentric/boot/admin/CustomNotifier.java[tags=customization-notifiers] | ||
---- | ||
|
||
[[customizing-headers]] | ||
=== Injecting Custom HTTP Headers === | ||
|
||
In case you need to inject custom HTTP headers into the requests made to the monitored application's actuator endpoints you can easily add a `HttpHeadersProvider`: | ||
|
||
[source,java,indent=0] | ||
---- | ||
include::{samples-dir}/spring-boot-admin-sample-servlet/src/main/java/de/codecentric/boot/admin/SpringBootAdminApplication.java[tags=customization-http-headers-providers] | ||
---- | ||
|
||
[[customizing-instance-filter]] | ||
=== Intercepting Requests And Responses === | ||
|
||
You can intercept and modify requests and responses made to the monitored application's actuator endpoints by implementing the `InstanceExchangeFilterFunction` interface. | ||
This can be useful for auditing or adding some extra security checks. | ||
|
||
[source,java,indent=0] | ||
---- | ||
include::{samples-dir}/spring-boot-admin-sample-servlet/src/main/java/de/codecentric/boot/admin/SpringBootAdminApplication.java[tags=customization-instance-exchange-filter-function] | ||
---- | ||
|
||
[[customizing-custom-views]] | ||
=== Custom Views === | ||
|
||
It is possible to add custom views to the ui. The views must be implemented as https://vuejs.org/[Vue.js] components. | ||
|
||
The Javascript-Bundle and Css-Stlysheet must be placed on the classpath at `/META-INF/spring-boot-admin-server-ui/extensions/{name}/` so the server can pick them up. | ||
The {github-src}/spring-boot-admin-samples/spring-boot-admin-sample-custom-ui/[spring-boot-admin-sample-custom-ui] module contains a sample which has the necessary maven setup to build such a module. | ||
|
||
The custom extension registers itself by calling `SBA.use()` and need to expose a `install()` function, which is called by the ui when setting up the routes. | ||
The `install()` function receives a parameter object referencing the {github-src}/spring-boot-admin-server-ui/src/main/frontend/viewRegistry.js[viewRegistry] and the {github-src}/spring-boot-admin-server-ui/src/main/frontend/store.js[applicationStore] in order to register views and/or callbacks. | ||
|
||
[[customizing-custom-views-top-level]] | ||
==== Adding a Top-Level View ==== | ||
|
||
Here is a simple top level view just listing all registered applications: | ||
[source,html] | ||
---- | ||
include::{samples-dir}/spring-boot-admin-sample-custom-ui/src/custom.vue[lines=17..-1] | ||
---- | ||
<1> If you define a `applications` prop the component will receive all registered applications. | ||
|
||
TIP: There are some helpful methods on the application and instances object available. Have a look at {github-src}/spring-boot-admin-server-ui/src/main/frontend/services/application.js[application.js] and {github-src}/spring-boot-admin-server-ui/src/main/frontend/services/instance.js[instance.js] | ||
|
||
And this is how you register the top-level view. | ||
[source,javascript] | ||
---- | ||
include::{samples-dir}/spring-boot-admin-sample-custom-ui/src/index.js[tags=customization-ui-toplevel] | ||
---- | ||
<1> Name of the view and the route to the view | ||
<2> Path where the view will be accessible | ||
<3> The imported custom component, which will be rendered on the route. | ||
<4> The label for the custom view to be shown in the top navigation bar. | ||
<5> Order for the view. Views in the top navigation bar are sorted by ascending order. | ||
|
||
[[customizing-custom-views-instance]] | ||
==== Visualizing a Custom Endpoint ==== | ||
Here is a view to show a custom endpoint: | ||
[source,html] | ||
---- | ||
include::{samples-dir}/spring-boot-admin-sample-custom-ui/src/custom-endpoint.vue[lines=17..-1] | ||
---- | ||
<1> If you define a `instance` prop the component will receive the instance the view should be rendered for. | ||
<2> Each instance has a preconfigured https://github.com/axios/axios[axios] instance to access the endpoints with the correct path and headers. | ||
|
||
Registering the instance view works like for the top-level view with some additional properties: | ||
[source,javascript] | ||
---- | ||
include::{samples-dir}/spring-boot-admin-sample-custom-ui/src/index.js[tags=customization-ui-endpoint] | ||
---- | ||
<1> The parent must be 'instances' in order to render the new custom view for a single instance. | ||
<2> If you add a `isEnabled` callback you can figure out dynamically if the view should be show for the particular instance. |
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
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
51 changes: 51 additions & 0 deletions
51
...ing-boot-admin-sample-servlet/src/main/java/de/codecentric/boot/admin/CustomNotifier.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,51 @@ | ||
/* | ||
* Copyright 2014-2018 the original author or authors. | ||
* | ||
* 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 de.codecentric.boot.admin; | ||
|
||
import de.codecentric.boot.admin.server.domain.entities.Instance; | ||
import de.codecentric.boot.admin.server.domain.entities.InstanceRepository; | ||
import de.codecentric.boot.admin.server.domain.events.InstanceEvent; | ||
import de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent; | ||
import de.codecentric.boot.admin.server.notify.AbstractEventNotifier; | ||
import de.codecentric.boot.admin.server.notify.LoggingNotifier; | ||
import reactor.core.publisher.Mono; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
// tag::customization-notifiers[] | ||
public class CustomNotifier extends AbstractEventNotifier { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(LoggingNotifier.class); | ||
|
||
public CustomNotifier(InstanceRepository repository) { | ||
super(repository); | ||
} | ||
|
||
@Override | ||
protected Mono<Void> doNotify(InstanceEvent event, Instance instance) { | ||
return Mono.fromRunnable(() -> { | ||
if (event instanceof InstanceStatusChangedEvent) { | ||
LOGGER.info("Instance {} ({}) is {}", instance.getRegistration().getName(), event.getInstance(), | ||
((InstanceStatusChangedEvent) event).getStatusInfo().getStatus()); | ||
} else { | ||
LOGGER.info("Instance {} ({}) {}", instance.getRegistration().getName(), event.getInstance(), | ||
event.getType()); | ||
} | ||
}); | ||
} | ||
} | ||
// end::customization-notifiers[] |
Oops, something went wrong.