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.

We will cover the following points:




A strict adherence to the ThingWatcher deployment guide is recommended in order to first deploy training and model microservices as well as to familiarize yourself with ThingWatcher APIs.

Prior to testing ThingWatcher, both the training and model microservices should be up and running

The media for ThingWatcher (including model and training micro-service) should be downloaded from PTC Software Download page .


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:

  1. Start Docker: Start > Program > Docker > Docker Quick Start Terminal
  2. Load model micro service tar

$ docker load < "D:\PTC\MED-61147-CD-522_F000_ThingWorx-Analytics-ThingWatcher-52-2\components\ModelService\ModelService\model-service.tar"

    3. Install model service:

$ docker run -d -p 8080:8080 -v '/d/TWatcherStorage/model:/data/models' -v '/d/TWatcherStorage/db:/tmp/' twxml/model-service:1.0 -jar maven/model-1.0.jar server maven/standalone-evaluator.yml

    4. Load training micro service tar file

                        $ docker load < "D:\PTC\MED-61147-CD-522_F000_ThingWorx-Analytics-ThingWatcher-52-2\components\TrainingService\TrainingService\training-service.tar"


    5. Install training service

                        $ docker run -d -p 8090:8080  twxml/training-service:1.0.0  -Dmodel.destination.uri=model:// -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,>8080/tcp  modest_albattani

8c13c0bc910e        twxml/model-service:1.0        "java"      2 weeks ago        Up 44 minutes>8080/tcp, 8081/tcp  thirsty_ptolemy


Using the sample utility

  • Download the attachment
  • Import into Eclipse (or IDE of choice) with the ThingWatcher dependencies added in classpath.
  • Update the trainingBaseURI (see below) to points to the training micro-services.
  • The utility should be ready to execute.


Code walk through


The code declares a thingwatcher in the following snippet:

ThingWatcher thingwatcher = new ThingWatcherBuilder()






  • 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 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 - Value = 901700,9017.0,-9016.403802019577

[main] INFO - isAnomalousValue = true

[main] INFO - 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 : (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 (update the ip address to the one on your system) to see all the models that have been created. For example:


Alternatively, click (or use) the URI reported in the training job output, here, to see the complete model definition. The output will be similar to:



When this sample test runs correctly, the ThingWatcher deployment has been validated.


Update for ThingWorx Analytics 8.0



To Note:

  • The utility provided is for testing purpose only.
  • The code does not represent any kind of best practice and is not meant to be a perfect java coding example.
  • It is provided as is with no guarantee.