Observability With Grafana
local graph
Observability With Grafana
Section titled “Observability With Grafana”chapter_01
Section titled “chapter_01”node-book_observability-with-grafana_chapter-01-introducing-observability-and-the-grafana-stack — Introducing Observability and the Grafana Stack
chapter_02
Section titled “chapter_02”node-book_observability-with-grafana_chapter-02-instrumenting-applications-and-infrastructure — Instrumenting Applications and Infrastructure
chapter_03
Section titled “chapter_03”node-book_observability-with-grafana_chapter-03-setting-up-a-learning-environment-with-demo-applications — Setting Up a Learning Environment with Demo Applications
chapter_04
Section titled “chapter_04”node-book_observability-with-grafana_chapter-04-looking-at-logs-with-loki — Looking at Logs with, Loki
chapter_05
Section titled “chapter_05”node-book_observability-with-grafana_chapter-05-monitoring-with-metrics-using-grafana-mimir-and-prometheus — Monitoring with Metrics Using Grafana Mimir and Prometheus
chapter_06
Section titled “chapter_06”node-book_observability-with-grafana_chapter-06-tracing-technicalities-with-grafana-tempo — Tracing Technicalities with Grafana Tempo
chapter_07
Section titled “chapter_07”node-book_observability-with-grafana_chapter-07-interrogating-infrastructure-with-kubernetes-aws-gcp-and-azu — Interrogating Infrastructure with Kubernetes, AWS, GCP, and Azure
chapter_08
Section titled “chapter_08”node-book_observability-with-grafana_chapter-08-displaying-data-with-dashboards — Displaying Data with Dashboards
chapter_09
Section titled “chapter_09”node-book_observability-with-grafana_chapter-09-managing-incidents-using-alerts — Managing Incidents Using Alerts
chapter_10
Section titled “chapter_10”node-book_observability-with-grafana_chapter-10-automation-with-infrastructure-as-code — Automation with Infrastructure as Code
chapter_11
Section titled “chapter_11”node-book_observability-with-grafana_chapter-11-architecting-an-observability-platform — Architecting an Observability Platform
chapter_12
Section titled “chapter_12”node-book_observability-with-grafana_chapter-12-real-user-monitoring-with-grafana — Real User Monitoring with Grafana
chapter_13
Section titled “chapter_13”node-book_observability-with-grafana_chapter-13-application-performance-with-grafana-pyroscope-and-k6 — Application Performance with Grafana Pyroscope and k6
chapter_14
Section titled “chapter_14”node-book_observability-with-grafana_chapter-14-supporting-devops-processes-with-observability — Supporting DevOps Processes with Observability
chapter_15
Section titled “chapter_15”node-book_observability-with-grafana_chapter-15-troubleshooting-implementing-best-practices-and-more-with-gr — Troubleshooting, Implementing Best Practices, and More with Grafana
Preface
Section titled “Preface”Hello and welcome! Observability with Grafana is a book about the tools offered by Grafana Labs for observability and monitoring. Grafana Labs is an industry-leading provider of open source tools to collect, store, and visualize data collected from IT systems. This book is primarily aimed toward IT engineers who will interact with these systems, whatever discipline they work in.
We have written this book as we have seen some common problems across organizations:
- Systems that were designed without a strategy for scaling are being pushed to handle additional data load or teams using the system
- Operational costs are not being attributable correctly in the organization, leading to poor cost analysis and management
- Incident management processes that treat the humans involved as robots without sleep schedules or parasympathetic nervous systems
In this book, we will use the OpenTelemetry Demo application to simulate a real-world environment and send the collected data to a free Grafana Cloud account that we will create. This will guide you through the Grafana tools for collecting telemetry and also give you hands-on experience using the administration and support tools offered by Grafana. This approach will teach you how to run the Grafana tools in a way so that anyone can experiment and learn independently.
This is an exciting time for Grafana, identified as a visionary in the 2023 Gartner Magic Quadrant for Observability (https://www.gartner.com/en/documents/4500499). They recently delivered change in two trending areas:
- Cost reduction: This has seen Grafana as the first vendor in the observability space to release tools that not only help you understand your costs but also reduce them.
- Artificial intelligence (AI): Grafana has introduced generative AI tools that assist daily operations in simple yet effective ways – for example, writing an incident summary automatically. Grafana Labs also recently purchased Asserts.ai to simplify root cause analysis and accelerate problem detection.
We hope you enjoy learning some new things with us and have fun doing it!
Who this book is for
Section titled “Who this book is for”IT engineers, support teams, and leaders can gain practical insights into bringing the huge power of an observability platform to their organization. The book will focus on engineers in disciplines such as the following:
- Software development: Learn how to quickly instrument applications and produce great visualizations enabling applications to be easily supported
- Operational teams (DevOps, Operations, Site Reliability, Platform, or Infrastructure): Learn to manage an observability platform or other key infrastructure platform and how to manage such platforms in the same way as any other application
- Support teams: Learn how to work closely with development and operational teams to have great visualizations and alerting in place to quickly respond to customers’ needs and IT incidents
This book will also clearly establish the role of leadership in incident management, cost management, and establishing an accurate data model for this powerful dataset.
What this book covers
Section titled “What this book covers”Chapter 1, Introducing Observability and the Grafana Stack, provides an introduction to the Grafana product stack in relation to observability as a whole. You will learn about the target audiences and how that impacts your design. We will take a look at the roadmap for observability tooling and how Grafana compares to alternative solutions. We will explore architectural deployment models, from self-hosted to cloud offerings. Inevitably, you will have answers to the question “Why choose Grafana?”.
Chapter 2, Instrumenting Applications and Infrastructure, takes you through the common protocols and best practices for each telemetry type at a high level. You will be introduced to widely used libraries for multiple programming languages that make instrumenting an application simple. Common protocols and strategies for collecting data from infrastructural components will also be discussed. This chapter provides a high-level overview of the technology space and aims to be valuable for quick reference.
Chapter 3, Setting Up a Learning Environment with Demo Applications, explains how to install and set up a learning environment that will support you through later sections of the book. You will also learn how to explore the telemetry produced by the demo app and add monitoring for your own service.
Chapter 4, Looking at Logs with, Loki, takes you through working examples to understand LogQL. You will then be introduced to common log formats, and their benefits and drawbacks. Finally, you will be taken through the important architectural designs of Loki, and best practices when working with it.
Chapter 5, Monitoring with Metrics Using Grafana Mimir and Prometheus, discusses working examples to understand PromQL with real data. Detailed information about the different metric protocols will be discussed. Finally, you will be taken through important architectural designs backing Mimir, Prometheus, and Graphite that guide best practices when working with the tools.
Chapter 6, Tracing Technicalities with Grafana Tempo, shows you working examples to understand TraceQL with real data. Detailed information about the different tracing protocols will be discussed. Finally, you will be taken through the important architectural designs of Tempo, and best practices when working with it.
Chapter 7, Interrogating Infrastructure with Kubernetes, AWS, GCP, and Azure, describes the setup and configuration used to capture telemetry from infrastructure. You will learn about the different options available for Kubernetes. Additionally, you will investigate the main plugins that allow Grafana to query data from cloud vendors such as AWS, GCP, and Azure. You will look at solutions to handle large volumes of telemetry where direct connections are not scalable. The chapter will also cover options for filtering and selecting telemetry data before it gets to Grafana for security and cost optimization.
Chapter 8, Displaying Data with Dashboards, explains how you can set up your first dashboard in the Grafana UI. You will also learn how to present your telemetry data in an effective and meaningful way. The chapter will also teach you how to manage your Grafana dashboards to be organized and secure.
Chapter 9, Managing Incidents Using Alerts, describes how to set up your first Grafana alert with Alert Manager. You will learn how to design an alert strategy that prioritizes business-critical alerts over ordinary notifications. Additionally, you will learn about alert notification policies, different delivery methods, and what to look for.
Chapter 10, Automation with Infrastructure as Code, gives you the tools and approaches to automate parts of your Grafana stack deployments while introducing standards and quality checks. You will gain a deep dive into the Grafana API, working with Terraform, and how to protect changes with validation.
Chapter 11, Architecting an Observability Platform, will show those of you who are responsible for offering an efficient and easy-to-use observability platform how you can structure your platform so you can delight your internal customers. In the environment we operate in, it is vital to offer these platform services as quickly and efficiently as possible, so more time can be dedicated to the production of customer-facing products. This chapter aims to build on the ideas already covered to get you up and running quickly.
Chapter 12, Real User Monitoring with Grafana, introduces you to frontend application observability, using Grafana Faro and Grafana Cloud Frontend Observability for real user monitoring (RUM). This chapter will discuss instrumenting your frontend browser applications. You will learn how to capture frontend telemetry and link this with backend telemetry for full stack observability.
Chapter 13, Application Performance with Grafana Pyroscope and k6, introduces you to application performance and profiling using Grafana Pyroscope and k6. You will obtain a high-level overview that discusses the various aspects of k6 for smoke, spike, stress, and soak tests, as well as using Pyroscope to continuously profile an application both in production and test environments.
Chapter 14, Supporting DevOps Processes with Observability, takes you through DevOps processes and how they can be supercharged with observability with Grafana. You will learn how the Grafana stack can be used in the development stages to speed up the feedback loop for engineers. You will understand how to prepare engineers to operate the product in production. Finally, You will learn when and how to implement CLI and automation tools to enhance the development workflow.
Chapter 15, Troubleshooting, Implementing Best Practices, and More with Grafana, closes the book by taking you through best practices when working with Grafana in production. You will also learn some valuable troubleshooting tips to support you with high-traffic systems in day-to-day operations. You will also learn about additional considerations for your telemetry data with security and business intelligence.
To get the most out of this book
Section titled “To get the most out of this book”The following table presents the operating system requirements for the software that will be used in this book:
| Software/hardware covered in the book | Operating system requirements |
|---|---|
| Kubernetes v1.26 | Either Windows, macOS, or Linux with dual CPU and 4 GB RAM |
| Docker v23 | Either Windows, macOS, or Linux with dual CPU and 4 GB RAM |
If you are using the digital version of this book, we advise you to type the code yourself or access the code from the book’s GitHub repository (a link is available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.
Code in Action
Section titled “Code in Action”The Code in Action videos for this book can be viewed at
Conventions used
Section titled “Conventions used”There are a number of text conventions used throughout this book.
Code in text: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: “The function used to get this information is the rate() function.”
A block of code is set as follows:
histogram_quantile( 0.95, sum( rate( http_server_duration_milliseconds_bucket{}[$__rate_interval]) ) by (le) )Any command-line input or output is written as follows:
$ helm upgrade owg open-telemetry/opentelemetry-collector -f OTEL-Collector.yamlBold: Indicates a new term, an important word, or words that you see onscreen. For instance, words in menus or dialog boxes appear in bold. Here is an example: “From the dashboard’s Settings screen, you can add or remove tags from individual dashboards.”
Tips or important notes
Appear like this.