Skip to content

Sample implementation of cloudshell centralized logging with Grafana-loki-promtail stack

Notifications You must be signed in to change notification settings

QualiSystemsLab/cloudshell-grafana-loki

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cloudshell Loki-Grafana Centralized Logging

This repo documents a sample implementation of cloudshell centralized logging with Grafana / Loki / Promtail stack.

Cloudshell outputs JSON logs that can be ingested into centralized logging tools such as Elastic / Loki. Centralized Logging is beneficial for tracking sandbox events that can occur across multiple servers.

Read more on cloudshell centralized logging in help article.

Sample Grafana Log Dashboard

Loki

Solution Architecture

Grafana provides dashboard UI, Loki is the backend logging aggregator, Promtail agent installed on all Quali components. These components are analagous to elastic stack components of Elastic / Kibana / Filebeat.

Standard Loki Architecture:

Loki

Cloudshell Integration:

Cloudshell Loki Architecture

Setup and Usage

  1. Configure cloudshell JSON logs by following along with Quali help article
  2. Set up Grafana Server (see Grafana help article)
  3. Set up Loki Server. This can be done with local binary install or docker installation
  4. Install Promtail agent on Quali components by downloading and adding the Promtail binary file to each server. See Grafana help article and get correct binary from grafana github release page
  5. Configure Loki Server config yaml in same directory as binary.
  6. Configure Promtail config yaml to scrape the target logs and run agent.
  7. Configure Loki as data source in Grafana. See Grafana help
  8. Customize dashboards
  9. Add cloudshell Loki service to cloudshell, which gives option to optionally present loki data from sandbox via Loki API calls

Customizing LogQL Queries

Loki / Grafana uses LogQL syntax which can allow to target job labels, or filter by target json field of logs.

sample filter to pull "dispro" logs of a target sandbox ID: {job="qualiserver"} | json | category="DistributedProvisioning.Execution" |= "b83d649f-319b-4545-bf56-39b65b30668a"

Pull sandbox setup via wildcard filter: {filename=~".*b83d649f-319b-4545-bf56-39b65b30668a.*Setup.*",job="sandboxlogs"}

Pass in top Level sandbox id variable into dashboard queries: sandbox id var

Push Sandbox Events To Loki

An alternative workflow to promtail monitoring of log files, is to push data directly into Loki. A good candidate workflow is to pull sandbox activity events and push directly into Loki without need for intermediary files. A custom "Loki Server" shell with these commands is included.

Solution Flow:

  1. At end of sandbox setup, pull sandbox events with sandbox api call.
  2. Store latest sandbox event in sandbox data, push setup events data into Loki
  3. At end of teardown, read last cached event id in sandbox data and make api call to gather remaining events
  4. Push Post-setup events into Loki

sample flow output:

Loki Cloudshell Service

sandbox events in grafana:

Loki Cloudshell Service

log browser labels:

Loki Cloudshell Service

Setup and Usage Info

  1. Import "Loki Server" Shell and create resource
  2. Add all relevant attribute data to Loki Server Shell
    • Sandbox Api Details (for pulling sandbox events)
    • Loki Server Details (for pushing to Loki)
  3. Loki Server resource does NOT have to be in sandbox, but does have to be in same cloudshell domain
  4. Customize Setup / Teardown to trigger proper command on shell. See examples in orchestration folder
    • Use Try / Finally to handle setup errors and then trigger Loki
    • sandbox.suppress_exceptions needs to be set to False so that exceptions bubble up to be handled properly

Loki Server Shell In Sandbox

Dashboards can be explored in Grafana, or optionally Loki shell commands can be triggered directly from sandbox. The use case is to query select logs and print them to sandbox console instead of browsing Grafana UI.

Sample command pulling Dispro Quali Server logs:

Dispro Logs

References and Articles

About

Sample implementation of cloudshell centralized logging with Grafana-loki-promtail stack

Resources

Stars

Watchers

Forks

Packages

No packages published