clearlinux/telemetrics-backend

Name: telemetrics-backend

Owner: Clear Linux* Project for Intel Architecture

Description: Collector and WebUI for https://github.com/clearlinux/telemetrics-client

Created: 2017-08-07 23:17:59.0

Updated: 2018-05-17 21:42:21.0

Pushed: 2018-05-17 21:42:19.0

Homepage: null

Size: 165

Language: Python

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

telemetrics-backend

Overview

This project provides the server-side component of a complete telemetrics (telemetry + analytics) solution for Linux-based operating systems. The client-side component source repository lives at https://github.com/clearlinux/telemetrics-client.

It consists of two Flask applications: an ingestion app, collector, for records received from telemetrics-client probes; and a web app, telemetryui, that exposes several views to visualize the telemetry data. The telemetryui app also provides a REST API to perform queries on the data.

The applications run within a web stack, using the nginx web server, the uWSGI application server, and PostgreSQL as the underlying database server.

The Flask apps have several other dependencies and are listed below.

Security considerations

The telemetrics-backend was written with a particular deployment scenario in mind: single server/VM hosting and running on an internal LAN (e.g. a corporate network not exposed to the public internet). Also, no identity management, user authentication, or role-based access controls have yet been implemented for the applications.

To control access to the applications, it is recommended that system administrators leverage web server authentication.

Regarding alternate deployment scenarios, one might want to host the collector, telemetryui, and database on three separate servers/VMs; and implement network access controls for these systems. The in-tree deployment script does not support these types of deployments, but with minimal modification to the source, they should be possible.

Installation

To install the telemetrics-backend, a deployment/installation script is provided that auto-installs required dependencies for the applications, configures nginx and uwsgi, deploys snapshots of the applications, and starts all required services. The script is named deploy.sh and lives in the scripts/ directory in this repository.

The script supports installation to the following Linux distributions: Ubuntu Server 16.04 (or newer), and Clear Linux OS for Intel Architecture (any recent build).

Running the deployment script

To see all options, run:

 scripts
deploy.sh -h
Prerequisites Installation

To perform a fresh installation on Ubuntu Server, run the following locally on the system:

deploy.sh -H localhost -a install

If you are installing on Clear Linux OS, run:

deploy.sh -H localhost -d clr -a install
Installation Notes

During script execution, you will be prompted for user input:

When the installation is complete, you will see the following message:

all complete (installation folder: /var/www/telemetry)
Other options

Other useful options for deploy.sh include -r and -s. The -r option sets the location for the telemetrics-backend git source repository you are working with. Its default value is the upstream repo location on github.com/clearlinux. The -s option lets you select a different git branch to install/deploy from rather than “master”, the default value.

collector operation

The collector app is an ingestion app that handles POST requests to / or /v2/collector at the web server location where telemetrics-backend has been installed. The requests are analyzed to make sure required header fields are present and that values are correct.

Generally, the POST requests are sent by probes from the telemetrics-client, since these probes use the client library, libtelemetry, to create well-formed records capable of being processed by telemetrics-backend.

At minimum, make sure that your telemetrics-client configuration in /etc/telemetrics/telemetrics.conf specifies the correct server URL for the server config option. For example, if telemetrics-backend is hosted at example.com, the client config should contain server=http://example.com/ or server=http://example.com/v2/collector.

collector plugable payload parsers

By default collector will save the payload record from telemetry messages as is received, there are cases when is desirable to apply additional transformations to payload on selected classifications. This use case is covered by custom payload parsers/(or transformations). For more information on this feature read specific documentation

telemetryui views

The telemetryui app is a web app that exposes several views to visualize the telemetry data and also provides a REST API to perform queries on record data.

The current views are:

Custom telemetryui views

To provided users with an extensible framework a concept of “plugin views” was implemented to add views without the need to make changes to the core of the application. To read more about plugin view go to relevant documentation.

Special configuration
Configuring the collector TID

The collector requires a Telemetry ID (TID) header value set with the HTTP header X-Telemetry-TID. The telemetrics-client daemon adds this header to telemetry records, and its default value is used for identifying records from Clear Linux OS systems.

However, when you are deploying your own instance of telemetrics-backend and have deployed telemetrics-client to systems configured to send records to this instance, it is recommended to generate your own random TID (e.g. using the uuidgen program). Once you have generated a TID, the following steps are needed:

Configuring nginx for TLS

The sites_nginx.conf config file is already enabled to accept TLS connections on port 443. However, you must install the X509 certificate chain and the certificate private key to a specific location before running deploy.sh. Both files should be in PEM format. Additional details on specific considerations can be found in the nginx documentation.

The certificate chain must be installed to /etc/nginx/ssl/telemetry.cert.pem and the private key installed to /etc/nginx/ssl/telemetry.key.pem.

If the certificates are not preinstalled, the deploy.sh script will simply comment out TLS-related nginx configuration. Specifically, it will comment out the listen 443 ssl, ssl_certificate, ssl_certificate_key, ssl_protocols, and ssl_ciphers directives.

Configuring record retention time

The collector app uses the uWSGI cron interface to purge records in the database on a daily basis that are older than a certain age. By default, a record will only be kept in the database for 5 weeks (starting from the timestamp the collector received the record). To modify the retention time, update the MAX_DAYS_KEEP_UNFILTERED_RECORDS value in collector/collector/config.py after installation, and restart uWSGI for the new setting to take effect.

Using the REST API

A REST API for querying records is available at “/api/records”. The API returns a JSON response that contains a list of records keyed on “records”.

Several parameters are available for filtering queries, similar to the filters available through the telemetryui Records view.

Example queries

To query for records, simply make a GET call to the endpoint.

Response object

The response is a JSON object that contains a list of objects keyed on “records”. This list is empty in case no records match the query parameters. Example response:


"records": [
    {
        "arch": "x86_64",
        "build": "2980",
        "classification": "org.clearlinux/hello/world",
        "kernel_version": "4.2.0-120",
        "machine_id": "66c196ce4222dd761470da5e7e35f6f1",
        "machine_type": "blank|blank|blank",
        "payload": "hello\n\n",
        "record_format_version": 2,
        "severity": 1,
        "ts_capture": "2015-09-30 00:39:35 UTC",
        "ts_reception": "2015-09-30 00:56:59 UTC"
    },
    {
        "arch": "x86_64",
        "build": "2980",
        "classification": "org.clearlinux/hello/world",
        "kernel_version": "4.2.0-120",
        "machine_id": "66c196ce4222dd761470da5e7e35f6f1",
        "machine_type": "blank|blank|blank",
        "payload": "hello\n",
        "record_format_version": 2,
        "severity": 1,
        "ts_capture": "2015-09-30 00:36:22 UTC",
        "ts_reception": "2015-09-30 00:38:45 UTC"
    }
]

Creating new database migrations

Database migrations are managed using Flask-Migrate. Upon initial install of telemetrics-backend, the first migration will be applied, and any additional migrations in the telemetryui/migrations/versions/ directory will be applied in sequence and upgrade the telemdb schema to the latest version.

To create a new migration, you can follow the steps below:

  1. Deploy telemetrics-backend from a git topic branch (not production).
  2. On the system deployed to, run
 su
var/www/telemetry/
  1. Modify shared/model.py as needed to make changes to the associated database schema.
  2. When finished, create a migration with
elemetryui
ce ../venv/bin/activate
rt FLASK_APP=run.py
k db migrate
  1. The last command above will report the name of the new (autogenerated) migration file. Modify it if additional migration steps are necessary beyond what Flask-Migrate autogenerated for you. To apply the migration to the database you need to execute the following command:

    k db upgrade
    
  2. Copy the new file back to your git repository (into the telemetryui/migrations/versions directory), push it to your topic branch, and redeploy to test the new migration.

Software License

The telemetrics-backend project is licensed under the Apache License, Version 2.0. The full license text is found in the LICENSE file, and individual source files contain the boilerplate notice described in the appendix of the LICENSE file.

Security Disclosures

To report a security issue or receive security advisories please follow procedures in this link.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.