Skip to content

Monitoring System ExampleΒΆ

This guide provides a professional, step-by-step walkthrough for using the MonitoringSystem in the agenticaiframework package to log events and record metrics. It is intended for developers who want to track agent activities, performance, and operational metrics in real-time.

Enterprise Observability

Part of 237 enterprise modules with 16 observability modules including distributed tracing, APM integration, and real-time dashboards.

Prerequisites & ConfigurationΒΆ

  • Installation: Ensure agenticaiframework is installed and accessible in your Python environment.
  • No additional configuration is required for this example.
  • Python Version: Compatible with Python 3.10+.

CodeΒΆ

Python
import logging

logger = logging.getLogger(__name__)

from agenticaiframework.monitoring import MonitoringSystem

if __name__ == "__main__":
    monitor = MonitoringSystem()

    # Log events
    monitor.log_event("AgentStarted", {"agent_name": "ExampleAgent"})
    monitor.log_event("TaskCompleted", {"task_name": "AdditionTask", "status": "success"})

    # Record metrics
    monitor.record_metric("ResponseTime", 1.23)
    monitor.record_metric("Accuracy", 0.98)

    # Display logged data
    logger.info("Logged Events:", monitor.events)
    logger.info("Logged Metrics:", monitor.metrics)

Step-by-Step ExecutionΒΆ

  1. Import the Class Import MonitoringSystem from agenticaiframework.monitoring.

  2. Instantiate the Monitoring System Create an instance of MonitoringSystem to manage event logging and metric recording.

  3. Log Events Use log_event to record significant occurrences, passing:

  4. event_type: A string describing the event.
  5. details: A dictionary with event-specific data.

  6. Record Metrics Use record_metric to store performance or operational metrics, passing:

  7. metric_name: The name of the metric.
  8. value: The metric's value.

  9. Inspect Logged Data Access events and metrics attributes to review stored information.

Best Practice: Use consistent naming conventions for events and metrics to simplify analysis and reporting.

Expected InputΒΆ

No user input is required; the script uses hardcoded values for demonstration purposes. In production, events and metrics could be generated dynamically from agent activities, API calls, or system monitoring hooks.

Expected OutputΒΆ

Text Only
1
2
3
4
5
6
[YYYY-MM-DD HH:MM:SS] [MonitoringSystem] Event logged: AgentStarted - {'agent_name': 'ExampleAgent'}
[YYYY-MM-DD HH:MM:SS] [MonitoringSystem] Event logged: TaskCompleted - {'task_name': 'AdditionTask', 'status': 'success'}
[YYYY-MM-DD HH:MM:SS] [MonitoringSystem] Metric recorded: ResponseTime = 1.23
[YYYY-MM-DD HH:MM:SS] [MonitoringSystem] Metric recorded: Accuracy = 0.98
Logged Events: [{'type': 'AgentStarted', 'details': {'agent_name': 'ExampleAgent'}, 'timestamp': <timestamp>}, {'type': 'TaskCompleted', 'details': {'task_name': 'AdditionTask', 'status': 'success'}, 'timestamp': <timestamp>}]
Logged Metrics: {'ResponseTime': 1.23, 'Accuracy': 0.98}

How to RunΒΆ

Run the example from the project root:

Bash
python examples/monitoring_example.py

If installed as a package, you can also run it from anywhere:

Bash
python -m examples.monitoring_example

Tip: Integrate MonitoringSystem into your agents to automatically log key lifecycle events and performance metrics.