Friday, February 14, 2020

Full Guide for using Bitnami Prometheus Operator Helm Chart with Additional Scrape Configuration

"The Prometheus Operator for Kubernetes provides easy monitoring definitions for Kubernetes services and deployment and management of Prometheus instances."
Bitnami kindly provided/maintained a Helm Chart of Prometheus Operator make it easy to start/deploy the Prometheus Operator in Kubernetes Cluster. Today, we will walk through the steps to get it running in your Kubernetes cluster.


  • Set up Helm and add Bitnami Helm Repo
    • You need have a Kubernetes cluster ready to deploy the Prometheus Operator on, I am using the docker-desktop cluster running on Windows 10. 
    • You need do "helm init" to install the Tiller to your running K8S cluster.
    • You need run "helm repo add bitnami https://charts.bitnami.com/bitnami" to add Bitnami Helm Repo.
  • Create the secret that contains your Additional Scrape Configuration
    • Create a local file named: additional-scrape-configs.yaml with content looks like:
    • Run the following command to make a secret out of the configuration file:
    • Apply the secret file to create the secret in your Kubernetes Cluster:
  • Install the bitnami/prometheus-operator Helm chart
  • Port forwarding for the prometheus to access it from your host machine
    • If everything went well, you should be able to access the prometheus from you host's web browser at http://localhost:9090
  • Last, you can start your prometheus instrumented app on your host to let the prometheus scrape some data.
    • You can go to the Targets on http://localhost:9090 to verify that the static target(s) configured Additional Scrape Configuration is UP.
If you don't have the correct named secret created or the format is malformed, the prometheus pod will not be started, and it is pretty hard to understand what is going on. Luckily you can watch the log from your svc/prometheus-operator-operator by using the following command to diagnose:
  • kubectl logs -f  svc/prometheus-operator-operator

Monday, February 10, 2020

Using FFmpeg streaming unix desktop to windows via UDP

"FFmpeg is a free and open-source project consisting of a vast software suite of libraries and programs for handling video, audio, and other multimedia files and streams."

FFmpeg is powerful, and sometime it is hard to figure out what exact the parameters to be used to achieve your goal with it. Today, we will teach you how to streaming Linux desktop to remote windows by using FFmpeg.

First, on your linux box start the FFmpeg streaming with the following command:

Note: The IP in the UDP url should be the remote windows IP. The FFmpeg will post the streaming data to that IP.

Then, on your remote windows box, start VLC 2.2.5 (an older version, be aware of that the current version 3.0.8, will not work, it just shows black screen when connect to the UDP streaming on windows), add a Network Stream:

udp://@0.0.0.01234

Voila, now you can view your Linux desktop on Windows now.

Wednesday, January 22, 2020

NATS multiple seed cluster

"NATS.io is a simple, secure and high performance open source messaging system for cloud native applications, IoT messaging, and microservices architectures."

There are some documents for NATS clustering, here and here.

Today, we would like to start a NATS cluster with two seed servers, the architecture look like: 


// To fill in the architecture diagram


Here are the steps for starting up the cluster:

  • Start up the two seed servers (seed1 and seed2):

  • Start three cluster servers (server A, B, C):


Voila! You get the cluster running, now it's time test it out:
  • Start subscriber and publisher:

Wednesday, October 23, 2019

MySQL docker volumes on Docker Desktop Windows 10

Using MySQL docker image is a quick and easy way to spin up an MySQL database for your application development and testing. However, if you are running on Windows Docker Desktop on Windows 10, if you do not have a correct volume setup, then the MySQL data volume will be embbed in the HyperV virual disk and is is very hard to reset/clean up. To mitigate the aforementioned problem, you can setup the correct volume on your host and share it with the Docker Desktop, this gives you full control for the MySQL data volume running in the Docker. Here are the steps:

  • create a local folder to hold the MySQL data volume:
    • mkdir c:\tmp\mysql
  • In your Docker Desktop via Settings -> Shared Drives mark your c: drive shared with Docker Desktop
  • Start your MySQL docker container:
    • docker run --net=mysql-network --name mysql -v c:/tmp/mysql:/var/lib/mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=***** -d mysql:latest
  • Start MySQL client docker container:
    • docker run -it --network mysql-network --rm mysql:latest mysql -hmysql -uroot -p*****
  • If you do want to blow away the MySQL data volume, now you can easily do it on your host machine.

