Telegraf: Start a JAVA jar ONE TIME before any Input Plugin starts aggregating data from the system

Hello,

I would like to start Java a java jar which has a REST API that collects metrics from the system on which Telegraf agent is running. Now, the issue is that if I start the jar using the EXEC input plugin, then according to telegraf.conf file, at a certain period of time the exec input plugin will want to collect data in some format ex JSON.

Could you please indicate how could I start the jar only one time before any input plugin will start collecting data?

Thanks and kind regards!

@Diana_Rusu Are you looking for the httpjson plugin? This will poll the REST API and parse the resulting JSON.

@jackzampolin Thanks for your reply. I wanted to use the httpjson plugin but then I saw that this plugin will “flatten the JSON and finds all numeric values, treating them as floats”. I do have and String as values. So, I need to mention that we do have an input plugin that reads the data, which is in JSON format, from the REST API.

For the moment I created a bash script but it’s not what I am looking for as final solution. Maybe this will clear out what my intention is with starting a JAVA jar from Telegraf -> one time only. Please have a look at the following script.

#!/bin/bash
PID_JAVA=""
BASE_DIR_JAVA="/x/x/x/GlobalAgent/linux64"
cd ${BASE_DIR_JAVA}
# Call following funct whenever Ctrl-C is invoked
exit_signal(){
    echo "Sending termination signal to JAVA PID $PID_JAVA"
    kill -9 $PID_JAVA
    echo "JAVA PID $PID_JAVA should be terminated now"
    exit 2
}
trap exit_signal SIGINT
nohup jre/bin/java -jar lib/jvmagent.jar &
PID_JAVA=$!
echo $PID_JAVA
sleep 10s
BASE_DIR_GO="/x/x/x/GlobalAgent/linux_amd64"
cd ${BASE_DIR_GO}
./telegraf --config ../telegraf.conf

while true; do
    sleep 1
done

So, I want to combine the Java Agent with Telegraf, by starting the jar with an exec function “somewhere”. Is this possible?

Once more thanks for coming back to this question. Best regards!

@Diana_Rusu I don’t think this is possible with telegraf. Can you use some other automation tooling (systemd unit files jump to mind) to start this process?

@jackzampolin Sad story here. I wish I could use systemd but sadly the operating system for the hosts I would like to deploy the Agent, is ancient and does not have systemd. Thanks for your suggestion, highly appreciate!

@Diana_Rusu You should have an init system of some sort to help you do this. I know you can use init.d to accomplish similar tasks.