DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • The Evolution of Scalable and Resilient Container Infrastructure
  • Scaling Microservices With Docker and Kubernetes on Production
  • The Human Side of Logs: What Unstructured Data Is Trying to Tell You
  • Top Book Picks for Site Reliability Engineers

Trending

  • Data Lake vs. Warehouse vs. Lakehouse vs. Mart: Choosing the Right Architecture for Your Business
  • Operational Principles, Architecture, Benefits, and Limitations of Artificial Intelligence Large Language Models
  • Endpoint Security Controls: Designing a Secure Endpoint Architecture, Part 2
  • Building a Real-Time Change Data Capture Pipeline With Debezium, Kafka, and PostgreSQL
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Monitoring and Observability
  4. Mastering Observability in 10 Minutes Using OpenSearch

Mastering Observability in 10 Minutes Using OpenSearch

Set up observability with OpenSearch and Data Prepper in 10 minutes: ingest logs, visualize data, and monitor systems easily.

By 
Milavkumar Shah user avatar
Milavkumar Shah
·
Jan. 16, 25 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
8.5K Views

Join the DZone community and get the full member experience.

Join For Free

Observability has become a key component in software development as it enables the best customer experience by ensuring system health and performance and detecting systemic issues proactively. However, getting started can often feel overwhelming. OpenSearch simplifies this by providing an open-source, scalable solution for logging, metrics, and visualization.

In this article, we’ll walk through setting up observability in 10 minutes using OpenSearch Observability. No complex jargon, just simple steps to get you started with real-world examples.

What Is Observability?

Observability is the ability to understand a system's internal state by analyzing its external outputs, such as logs, metrics, and traces. Below are the three key telemetry signals:

  • Logs: What happened?
  • Metrics: What is the system’s performance?
  • Traces: How did events flow through the system?

For a deeper dive into observability basics, check out What is Observability? A Practical Overview on DZone.

Why OpenSearch and Data Prepper for Observability?

Here’s why this combo is ideal:

  1. Open-source flexibility: Scale with your requirements.
  2. Simple setup: No complex configurations.
  3. Real-time insights: Visualize logs instantly.
  4. Streamlined data pipelines: Ingest and prepare data with ease.

For comparisons with other tools, check out Choosing the Right Observability Platform.

Step 1: Quick Setup of OpenSearch

Follow the steps to get OpenSearch running quickly using Docker. Open your terminal and run:

Shell
 
docker run -d --name opensearch-node \
  -p 9200:9200 -p 9600:9600 \
  -e "discovery.type=single-node" \
  -e "plugins.security.disabled=true" \
  opensearchproject/opensearch:latest


This single command sets up your environment. You can now access OpenSearch at http://localhost:9200. 

If you’re new to Docker, you might find Getting Started With Docker on DZone helpful.

Step 2: Set Up Data Prepper for Data Ingestion

Data Prepper is an open-source tool for ingesting logs, metrics, and traces to OpenSearch. It’s lightweight and easy to configure for observability pipelines.

Install Data Prepper

Download and start Data Prepper using Docker:

Shell
 
docker run --name data-prepper \
  --network=host \
  opensearchproject/data-prepper:latest


This command spins up a Data Prepper instance listening for log data.

Configure Data Prepper

Create a data-prepper-config.yml file with the following content to process logs:

YAML
 
pipelines:
  my-pipeline:
    source:
      file:
        path: /var/logs/application.log
    sink:
      opensearch:
        hosts: ["http://localhost:9200"]
        index: "application-logs"


Place this configuration file in the same directory where you run Data Prepper.

Restart the container with the config file mounted:

Shell
 
docker run --name data-prepper \
  -v $(pwd)/data-prepper-config.yml:/usr/share/data-prepper/data-prepper-config.yml \
  --network=host \
  opensearchproject/data-prepper:latest


Step 3: Generate Logs

Create a Python script (app.py) to simulate application logs:

Python
 
import logging
import time

logging.basicConfig(
    filename='application.log',
    level=logging.INFO,
    format='%(asctime)s - %(levelname)s - %(message)s'
)

actions = ["User logged in", "Page viewed", "Error occurred"]
while True:
    for action in actions:
        logging.info(action)
        time.sleep(1)


Run the script to generate logs. Data Prepper will ingest them and send them to OpenSearch.

Step 4: Visualize Logs in OpenSearch Dashboards

  1. Open OpenSearch Dashboards at http://localhost:5601.
  2. Navigate to Discover and create an index pattern for application-logs.
  3. Explore the logs and create visualizations.

Step 5: Real-World Use Case: E-Commerce Monitoring

Simulate an e-commerce use case by extending the Python script to log user actions like login, add-to-cart, and checkout:

Python
 
import random

users = range(1, 10)
actions = ["login", "add_to_cart", "checkout"]

while True:
    user = random.choice(users)
    action = random.choice(actions)
    logging.info(f"User {user} performed {action}")
    time.sleep(2)


Visualize:

  • Track frequent actions using bar charts.
  • Identify anomalies, like checkout errors, using filters.

Step 6: Alerts and Automation

Set up alerts to proactively monitor system health:

  1. Go to Alerting in OpenSearch Dashboards.
  2. Create a rule to trigger alerts for specific log patterns (e.g., frequent errors).

Conclusion

You have set up OpenSearch and Data Prepper to ingest and visualize logs in less than 10 minutes. Observability for your projects is now at hand, from small to gigantic. Now that you've got a good handle on logs, add metrics and traces to complete your full-stack observability.

OpenSearch's ecosystem is both novice-friendly and powerful. Start now, and let your systems talk to you.

Observability Docker (software)

Opinions expressed by DZone contributors are their own.

Related

  • The Evolution of Scalable and Resilient Container Infrastructure
  • Scaling Microservices With Docker and Kubernetes on Production
  • The Human Side of Logs: What Unstructured Data Is Trying to Tell You
  • Top Book Picks for Site Reliability Engineers

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!