Friday, October 18, 2019

How to use Intellij to debug Lagom application

When you are learning and running Lagom project, you may want to setup debug in your IDE - Intellij to be able to debug the Lagom application to get some insight on what is going on under the hood. Here is one way how you can setup the Intellij Remote debug to debug Lagom application:

  • First in your terminal run:
    • sbt -jvm-debug 5005
      • this will start the sbt shell with JDWP server on 5005
      • you can use IntelliJ Remote debug to attach the JVM
    • in sbt shell, run: 
      • runAll
  • From then on you should be able to setup break point and debugging on.

Thursday, October 17, 2019

Thingsboard install_dev_db HSQLDB spring.datasource.hikari.maximumPoolSize problem

Thingsboard is a fantastic open source IoT data gathering and visualization platform. I was trying to setup the local development mode for Thingsboard and always step on the mines, so I just want to document the problem and solution for install_dev_db. When you check out the Thingsboard source from github, you need to build the project on your computer:

  • mvn clean install -DskipTests
Then you try to run the application by using your IDE to run java main file: org.thingsboard.server.ThingsboardServerApplication, you will get the following error:
Schema-validation: missing table [admin_settings]

This is an indication that you don't have the database setup, for running in dev mode, we need to swith the DB to HSQLDB by commenting out the Postgres DB configuration and plug in the HSQLDB configuration found here.

When you try to run the install_dev_db.bat you may run into the following error:

Error creating bean with name 'baseTimeseriesService': Unsatisfied dependency expressed through field 'timeseriesDao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaTimeseriesDao': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'spring.datasource.hikari.maximumPoolSize' in value "${spring.datasource.hikari.maximumPoolSize}"

To solve the aforementioned error, you need add the following configuration in your thingsboard.yml under the spring.datasource:


hikari:
  maximumPoolSize: "${SPRING_DATASOURCE_MAXIMUM_POOL_SIZE:50}"
This will let you successfully setup the dev DB for thingsboard.

Tuesday, May 23, 2017

Setup your own Git server on windows running on NodeJS

