reactor-c
C Runtime for Lingua Franca
Loading...
Searching...
No Matches
trace_to_influxdb.c File Reference
#include <stdio.h>
#include "reactor.h"
#include "trace.h"
#include "trace_util.h"
#include "influxdb.h"

Macros

#define LF_TRACE
 
#define MAX_NUM_REACTIONS   64
 
#define MAX_NUM_WORKERS   64
 

Functions

void usage ()
 
size_t read_and_write_trace ()
 
int main (int argc, char *argv[])
 

Variables

FILE * trace_file = NULL
 
influx_client_t influx_client
 
influx_v2_client_t influx_v2_client
 
instant_t latest_time = 0LL
 

Detailed Description

Author
Edward A. Lee
Ravi Akella

LICENSE

Copyright (c) 2021, The University of California at Berkeley

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

DESCRIPTION

Standalone program to send a Lingua Franca trace file to InfluxDB. InfluxDB is a database server to which data can be posted using HTTP or sent as a UDP datagram.

Compiling this Program

To compile this program, simply do this in this source directory:

sudo make install

This will place an executable program trace_to_influxdb in the directory usr/local/bin.

Setting up InfluxDB

To set up InfluxDB, see:

https://docs.influxdata.com/influxdb/v2.0/get-started/

If you have previously installed InfluxDB and you want a fresh start, do this:

rm -rf ~/.influxdbv2/
ps aux | grep nflux

The second command will report any InfluxDB processes that are running. Kill them with

kill -9 PID

where 'PID' is replaced with whatever process ID(s) are reported by the ps command above.

To start an InfluxDB server on localhost with port 8087:

influxd --http-bind-address :8087 --reporting-disabled

The 'reporting-disabled' option simply disables notifications to the InfluxDB mother ship.

You then need to set up at least one user, organization, and bucket. You can do this by pointing your browser to

http://localhost:8087

The browser will walk you through the process of creating a user, password, organization, and initial bucket. E.g.:

User: eal superSecretPassword
Organization: iCyPhy
Bucket: test

The UI in the browser will then give you the options Quick Start or Advanced, either of which you can select. If you select "Data" on the left, you can browse Buckets to verify that your test bucket was created.

Uploading Trace Data to InfluxDB

First, generate a trace file by setting a target parameter in a Lingua Franca program:

target C {
tracing: true
};

Then, when you run this program, a binary file with extension .lft will be created.

In your browser, in the InfluxDB UI, select Data on the left, then select the Tokens tab. Select a token and copy the token string to clipboard. It will looks something like this:

N1mK4b7z29YuWrWG_rBRJF3owaXjPA6gBVOgGG3eStS_zbESHTYJgfJWHB2JA_y3-BMYlMPVa05ccLVA1S770A==

Then, invoke the conversion program as follows:

trace_to_influxdb Filename.lft \
--token N1mK4b7z29YuWrWG_rBRJF3owaXjPA6gBVOgGG3eStS_zbESHTYJgfJWHB2JA_y3-BMYlMPVa05ccLVA1S770A==

where 'Filename' and the token are replaced with your values. This will upload the trace data to InfluxDB.

You can also specify the following command-line options:

  • -h, –host: The host name running InfluxDB. If not given, this defaults to "localhost".
  • -p, –port: The port for accessing InfluxDB. This defaults to 8086. If you used 8087, as shown above, then you have to give this option.

The data can then be viewed in the InfluxDB browser, or you can configure an external tool such as Grafana to visualize it (see https://grafana.com/docs/grafana/latest/datasources/influxdb/).

Macro Definition Documentation

◆ LF_TRACE

#define LF_TRACE

◆ MAX_NUM_REACTIONS

#define MAX_NUM_REACTIONS   64

◆ MAX_NUM_WORKERS

#define MAX_NUM_WORKERS   64

Function Documentation

◆ main()

int main ( int argc,
char * argv[] )

◆ read_and_write_trace()

size_t read_and_write_trace ( )

Read a trace in the trace_file and write it to InfluxDB.

Returns
The number of records read or 0 upon seeing an EOF.

◆ usage()

void usage ( )

Print a usage message.

Variable Documentation

◆ influx_client

influx_client_t influx_client

Struct identifying the influx client.

◆ influx_v2_client

influx_v2_client_t influx_v2_client

◆ latest_time

instant_t latest_time = 0LL

Largest timestamp seen.

◆ trace_file

FILE* trace_file = NULL

File containing the trace binary data.