Skip to content

Commit 81e78ef

Browse files
Merge branch 'main' into umutn-mcp-readme-v1
2 parents 3875145 + 6a77f60 commit 81e78ef

File tree

20 files changed

+1558
-0
lines changed

20 files changed

+1558
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Copyright (c) 2025 Oracle and/or its affiliates.
2+
3+
The Universal Permissive License (UPL), Version 1.0
4+
5+
Subject to the condition set forth below, permission is hereby granted to any
6+
person obtaining a copy of this software, associated documentation and/or data
7+
(collectively the "Software"), free of charge and under any and all copyright
8+
rights in the Software, and any and all patent rights owned or freely
9+
licensable by each licensor hereunder covering either (i) the unmodified
10+
Software as contributed to or provided by such licensor, or (ii) the Larger
11+
Works (as defined below), to deal in both
12+
13+
(a) the Software, and
14+
(b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
15+
one is included with the Software (each a "Larger Work" to which the Software
16+
is contributed by such licensors),
17+
18+
without restriction, including without limitation the rights to copy, create
19+
derivative works of, display, perform, and distribute the Software and make,
20+
use, sell, offer for sale, import, export, have made, and have sold the
21+
Software and the Larger Work(s), and to sublicense the foregoing rights on
22+
either these or other terms.
23+
24+
This license is subject to the following condition:
25+
The above copyright notice and either this complete permission notice or at
26+
a minimum a reference to the UPL must be included in all copies or
27+
substantial portions of the Software.
28+
29+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35+
SOFTWARE.
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
<!--
2+
Copyright (c) 2025 Oracle and/or its affiliates.
3+
4+
The Universal Permissive License (UPL), Version 1.0
5+
6+
Subject to the condition set forth below, permission is hereby granted to any
7+
person obtaining a copy of this software, associated documentation and/or data
8+
(collectively the "Software"), free of charge and under any and all copyright
9+
rights in the Software, and any and all patent rights owned or freely
10+
licensable by each licensor hereunder covering either (i) the unmodified
11+
Software as contributed to or provided by such licensor, or (ii) the Larger
12+
Works (as defined below), to deal in both
13+
14+
(a) the Software, and
15+
(b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
16+
one is included with the Software (each a "Larger Work" to which the Software
17+
is contributed by such licensors),
18+
19+
without restriction, including without limitation the rights to copy, create
20+
derivative works of, display, perform, and distribute the Software and make,
21+
use, sell, offer for sale, import, export, have made, and have sold the
22+
Software and the Larger Work(s), and to sublicense the foregoing rights on
23+
either these or other terms.
24+
25+
This license is subject to the following condition:
26+
The above copyright notice and either this complete permission notice or at
27+
a minimum a reference to the UPL must be included in all copies or
28+
substantial portions of the Software.
29+
30+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
31+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
32+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
33+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
34+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
35+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36+
SOFTWARE.
37+
-->
38+
39+
# OCI Container Instances Grafana and Prometheus example with Java Sprinboot
40+
## With multiple volumes and a custom sidecar to tail access log to OCI Logging and mount the Grafana and Prometheus configs from OCI Object Storage bucket for live changes
41+
42+
Reviewed: 4.12.2025
43+
44+
## When to use this asset?
45+
46+
Anyone who wants to experiment with OCI Container Instances and setup a multi-container instance with multiple volumes and have a setup for Prometheus and Grafana. Including:
47+
48+
<ul>
49+
<li>Node exporter for the OCI container instance metrics</li>
50+
<li>Spring Boot Java exporter for app metrics</li>
51+
<li>Logs are exported to OCI Logging with a custom sidecar. Springboot app log is configured to <code>resources/application.properties</code> as <code>/var/log/app.log</code></li>
52+
<li>Custom sidecar also pulls configs in 30s intervals from a Object Storage private bucket for easy config changes to <code>/etc</code> of Prometheus and Grafana containers' shared volume</li>
53+
</ul>
54+
55+
## Author
56+
<a href="https://github.com/mikarinneoracle">mikarinneoracle</a>
57+
58+
## How to use this asset?
59+
60+
## Build containers
61+
62+
Build containers with GitHub Actions <code>containers.yml</code>pipeline
63+
<p>
64+
65+
This requires three secrets:
66+
<pre>
67+
DOCKER_USERNAME
68+
AUTH_TOKEN
69+
TENANCY_NAMESPACE
70+
</pre>
71+
72+
It uses <code>FRA</code> region for OCIR, i.e. Registry is <code>fra.ocir.io</code>
73+
74+
## Create object storage bucket with Prometheus and Grafana configs
75+
76+
Bucket name: <code>prometheus-grafana</code> (default, can be changed when deploying the Stack)
77+
<p>
78+
Directories in the bucket:
79+
<pre>
80+
├── grafana/
81+
│ └── provisioning/
82+
│ ├── dashboards/
83+
│ └── datasources/
84+
└── prometheus/
85+
</pre>
86+
Upload files from <code>object-storage</code> to the directory structure above in the bucket.
87+
<p>
88+
<b>Note!</b> Remember to change the <code>username</code> and <code>password</code> in <code>grafana.ini</code> before uploading!
89+
90+
## Deploy the Container Instances with the Terraform Stack
91+
92+
Deploy the Container Instances stack with OCI Resource Manager (Terraform). First clone this repo to localhost and drag-drop the terraform folder to OCI Resource Manager to create a new Stack. Then configure the stack and apply.
93+
<p>
94+
95+
Subnet ports can be opened for the following access:
96+
<ul>
97+
<li>8080 for the Springboot app</li>
98+
<li>3000 for Grafana</li>
99+
<li>9090 for Prometheus (optional)</li>
100+
</ul>
101+
<p>
102+
103+
For taking this to a a quick spin, you can create/use a VCN with a public subnet to have public access to Grafana.
104+
VCN and subnet creation including the ports above is manual and not included in the Terraform Stack.
105+
<p>
106+
107+
Also the OCI Log needs to be created manually for logging.
108+
<p>
109+
110+
Once created git clone this repo and drag&drop the terraform folder to OCI Resource Manager when creating a new Stack.
111+
Then, configure the stack vars and apply to have the stack deployed for testing. Destroy and delete after finishing the test.
112+
113+
114+
## Useful Links
115+
116+
- [OCI Container Instances](https://www.oracle.com/cloud/cloud-native/container-instances/)
117+
- Learn how OCI Container Instances lets you easily run applications on serverless compute optimized for containers
118+
- [OCI SDK](https://docs.oracle.com/en-us/iaas/Content/API/Concepts/sdks.htm)
119+
- Oracle Cloud Infrastructure provides a number of Software Development Kits (SDKs) and a Command Line Interface (CLI) to facilitate development of custom solutions
120+
- [OCI Logging](https://docs.oracle.com/en-us/iaas/Content/Logging/Concepts/loggingoverview.htm)
121+
- The Oracle Cloud Infrastructure Logging service is a highly scalable and fully managed single pane of glass for all the logs in your tenancy. Logging provides access to logs from Oracle Cloud Infrastructure resources
122+
- [OCI Object Storage](https://www.oracle.com/cloud/storage/object-storage/)
123+
- Oracle Cloud Infrastructure (OCI) Object Storage provides scalable, durable, low-cost storage for any type of data. Benefit from 11 nines of durability. Scale storage to nearly unlimited capacity for your unstructured data
124+
- [Oracle](https://www.oracle.com/)
125+
- Oracle Website
126+
127+
## License
128+
129+
Copyright (c) 2025 Oracle and/or its affiliates.
130+
131+
Licensed under the Universal Permissive License (UPL), Version 1.0.
132+
133+
See [LICENSE](LICENSE) for more details.
134+
135+
ORACLE AND ITS AFFILIATES DO NOT PROVIDE ANY WARRANTY WHATSOEVER, EXPRESS OR IMPLIED, FOR ANY SOFTWARE, MATERIAL OR CONTENT OF ANY KIND CONTAINED OR PRODUCED WITHIN THIS REPOSITORY, AND IN PARTICULAR SPECIFICALLY DISCLAIM ANY AND ALL IMPLIED WARRANTIES OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. FURTHERMORE, ORACLE AND ITS AFFILIATES DO NOT REPRESENT THAT ANY CUSTOMARY SECURITY REVIEW HAS BEEN PERFORMED WITH RESPECT TO ANY SOFTWARE, MATERIAL OR CONTENT CONTAINED OR PRODUCED WITHIN THIS REPOSITORY. IN ADDITION, AND WITHOUT LIMITING THE FOREGOING, THIRD PARTIES MAY HAVE POSTED SOFTWARE, MATERIAL OR CONTENT TO THIS REPOSITORY WITHOUT ANY REVIEW. USE AT YOUR OWN RISK.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM openjdk:26-ea-21-oraclelinux8
2+
3+
EXPOSE 8080
4+
5+
WORKDIR /
6+
COPY ./target/PrometheusJavaDemo-0.0.1-SNAPSHOT.jar /
7+
CMD java -jar PrometheusJavaDemo-0.0.1-SNAPSHOT.jar
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-starter-parent</artifactId>
8+
<version>3.5.7</version>
9+
<relativePath/> <!-- lookup parent from repository -->
10+
</parent>
11+
<groupId>com.example.java.</groupId>
12+
<artifactId>PrometheusJavaDemo</artifactId>
13+
<version>0.0.1-SNAPSHOT</version>
14+
<name>demo</name>
15+
<description>SignUp project for Spring Boot with Redis</description>
16+
<url/>
17+
<licenses>
18+
<license/>
19+
</licenses>
20+
<developers>
21+
<developer/>
22+
</developers>
23+
<scm>
24+
<connection/>
25+
<developerConnection/>
26+
<tag/>
27+
<url/>
28+
</scm>
29+
<properties>
30+
<java.version>21</java.version>
31+
</properties>
32+
<dependencies>
33+
<dependency>
34+
<groupId>org.springframework.boot</groupId>
35+
<artifactId>spring-boot-starter-web</artifactId>
36+
</dependency>
37+
<dependency>
38+
<groupId>org.springframework.boot</groupId>
39+
<artifactId>spring-boot-starter-test</artifactId>
40+
<scope>test</scope>
41+
</dependency>
42+
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-actuator -->
43+
<dependency>
44+
<groupId>org.springframework.boot</groupId>
45+
<artifactId>spring-boot-starter-actuator</artifactId>
46+
<version>3.5.7</version>
47+
</dependency>
48+
<!-- https://mvnrepository.com/artifact/io.micrometer/micrometer-registry-prometheus -->
49+
<dependency>
50+
<groupId>io.micrometer</groupId>
51+
<artifactId>micrometer-registry-prometheus</artifactId>
52+
<version>1.15.5</version>
53+
<scope>runtime</scope>
54+
</dependency>
55+
<!-- https://mvnrepository.com/artifact/io.prometheus/prometheus-metrics-core -->
56+
<dependency>
57+
<groupId>io.prometheus</groupId>
58+
<artifactId>prometheus-metrics-core</artifactId>
59+
<version>1.4.1</version>
60+
</dependency>
61+
<!-- https://mvnrepository.com/artifact/io.prometheus/prometheus-metrics-exporter-servlet-jakarta -->
62+
<dependency>
63+
<groupId>io.prometheus</groupId>
64+
<artifactId>prometheus-metrics-exporter-servlet-jakarta</artifactId>
65+
<version>1.4.2</version>
66+
</dependency>
67+
<!-- https://mvnrepository.com/artifact/io.prometheus/prometheus-metrics-instrumentation-jvm -->
68+
<dependency>
69+
<groupId>io.prometheus</groupId>
70+
<artifactId>prometheus-metrics-instrumentation-jvm</artifactId>
71+
<version>1.4.1</version>
72+
</dependency>
73+
74+
</dependencies>
75+
76+
<build>
77+
<plugins>
78+
<plugin>
79+
<groupId>org.graalvm.buildtools</groupId>
80+
<artifactId>native-maven-plugin</artifactId>
81+
<configuration>
82+
<buildArgs>
83+
<buildArg>-Ob</buildArg>
84+
<buildArg>--emit build-report</buildArg>
85+
</buildArgs>
86+
</configuration>
87+
</plugin>
88+
<plugin>
89+
<groupId>org.springframework.boot</groupId>
90+
<artifactId>spring-boot-maven-plugin</artifactId>
91+
</plugin>
92+
</plugins>
93+
</build>
94+
95+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
Copyright (c) 2025 Oracle and/or its affiliates.
3+
4+
The Universal Permissive License (UPL), Version 1.0
5+
6+
Subject to the condition set forth below, permission is hereby granted to any
7+
person obtaining a copy of this software, associated documentation and/or data
8+
(collectively the "Software"), free of charge and under any and all copyright
9+
rights in the Software, and any and all patent rights owned or freely
10+
licensable by each licensor hereunder covering either (i) the unmodified
11+
Software as contributed to or provided by such licensor, or (ii) the Larger
12+
Works (as defined below), to deal in both
13+
14+
(a) the Software, and
15+
(b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
16+
one is included with the Software (each a "Larger Work" to which the Software
17+
is contributed by such licensors),
18+
19+
without restriction, including without limitation the rights to copy, create
20+
derivative works of, display, perform, and distribute the Software and make,
21+
use, sell, offer for sale, import, export, have made, and have sold the
22+
Software and the Larger Work(s), and to sublicense the foregoing rights on
23+
either these or other terms.
24+
25+
This license is subject to the following condition:
26+
The above copyright notice and either this complete permission notice or at
27+
a minimum a reference to the UPL must be included in all copies or
28+
substantial portions of the Software.
29+
30+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
31+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
32+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
33+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
34+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
35+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36+
SOFTWARE.
37+
*/
38+
39+
package org.example;
40+
41+
import io.prometheus.metrics.core.metrics.Counter;
42+
import io.prometheus.metrics.exporter.servlet.jakarta.PrometheusMetricsServlet;
43+
import io.prometheus.metrics.instrumentation.jvm.JvmMetrics;
44+
import org.springframework.boot.SpringApplication;
45+
import org.springframework.boot.autoconfigure.SpringBootApplication;
46+
import org.springframework.boot.web.servlet.ServletRegistrationBean;
47+
import org.springframework.context.annotation.Bean;
48+
import org.springframework.web.bind.annotation.GetMapping;
49+
import org.springframework.web.bind.annotation.RestController;
50+
import java.net.DatagramSocket;
51+
import java.net.InetAddress;
52+
import org.slf4j.Logger;
53+
import org.slf4j.LoggerFactory;
54+
55+
@SpringBootApplication
56+
@RestController
57+
public class PrometheusJavaDemo {
58+
59+
private int i = 0;
60+
private static final Counter requestCount = Counter.builder()
61+
.name("requests_total")
62+
.register();
63+
private static final Logger logger = LoggerFactory.getLogger(PrometheusJavaDemo.class);
64+
65+
public static void main(String[] args) {
66+
SpringApplication.run(PrometheusJavaDemo.class, args);
67+
JvmMetrics.builder().register();
68+
}
69+
70+
@GetMapping("/")
71+
public String sayHello() throws InterruptedException {
72+
requestCount.inc();
73+
String ip = "";
74+
try(final DatagramSocket socket = new DatagramSocket()){
75+
socket.connect(InetAddress.getByName("8.8.8.8"), 10002);
76+
ip = socket.getLocalAddress().getHostAddress();
77+
} catch (Exception e)
78+
{
79+
logger.info(e.getMessage());
80+
}
81+
i++;
82+
String message = "";
83+
if(i == 1)
84+
{
85+
//message = "Hello " + i + " <br>ip = " + ip;
86+
message = "CI just got refreshed! Hello " + i + " <br>ip = " + ip;
87+
} else {
88+
message = "Hello from CI " + i + " <br>ip = " + ip;
89+
}
90+
logger.info(message);
91+
return message;
92+
}
93+
94+
@Bean
95+
public ServletRegistrationBean<PrometheusMetricsServlet> createPrometheusMetricsEndpoint() {
96+
return new ServletRegistrationBean<>(new PrometheusMetricsServlet(), "/metrics/*");
97+
}
98+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
logging.file.name=/var/log/app.log

0 commit comments

Comments
 (0)