Task02
Building the Telegraf Configuration

Telegraf Inputs

Step 1 - Create base gnmi.conf

In this task you will populate the base gnmi.conf using the gnmi input. This file will be used to build up the gNMI subscriptions to the NX-OS devices. Open file telegraf/gnmi.conf


code -r /home/cisco/CiscoLive/DEVWKS-2135/telegraf/gnmi.conf

Step 2 - Populate the gnmi.conf file.

Copy the below content to the gnmi.conf file and press Ctrl+s to save the file.


[agent]
  logtarget = "file"
  logfile = "/var/log/telegraf/telegraf.log"
  debug = true
  hostname = "telegraf"
  interval = "10s"
  round_interval = false
  metric_batch_size = 1000
  metric_buffer_limit = 10000
  
  [[inputs.ping]]
    urls = ["10.15.24.10", "10.15.24.11", "10.15.24.12"]
  
  [inputs.ping.tags]
    tag1 = "ping"
  
  [[inputs.gnmi]]
    # Address and port of the GNMI GRPC server
    addresses = ["10.15.24.10:50051", "10.15.24.11:50051","10.15.24.12:50051"]
  
    ## define credentials
    username = "admin"
    password = "cisco.123"
  
    ## enable client-side TLS and define CA to authenticate the device
    enable_tls = true
    tls_ca = "/etc/telegraf/certs/gnmi.crt"
    insecure_skip_verify = true
  
    # redial in case of failures after
    redial = "10s"
  [inputs.gnmi.tags]
    tag1 = "gnmi"
  
    [[inputs.gnmi.subscription]]
      name = "mgmt-ip"
      origin = "openconfig"
      path = "/interfaces/interface[name=mgmt0]/subinterfaces/subinterface/ipv4/addresses/address/config"
      subscription_mode = "sample"
      sample_interval = "600s"

    [[inputs.gnmi.subscription]]
      name = "platform"
      origin = "openconfig"
      path = "/components/component/state/name"
      subscription_mode = "sample"
      sample_interval = "30s"
  
  [[outputs.file]]
    files = ["stdout"]
    data_format = "json"

  [[outputs.influxdb_v2]]
    ## The URLs of the InfluxDB cluster nodes.
    ##
    ## Multiple URLs can be specified for a single cluster, only ONE of the
    ## urls will be written to each interval.
    ##   ex: urls = ["https://us-west-2-1.aws.cloud2.influxdata.com"]
    urls = ["http://influxdb:8086"]
  
    ## API token for authentication.
    token = "$DOCKER_INFLUXDB_INIT_ADMIN_TOKEN"
    organization = "$DOCKER_INFLUXDB_INIT_ORG"
    bucket = "$DOCKER_INFLUXDB_INIT_BUCKET"
    # bucket = 'nxos_dialout'
  
  [outputs.influxdb_v2.tagpass]
    tag1 = ["gnmi", "ping"]


Step 3 - Open the docker-compose.yml file if it was closed previously.


code -r /home/cisco/CiscoLive/DEVWKS-2135/docker-compose.yml

Step 4 - Update the Docker Compose to Include Telegraf, InfluxDB and Grafana

Copy the below content to the docker-compose.yml file and press Ctrl+s to save the file.



version: "2.1"
services:
  influxdb:
    image: influxdb:2.1-alpine
    container_name: influxdb
    env_file:
      - influxv2.env
    volumes:
      # Mount for influxdb data directory and configuration
      - influxdbv2:/var/lib/influxdb2:rw
    ports:
      - "8086:8086"
  telegraf:
    image: telegraf:1.22-alpine
    container_name: telegraf
    depends_on:
      - influxdb
    volumes:
      # Mount for telegraf config
      - ./telegraf/gnmi.conf:/etc/telegraf/telegraf.conf:ro
      - ./telegraf/certs/gnmi.crt:/etc/telegraf/certs/gnmi.crt:ro
    env_file:
      - influxv2.env
    ports:
      - 50050:50050

  grafana:
    image: grafana/grafana:latest
    container_name: grafana
    ports:
      - "3000:3000"
    environment:
      GF_SECURITY_ADMIN_PASSWORD: "CiscoLive"
      # GF_PATHS_DATA: "/var/lib/grafana"
      # GF_PATHS_LOGS: "/var/log/grafana"
    # user: "1000"
    volumes:
      - ./grafana/provisioning/:/etc/grafana/provisioning/
    
  # links:
  #   - influxdb
    restart: always
    depends_on:
      - influxdb

  yangsuite:
    container_name: yangsuite
    image: yangsuite:latest
    build:
      context: ./yangsuite
      dockerfile: ./Dockerfile
    env_file:
      - ./yangsuite/setup.env
    command: /yangsuite/migrate_and_start.sh
    volumes:
      - static-content:/ys-static
      - uwsgi:/yangsuite/uwsgi
      - ./ys-data:/ys-data
  nginx:
    container_name: nginx
    image: nginx:latest
    build:
      context: ./nginx
      dockerfile: ./Dockerfile
    depends_on:
      - yangsuite
    ports:
      - "80:80"
      - "8443:8443"
    volumes:
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf
      - static-content:/etc/nginx/html
      - uwsgi:/var/run/uwsgi

volumes:
  influxdbv2:
  static-content:
  uwsgi:

  

    

Step 5 - Starting docker-compose

Run the docker-compose.yml file via the below command. Confirm that the subscriptions establish to the switches and the data is outputed to the terminal.


docker-compose up

Check Telegraf Output

If the telegraf output is not similar to the below output, please notifiy the lab instructor


  ➜  DEVWKS-2135 ✗ | docker-compose up
  .
  .
  .      
  telegraf   | {"fields":{"name":"N9K-X9364v"},"name":"platform","tags":{"host":"telegraf","name":"1","path":"openconfig:/components","source":"10.15.5.11","tag1":"gnmi"},"timestamp":1673791511}
  telegraf   | {"fields":{"name":"N9K-vSUP"},"name":"platform","tags":{"host":"telegraf","name":"27","path":"openconfig:/components","source":"10.15.5.11","tag1":"gnmi"},"timestamp":1673791511}
  telegraf   | {"fields":{"name":"N9K-X9364v"},"name":"platform","tags":{"host":"telegraf","name":"1","path":"openconfig:/components","source":"10.15.5.10","tag1":"gnmi"},"timestamp":1673791511}
  telegraf   | {"fields":{"name":"N9K-vSUP"},"name":"platform","tags":{"host":"telegraf","name":"27","path":"openconfig:/components","source":"10.15.5.10","tag1":"gnmi"},"timestamp":1673791511}
  telegraf   | {"fields":{"name":"N9K-X9364v"},"name":"platform","tags":{"host":"telegraf","name":"1","path":"openconfig:/components","source":"10.15.5.12","tag1":"gnmi"},"timestamp":1673791511}


  • Introduction
  • Lab Environment and Topology
  • Streaming Telemetry Overview
  • Tools Overview
  • TIG Stack
  • Browse YANG Suite
  • Bonus Task!
  • Thanks