As technology moving ahead, now days Git is the de facto version control system to used, if you would like to have a local private git server running on windows, here is an option running on NodeJS - git-server-windows, to setup up it is pretty easy:


  • Create a directory where you want to install the git-server-windows, cd to that directory, run 'npm install git-server-windows'
  • copy node_moduels/git-server-windows/*.cmd .
  • Create a directory: repos
  • cd to repos and create your repository, for example, myRepository; then cd to myRepository, run ' git init --bare'
  • In the top folder, create index.js and paste the following content:

    • var Git = require('git-server-windows');
      Git.server();
  • Run 'node index.js' to start the server
  •  Setup as windows services by using node-windows



Thursday, October 10, 2013

Try out Java EE @DataSourceDefinition with DB2 on GlassFish 4

Came back from Java One 2013, learned some tricks from Adam Bien, I decided to give @DataSourceDefinition a try on GlassFish 4 with DB2 database, after a little bit bumps, I got it work:

  1. Copy your DB2 JDBC driver files(db2jcc4.jar and db2jcc_license_cu.jar) to glassfish/lib direcotry.
  2. Setup a singleton EJB to define your DataSourceDefinition:
  3. @DataSourceDefinition(
     className="com.ibm.db2.jcc.DB2DataSource",
     serverName="host_name",
     name="java:global/jdbc/APP",
     databaseName="database_name",
     portNumber=db_port,
     user="username",
     password="passowrd",
     properties={"driverType=4"}
    )
    @Singleton
    public class DataSourceConfiguration {
    }
    
  4. Add the JNDI reference in your persistence.xml:
  5. java:global/jdbc/APP
    
  6. In your Rest resource file
  7. ...
    @PersistenceContext
    EntityManager em;
    ...
    @GET
    @Produces("application/xml")
    public String getXml() {
        Query q = em.createQuery("select c from Customer c");
        List customers = q.getResultList();
        return "" + customers.get(1).getId() + "";
    }
    
    
    
There are a few catches I ran into:
  • Error:
  • Failure in loading native library db2jcct2, java.lang.UnsatisfiedLinkError
    
    You need to add the vendor specific properties: driverType=4 to force it use type 4 JDBC driver.

Thursday, January 26, 2012

Test DB2 JDBC Data source failed in WebSphere 7 cluster

As far as how to create a new DB2 datasource in WebSphere 7 is pretty straightforward, it contains two steps:
1. Create a new JAAS J2C data entry to hold your username and password.
2. Create a new DataSource by using the newly created JAAS J2C data entry.
That's all you need to do. But where may be a catch when you try to do it in a cluster environment, you may run into the following exepction when you try to test your newly created Data source:
java.lang.Exception: java.sql.SQLException: null userid not supported

My solution is to restart the nodeagents on the custer nodes.

Thursday, December 22, 2011

How to setup and use DB2Mon

I used to use TOAD to monitor the connection to Oracle, but when I moving to DB2 world, I am struggling to find out a similar tool to look at what kind connections/activities happen on the Database. One of my collegue suggested DB2Mon, I set off and decide to give it a try, here I record what I need to do:
1. Start IBM DB2 Configuration Assistant, right click, Add Database Using Wizard, Manually configure a connection to a database; setup your database connection; Test your connection by right click the newly created connection->TestConnection->CLI
2. Start your DB2Mon, you should see your newly created Database connection, select it and input your user/password.

Thursday, December 08, 2011

How to get a JDBC connection in EJB 3 running on WebSphere

There are several ways to get a JDBC connection in EJB3 running on WebSphere:
1. JNDI lookup
2. @Resource Injection
2.1 In ibm-ejb-jar-bnd.xml
<session name="OrderRepositoryBean">
<resource-ref name="DFSAdabasDataSource" binding-name="jdbc/DFS_ADABAS" />
</session>
2.2 In OrderRespositoryBean
@Resource(name = "DFSAdabasDataSource")
private DataSource ds;
3. NOT WORK!!! @Resource Injection by using mappedName, assuming the JNDI name is : jdbc/DFS_ADABAS
// In OrderRepositoryBean
@Resource(mappedName = "jdbc/DFS_ADABAS")
private DataSource ds;
4. Using OpenJPAEntityManager
@PersistenceContext(unitName = "CACSAMP")
private EntityManager emDFS;
......
(Connection) ((OpenJPAEntityManager) emDFS.getDelegate()).getConnection();

Wednesday, December 07, 2011

Configure IBM InfoSphere Classic JDBC Driver datasource in WebSphere

To setup the InfoSphere Classic JDBC Data source in WebSphere, you could follow the following steps:
1. Create new JDBC Provider
1.1 Resources->JDBC->JDBC providers->new
1.2 Database type: User-defined; Implementation class name: com.cac.jdbc.ConnectionPoolDataSource; Name: IBM InfoSphere Classic JDBC
1.3 Class path: ${User-defined_JDBC_DRIVER_PATH}/DataFederationServer/cacjdbc21.jar
1.4 Review summary->Finish->save
2. Create Java 2 Connector authentication data entry
2.1 Security->Global security; Under Authentication cache settings, click Java Authentication And Authorization Service->J2C authnetication data; new
2.2 Alias: ; UserID: ; Password: ; Apply-> save
3. Create new Data Source
3.1 Resources->JDBC->Data sources; new
3.2 Data source name: DFS_XXXX; JNDI name: jdbc/DFS_ADABAS
3.3 Select the JDBC provider created in step 1.
3.4 Data store helper class name: com.ibm.websphere.rsadapter.GenericDataStoreHelper; Uncheck used for CMP check box.
3.5 Component-managed authentication alias: the one you created in step 2.

3.6 Review summary->Finish->save
3.7 setup the Custom properties for the newly create Data source by click on the Data source name -> Customer properties
3.7.1 URL: your Data Federation Server JDBC URL;
3.7.2
webSphereDefaultIsolationLevel: 1 (READ_UNCOMMITED); very tricky, I can only make it work by setting to 1. It turns out the backend (ADABAS) is set to support READ_UNCOMMITED.
3.8 If you run into "JDBC hung when try to close connection" in your application, try to turn off the statement cache; Search IBM fix pack change list for similar problem for Oracle, and Sybase JDBC connection.
You almost done, just restart your web sphere server and start to use the JDBC Data source.

How to currentSchema for DB2 DataSource in WebSphere

Without setting the currentSchema for DB2, you need to fully qualified the DB object (table, view etc) name.
According IBM documentation, currentSchema means "This allows the end user or application to name SQL objects without having to qualify them by schema name."

How to setup the crrentSchema for DB2 DataSource in Websphere?
Resources->JDBC->Click your Data Source name->Customer properties->currentSchema.
Restart your Websphere to make it take effective.
BTW: The DataSource currentSchema setting could be co-exist with the openjpa.jdbc.Schema setting in persistent.xml without intereference with each other.

Friday, November 18, 2011

How to get the Database connection URL from OpenJPA EJB

Normally you would like to have a quick and easy way to tell which DB your application is connect to. To get this kind of you information in an OpenJPA/EJB3 stack, you may be able to do the following:
public String getDataBaseURL() {
        final Connection conn = (Connection) ((OpenJPAEntityManager) em.getDelegate()).getConnection();
        String url;
        try {
            url = conn.getMetaData().getURL();
        } catch (final SQLException e) {
            url = "Failed to get the DB URL";
        }
        return url;
    }

Tuesday, September 13, 2011

Windows firewall blocks access to Apache Tomcat service from remote computer

Today, my colleague installed Tomcat as windows service on a Windows 7 box, strangely he could access via http://127.0.0.1:8080 and http://ipofserver:8080, but he could not access http://ipofserver:8080 from a remote computer. After some digging, it turns out to be the Windows 7 firewall blocked the remote access traffic. The solution of the problem is simple: just manually start the tomcat7.exe, Windows 7 will show the firewall warning dialog, just allow access.;-)

Tuesday, August 30, 2011

JNI Refreshment

Today one of my colleague asked me some questions on JNI implementation. The knowledge seems fading away from me. To avoid it happens again, I recorded the basic steps:
  1. Delare your native methods in a normal Java class, for example, HelloJNI.java.
  2. javac the java file(HelloJNI.java).
  3. javah -jni HelloJNI to generate the .h file(s).
  4. Write your native code, using the .h file generated in step 3; copy the function prototye from the .h file into your .c file.
  5. compile by using Visual Studio 2005 command shell(cl command).
  6. Modify your java class to load the library; recompile it; ready to run it!!!
Reference:
  1. http://java.sun.com/docs/books/jni/html/jniTOC.html
  2. http://patriot.net/~tvalesky/jninative.html
  3. http://java.sun.com/developer/onlineTraining/Programming/JDCBook/jniexamp.html#comp
  4. command to compile your c file: c:\test\jnitest>cl /I"C:\Program Files (x86)\Java\jdk1.6.0_24\include" /I"C:\Program Files (x86)\Java\jdk1.6.0_24\include\win32" -LD HelloJNI.c -Felibnative.dll
  5. JNI in package

Thursday, July 07, 2011

Decoding IBM DB2 error message

Ever get an IBM DB2 error message like "SQL0407N Assignment of a NULL value to a NOT NULL column TBSPACEID=n1, TABLEID=n2, COLNO=n3 is not allowed. What actually does "TBSPACEID=n1, TABLEID=n2, COLNO=n3" mean? Don't ask me, you should ask IBM DB2, but how?

SELECT C.TABSCHEMA, C.TABNAME,
C.COLNAME
FROM SYSCAT.TABLES AS T,
SYSCAT.COLUMNS AS C
WHERE T.TBSPACEID = n1
AND T.TABLEID = n2
AND C.COLNO = n3
AND C.TABSCHEMA = T.TABSCHEMA
AND C.TABNAME = T.TABNAME

Wednesday, January 05, 2011

Install Oracle Developer Suite 10g on Windows 7 (64bit)

Recently, I got a task to install Oracle Developer Suite on Windows 7(64bit), but there seems lots of hassles to achieve this goal. There is a thread on Oracle forum on that topic. Here I log what I did to get it installed on my Windows 7(64bit) with 8G RAM.
  • extract the setup files (version 101202) downloaded from otn.
  • right click the install\setup.exe property, set compatibility to Windows XP SP2
  • edit the virtual memory size to custom size from 1024m to 8000m, restart it
  • run the install\setup.exe
Hope this helps.

Saturday, December 04, 2010

Oracle 11g alert log location

Oracle alert log contains much useful information about your Oracle database, but do you know where is it located and how could you find it out?
  1. Connect to the database with SQL*Plus or another query tool, such as SQL Developer.

  2. Query the V$DIAG_INFO view as shown in "Viewing ADR Locations with the V$DIAG_INFO View".

  3. To view the text-only alert log, without the XML tags, complete these steps:

    1. In the V$DIAG_INFO query results, note the path that corresponds to the Diag Trace entry, and change directory to that path.

    2. Open file alert_SID.log with a text editor.

  4. To view the XML-formatted alert log, complete these steps:

    1. In the V$DIAG_INFO query results, note the path that corresponds to the Diag Alert entry, and change directory to that path.

    2. Open the file log.xml with a text editor.

Monday, September 06, 2010

How to use Android Market on Android Emulator 2.2

After some digging, finally I got android market working on Android emulator 2.2 running on Windows Vista. Here is the steps,:
  • Start SDK Setup.exe and create an AVD - android-2.2
  • Copy system.img coming with the SDK platform to the newly created AVD.
cd c:\Users\dliu\.android\avd\android-2.2.avd
copy c:\labs\android-sdk-windows\platforms\android-8\images\system.img .
  • Start the emulator by using command line:
c:\labs\android-sdk-windows\tools>emulator -avd android-2.2 -partition-size 96
  • Pull build.prop from the emulator for editing:
c:\labs\android-sdk-windows\tools>adb.exe pull /system/build.prop .
  • Comment out ro.config.nocheckin=yes line from the build.prop file just pulled out from the emulator.
  • Push back the updated build.prop file to the emuloator
C:\labs\android-sdk-windows\tools>adb.exe remount
C:\labs\android-sdk-windows\tools>adb.exe push build.prop /system/build.prop
C:\labs\android-sdk-windows\tools>adb.exe push c:\labs\r21-update-nexusone-modacocustomcustomrom-withadditions-chinese-signed\system\app\GoogleServicesFramework.apk /system/app
C:\labs\android-sdk-windows\tools>adb.exe push c:\labs\r21-update-nexusone-modacocustomcustomrom-withadditions-chinese-signed\system\app\Vending.apk /
system/app
C:\labs\android-sdk-windows\tools>adb shell rm /system/app/SdkSetup.apk
  • Stop the emulator and delete the files: userdata-qemu.img, userdata.img, cache.img
  • start the emulator by using command line again, you should get the Android Market in your emulator.

Full Guide for using Bitnami Prometheus Operator Helm Chart with Additional Scrape Configuration

"The Prometheus Operator for Kubernetes provides easy monitoring definitions for Kubernetes services and deployment and management of...