Skip to content

Connect and Operate Guance, TrueWatch DataKit

This document primarily introduces how to use this system to connect with Datakit.

Always use the latest version of DataFlux Func for operations

1. Background

In some cases, independently installed DataFlux Func also needs to interact with Guance, TrueWatch, including but not limited to:

  • DataFlux Func acts as a collector, reporting data to Guance, TrueWatch
  • Business processing in DataFlux Func requires data from Guance, TrueWatch

For more information about DataFlux Func installation, please refer to:

For more information on using and maintaining DataFlux Func, please refer to:

2. Ensure Connectivity of DataKit Connectors

Before writing data to DataKit using DataFlux Func, ensure connectivity first. Therefore, after installing DataKit, you need to adjust the configuration to allow DataFlux Func to connect.

You can install DataFlux Func and DataKit on the same server, where DataFlux Func will automatically search for locally installed DataKit upon startup.

However, since DataFlux Func runs via Docker Stack and bridges to the host's docker0, it does not directly connect to the host's local network. Therefore, even if DataFlux Func and DataKit are installed on the same server, you cannot simply bind the listening port of DataKit to the local network (127.0.0.1).

At this point, you should modify the configuration to bind the listening port to docker0 (172.17.0.1) or 0.0.0.0. Summary as follows:

Bound IP Host DataFlux Func External Systems
127.0.0.1 Accessible via 127.0.0.1 Unreachable Unreachable
172.17.0.1 Accessible via 172.17.0.1 Accessible via 172.17.0.1 Unreachable
0.0.0.0 Accessible via 127.0.0.1, 172.17.0.1, etc. Accessible via 172.17.0.1 Accessible via Host IP

Reference operations when DataKit is located on the DataFlux Func host:

  1. Open DataKit configuration: sudo vim /usr/local/datakit/conf.d/datakit.conf
  2. Change http_listen = "localhost:9529" to http_listen = "0.0.0.0:9529"
  3. Restart DataKit: sudo datakit service -R
  4. Confirm that DataKit can be accessed via docker0: curl -i http://172.17.0.1:9529/v1/ping
  5. Return HTTP/1.1 200 OK indicating success

DataKit installation, deployment documents see: - Guance Documentation / DataKit - TrueWatch Documentation / DataKit

2.1 Use Automatically Generated DataKit Connectors

Upon startup, DataFlux Func will automatically attempt to find any existing DataKit on the host network.

If DataKit is successfully discovered, the system will automatically create a DataKit connector under "Connectors," eliminating the need for manual addition by users.

2.2 Manually Add DataKit Connectors

In certain situations, DataFlux Func may fail to automatically detect DataKit, such as:

  • DataFlux Func starts before DataKit is installed
  • DataKit is not properly configured, preventing DataFlux Func from connecting to the local DataKit
  • DataKit configuration has been modified, such as using a non-default port
  • Need to connect to DataKit on another server

In these cases, users need to manually add DataKit under "Connectors":

Option Example Value Description
ID datakit Used later for obtaining the operation object via DFF.CONN('{Connector ID}')
Host 172.17.0.1 Since DataFlux Func runs in Docker, fill in the address of docker0 here for accessing DataKit on the host.
If DataKit is on a network location, enter the actual domain name or IP
Port 9529 If you changed the default listening port of DataKit, fill in the actual listening port here
Protocol HTTP Normal HTTP is sufficient.
If your DataKit is deployed on a network location with a domain and certificate, fill in accordingly
Source dataflux_func This is DataKit's input.
Do not change it to mysql or other already existing inputs to avoid confusion

3. Writing Code to Operate DataKit

After creating the DataKit connector, you can operate DataKit within the code:

Python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
@DFF.API('DataKit Demo')
def datakit_demo():
    # Get DataKit operation object
    datakit = DFF.CONN('datakit')

    # Write data as Metrics into DataKit
    datakit.write_metric(measurement='Metrics', tags={'Tag Name':'Tag Value'}, fields={'Field Name':'Field Value'})

    # Write data as Logs into DataKit
    datakit.write_logging(measurement='Metrics', tags={'Tag Name':'Tag Value'}, fields={'Field Name':'Field Value'})

    # Query data using DQL statements
    data = datakit.query(dql='M:: Metrics')

X. More Documentation

For complete API documentation of the DataKit operation object, please refer to: