Sample Java utility to validate ThingWatcher 52.2 installation
This Blog presents a simple Java utility to validate the deployment of ThingWatcher. It is important to note that the utility used is not a real life situation, the intent was to keep it as simple as possible in order to achieve its aim: validation of the deployment. An understanding of Java IDE (such as Eclipse) is necessary in order to run the utility with relevant dependency and classpath setup. Those are beyond the scope of this posting.
The commands to deploy the micro-services will vary depending on the platform used and are presented in the ThingWatcher deployment guide. As a reference example, on Windows the command will be similar to the following:
$docker run -d -p 8090:8080 twxml/training-service:1.0.0 -Dmodel.destination.uri=model://192.168.99.100:8080/models-jar maven/training-standalone-1.0.0-bin.jar server /maven/training-standalone-single.yml
Note: the -Dmodel.destination.uri points here to the model micro-service host. To find the ip address, enter docker-machine ip on the model micro-service docker machine.
6. Validate micro-services deployment:
Execute docker ps and confirmed that both services are up, as in the following example: CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5b6a29b95611 twxml/training-service:1.0.0 "java -Dmodel.destina" 13 days ago Up 44 minutes 8081/tcp, 0.0.0.0:8090->8080/tcp modest_albattani
8c13c0bc910e twxml/model-service:1.0 "java -Dfile.storage." 2 weeks ago Up 44 minutes 0.0.0.0:8080->8080/tcp, 8081/tcp thirsty_ptolemy
In the above code it is important to update the trainingBaseURI argument with the correct ip address and port for the training micro-service host.
The code then loops 10000 times and sends a new value, which simulates the sensor data, at a simulated 100 ms interval. The value is computed as Math.sin(i) for the whole calibrating phase and most of the monitoring phase too.
We artificially introduce an anomaly by sending a value of Math.incremetExact(i) between the 9000th and 9900th iterations.
During the Monitoring phase, the code logs the value, the anomalous status and the thingwatcher state.
It is advised to save the output to a file in order to review the logging once the utility has run.
In Eclipse this can be done by selecting the Main.java with right mouse button > Run As… > Run Configuration > Common and tick Output File under the Standard Input and Output, and specify a location for the output file.
A review of the output log file will shows that somewhere between timestamp 900000 and 990000, the isAnomalousValue is true.
Note that this does not starts and ends exactly at 900000 and 990000, as ThingWatcher needs a few occurrences before reporting it as anomaly. Sample output indicating an anomalous state:
[main] INFO com.thingworx.analytics.demo.Main - Value = 901700,9017.0,-9016.403802019577
[main] INFO com.thingworx.analytics.demo.Main - isAnomalousValue = true
[main] INFO com.thingworx.analytics.demo.Main - ThingWatcherStat = MONITORING
As part of validating the successful deployment of ThingWatcher, it is recommended to validate the correct creation of a training and model job.
Validate training job creation
In order to validate the successful creation of a training job, execute a GET request to the training micro service : http://192.168.99.100:8090/training (update the ip address to the one on your system) This should return a COMPLETED job whose body starts with something similar to:
Validate model job creation
In order to validate the successful creation of a model job, execute a GET request to http://192.168.99.100:8080/models (update the ip address to the one on your system) to see all the models that have been created. For example: