Java – Put CPU % into a local file by Cron job No.81

How to save the current CPU % on Ubuntu into a local file by Cron job with an execution of Jar is shown in this blog. ▼1. How to export the current CPU % on Ubuntu The command “top -b -n 1” is executed by Java and save only CPU % into a file. ▼2. Prerequisites This blog is based on Java – Capture CPU,Memory,Network info on Ubuntu No.79. ▼3. Java code to export the current CPU % on Ubuntu 3-1. Develop perfch2.java “perfch2.java” run the command “top -b -n 1” and save only CPU % into a file by Java. the file name of output is CPU{epochmilliseconds}.txt when file … Continue reading “Java – Put CPU % into a local file by Cron job No.81”

Java – Connect to MySQL on Ubuntu and run select query No.80

How to connect to MySQL and run select query is shown in this blog. ▼1. What is MySQL? MySQL, the most popular Open Source SQL database management system, is developed, distributed, and supported by Oracle Corporation. MySQL is available on some cloud services such as Azure, AWS, Oracle etc. ▼2. Prerequisites 2-1. Install JDK Install Java 8 openjdk x64 of zulu Set environment variables Use vi editor like “vi ~/.bashrc” and add below in ~/.bashrc export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-x64/ Check the value of $JAVA_HOME 2-2. Install Visual Studio Code https://code.visualstudio.com/docs/setup/linux 2-3. Install Maven Apache Kafka Word Count – Java No.44 “2-3. Installing Apache Maven” 2-4. Install the latest version of MySQL # … Continue reading “Java – Connect to MySQL on Ubuntu and run select query No.80”

Java – Capture CPU,Memory,Network info on Ubuntu No.79

In this blog, how to capture CPU, Memory, Disk, Network information by Java is shown.it would be helpful if you need narrow down the issue about connection failure to Database to find a root cause. ▼1. How to know CPU, Memory, Network status on Ubuntu We can know CPU, Memory, Network, Disk usage on Ubuntu to run the following commands. ▼2. Prerequisite 2-1. Install JDK Install Java 8 openjdk x64 of zulu Set environment variables Run vi command (vi ~/.bashrc) and update ~/.bashrc file as below. export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-x64/bin/ Check $JAVA_HOME 2-2. Install Visual Studio Code https://code.visualstudio.com/docs/setup/linux 2-3. Install Maven Apache Kafka Word Count – Java No.44 “2-3. Installing Apache Maven” … Continue reading “Java – Capture CPU,Memory,Network info on Ubuntu No.79”

Java – Connect to Azure Cosmos DB (SQL API) No.11

In this blog, how to connect to Cosmos DB SQL API by Java is shown. ▼1. Connect to Azure Cosmos DB Azure Cosmos DB is NoSQL Database. it is not Relational Database. we don’t need to set schema and table beforehand. we need to set partition key for a collection of a container to distribute data into the partitions. ▼2. Prerequisites 2-1. Prepare for a trial free Azure Cosmos DB Account, not necessary for a subscription https://cosmos.azure.com/try/ 2-2. Enable Maven auto-import in IntelliJ IDEA Enable auto-import on IntelliJ IDEA No.13 2-3. Update Pom.xml Please change the latest version each libraries. (a part of pom.xml) <dependencies> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-simple</artifactId> <version>1.7.30</version> </dependency> … Continue reading “Java – Connect to Azure Cosmos DB (SQL API) No.11”

Apache Kafka – Develop Producer Java application No.66

How to develop Producer application by Java on Visual Studio Code is shown in this blog. ▼1. Apache Kafka Ref: Apache Kafka ▼2. Prerequisites Install Apache Kafka 4 nodes No.42 Apache Kafka Word Count – Java No.44“2-3. Installing Apache Maven” ▼3. Develop Producer Java application This producer Java application write events from 1 to 100 into a topic. 3-1. Make a directoryMake a directory to develop an application. 3-2. Create a project using Apache Maven 3-3. Remove the App.java and AppTest.java files 3-4. Update pom.xml file Adding below in pom.xml(a part of pom.xml) Dependency Analytics Extension need to be installed on VS Code to check and update dependencies automatically. 3-5. … Continue reading “Apache Kafka – Develop Producer Java application No.66”

Java – Visual Studio Code on Ubuntu No.24

In this blog, How to run Java on Visual Studio Code on Ubuntu is shown. ▼1. Run Java using Visual Studio Code on Ubuntu Visual Studio Code is the developer tool provided by Microsoft. Visual Studio Code works on both Windows and Linux OS. in this case, VS Code is used on Ubuntu. ▼2. Prerequisites 2-1.Install Ubuntu Ubuntu 20.04.5 LTS 2-2. Setup Visual Studio Code 2-3. Install Java Extension Pack 2-4. Install JDK (OpenJDK 15) In this case, jdk-15.0.2+7 is under /home/user/Downloads/ path. 2-5. Set Environment variables for java.configuration.runtimes and java.home (e.g) { “java.home”:”/home/user/Downloads/jdk-15.0.2+7″, “java.configuration.runtimes”: [ { “name”:”JavaSE-15″, “path”:”/home/user/Downloads/jdk-15.0.2+7″ } ] } ▼3. Show Hello World by Java 3-1. Create … Continue reading “Java – Visual Studio Code on Ubuntu No.24”

Install IntelliJ IDEA on Ubuntu No.43

How to install IntelliJ IDEA on Ubuntu is shown in this blog. ▼1. What is IntelliJ IDEA? IntelliJ IDEA is a developer tool. Java, Kotlin, Groovy, Scala languages etc are available. there are 2 types Edition, Ultimate Edition and Community Edition for Free. ▼2. Installing IntelliJ IDEA 2-1. Download IntelliJ IDEA Community Edition We can download IntelliJ IDEA from this site Download IntelliJ IDEA. in this case, idealC-2021.2.3.tar.gz is used on Ubuntu 21.04. 2-2. Unzip downloaded IntelliJ IDEA Community Edition 2-3. Run idea.sh to start IntelliJ IDEA 2-4. Install Java 8 JDK Azul Zulu OpenJDK Java 8 (LTS) is used in this blog. How to install this JDK is shown … Continue reading “Install IntelliJ IDEA on Ubuntu No.43”

Apache Kafka Word Count – Java No.44

How to count the words in topic by Java is shown. ▼1. Steps of counting words in a topic by Java ▼2. Prerequisites 2-1. Installing an Apache Kafka cluster Install Apache Kafka 4 nodes No.42 2-2. Installing IntelliJ IDEA Install IntelliJ IDEA on Ubuntu No.43 2-3. Installing Apache Maven Maven – Download Apache Maven 2-4. Setting parameters of $KAFKABROKERS and $KAFKAZOOKEEPER 2-5. Creating the topic for both input and output ▼3. Counting words in a topic by Java 3-1. Creating a project of IntelliJ IDEA Creating a new project 3-2. Confirming the version 1.8 of JDK is used 3-3. Putting the following information while creating a project 3-4. Updating pom.xml … Continue reading “Apache Kafka Word Count – Java No.44”

Install Apache Kafka 4 nodes No.42

How to install Apache Kafka 4 nodes is shown here. 4 ubuntu nodes are used for Apache Kafka. ▼1. What is Apache Kafka? Kafka combines three key capabilities. Ref: Apache Kafka ▼2. Installing Apache Kafka with 4 nodes 2-1. Preparing for 4 Ubuntu 20.04.01 LTS x64 nodes One node is used for Zookeeper Server. other 3 nodes are used to provide Kafka Broker services. 2-2. Updating hosts file on 4 nodes 2-3. Installing Java 8 JDK on 4 nodes Azul Zulu OpenJDK Java 8 (LTS) is used for this Kafka. Download Azul Zulu Builds of OpenJDK | Azul 2-4. Installing Apache Kafka on 4 nodes There is a download site … Continue reading “Install Apache Kafka 4 nodes No.42”

Apache Kafka – Consumer Java – Duplicate Messages No.78

In this blog, Duplicate messages in Consumer are shown using Java with false of enable.auto.commit property. ▼1. What is enable.auto.commit property? Setting enable.auto.commit means that offsets are committed automatically. if it is false, committing offset is needed in producer. KafkaConsumer (clients 0.9.0.1 API) (apache.org) ”Manual Offset Control” ▼2. Prerequisites ▼3. Reproducing duplicate messages in Consumer Setting Auto Commit to false and adding commit offset in Consumer are usually executed to read messages in Java. for the purpose of reproducing duplicate messages, I commented out commitSync() in this case. 3-1. Deploying Consumer Java application Setting enable.auto.commit to false. 3-2. Runing Producer and write 5 messages in a topic Apache Kafka – Develop … Continue reading “Apache Kafka – Consumer Java – Duplicate Messages No.78”