mcp-instana 0.1.0__py3-none-any.whl → 0.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mcp_instana-0.1.1.dist-info/METADATA +908 -0
- mcp_instana-0.1.1.dist-info/RECORD +30 -0
- {mcp_instana-0.1.0.dist-info → mcp_instana-0.1.1.dist-info}/WHEEL +1 -1
- mcp_instana-0.1.1.dist-info/entry_points.txt +4 -0
- mcp_instana-0.1.0.dist-info/LICENSE → mcp_instana-0.1.1.dist-info/licenses/LICENSE.md +3 -3
- src/application/__init__.py +1 -0
- src/{client/application_alert_config_mcp_tools.py → application/application_alert_config.py} +251 -273
- src/application/application_analyze.py +415 -0
- src/application/application_catalog.py +153 -0
- src/{client/application_metrics_mcp_tools.py → application/application_metrics.py} +107 -129
- src/{client/application_resources_mcp_tools.py → application/application_resources.py} +128 -150
- src/application/application_settings.py +1135 -0
- src/application/application_topology.py +107 -0
- src/core/__init__.py +1 -0
- src/core/server.py +436 -0
- src/core/utils.py +213 -0
- src/event/__init__.py +1 -0
- src/{client/events_mcp_tools.py → event/events_tools.py} +128 -136
- src/infrastructure/__init__.py +1 -0
- src/{client/infrastructure_analyze_mcp_tools.py → infrastructure/infrastructure_analyze.py} +200 -203
- src/{client/infrastructure_catalog_mcp_tools.py → infrastructure/infrastructure_catalog.py} +194 -264
- src/infrastructure/infrastructure_metrics.py +167 -0
- src/{client/infrastructure_resources_mcp_tools.py → infrastructure/infrastructure_resources.py} +192 -223
- src/{client/infrastructure_topology_mcp_tools.py → infrastructure/infrastructure_topology.py} +105 -106
- src/log/__init__.py +1 -0
- src/log/log_alert_configuration.py +331 -0
- src/prompts/mcp_prompts.py +900 -0
- src/prompts/prompt_loader.py +29 -0
- src/prompts/prompt_registry.json +21 -0
- mcp_instana-0.1.0.dist-info/METADATA +0 -649
- mcp_instana-0.1.0.dist-info/RECORD +0 -19
- mcp_instana-0.1.0.dist-info/entry_points.txt +0 -3
- src/client/What is the sum of queue depth for all q +0 -55
- src/client/instana_client_base.py +0 -93
- src/client/log_alert_configuration_mcp_tools.py +0 -316
- src/client/show the top 5 services with the highest +0 -28
- src/mcp_server.py +0 -343
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Infrastructure Metrics MCP Tools Module
|
|
3
|
+
|
|
4
|
+
This module provides infrastructure metrics-specific MCP tools for Instana monitoring.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import json
|
|
8
|
+
import logging
|
|
9
|
+
from datetime import datetime
|
|
10
|
+
from typing import Any, Dict, List, Optional, Union
|
|
11
|
+
|
|
12
|
+
from pydantic import StrictBool
|
|
13
|
+
|
|
14
|
+
from src.core.utils import (
|
|
15
|
+
BaseInstanaClient,
|
|
16
|
+
register_as_tool,
|
|
17
|
+
with_header_auth,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
try:
|
|
21
|
+
from instana_client.api.infrastructure_metrics_api import InfrastructureMetricsApi
|
|
22
|
+
from instana_client.models.get_combined_metrics import GetCombinedMetrics
|
|
23
|
+
except ImportError as e:
|
|
24
|
+
import logging
|
|
25
|
+
logger = logging.getLogger(__name__)
|
|
26
|
+
logger.error(f"Error importing Instana SDK: {e}", exc_info=True)
|
|
27
|
+
raise
|
|
28
|
+
|
|
29
|
+
# Configure logger for this module
|
|
30
|
+
logger = logging.getLogger(__name__)
|
|
31
|
+
|
|
32
|
+
class InfrastructureMetricsMCPTools(BaseInstanaClient):
|
|
33
|
+
"""Tools for infrastructure metrics in Instana MCP."""
|
|
34
|
+
|
|
35
|
+
def __init__(self, read_token: str, base_url: str):
|
|
36
|
+
"""Initialize the Infrastructure Analyze MCP tools client."""
|
|
37
|
+
super().__init__(read_token=read_token, base_url=base_url)
|
|
38
|
+
|
|
39
|
+
@register_as_tool
|
|
40
|
+
@with_header_auth(InfrastructureMetricsApi)
|
|
41
|
+
async def get_infrastructure_metrics(self,
|
|
42
|
+
offline: Optional[StrictBool] = False,
|
|
43
|
+
snapshot_ids: Optional[Union[str, List[str]]] = None,
|
|
44
|
+
metrics: Optional[List[str]] = None,
|
|
45
|
+
time_frame: Optional[Dict[str, int]] = None,
|
|
46
|
+
rollup: Optional[int] = None,
|
|
47
|
+
query: Optional[str] = None,
|
|
48
|
+
plugin: Optional[str]=None,
|
|
49
|
+
ctx=None, api_client=None) -> Dict[str, Any]:
|
|
50
|
+
"""
|
|
51
|
+
Get infrastructure metrics from Instana server.
|
|
52
|
+
This tool retrieves infrastructure metrics for specific components in your environment.
|
|
53
|
+
It supports filtering by snapshot IDs, time ranges, metric types, and plugin source.
|
|
54
|
+
Use this tool to analyze system health, performance trends, and resource utilization
|
|
55
|
+
for infrastructure entities (e.g., hosts, containers, JVMs).
|
|
56
|
+
|
|
57
|
+
Args:
|
|
58
|
+
metrics: List of metrics to retrieve with their aggregations
|
|
59
|
+
snapshot_ids: Snapshot ID to retrieve metrics for
|
|
60
|
+
time_frame: Dictionary with 'from' and 'to' timestamps in milliseconds
|
|
61
|
+
Example: {"from": 1617994800000, "to": 1618081200000}
|
|
62
|
+
offline: Whether to include offline snapshots.
|
|
63
|
+
plugin: Plugin to use for retrieving metrics
|
|
64
|
+
limit: Maximum number of items to return (default: 3)
|
|
65
|
+
ctx: The MCP context (optional)
|
|
66
|
+
|
|
67
|
+
Returns:
|
|
68
|
+
Dictionary containing application metrics data or error information
|
|
69
|
+
"""
|
|
70
|
+
|
|
71
|
+
try:
|
|
72
|
+
|
|
73
|
+
# If no metrics is provided, return an error
|
|
74
|
+
if not metrics:
|
|
75
|
+
return {"error": "Metrics is required for this operation"}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
# If no plugin is provided, return an error
|
|
79
|
+
if not plugin:
|
|
80
|
+
return {"error": "Plugin is required for this operation"}
|
|
81
|
+
|
|
82
|
+
if not query:
|
|
83
|
+
return {"error": "Query is required for this operation"}
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
if not time_frame:
|
|
87
|
+
to_time = int(datetime.now().timestamp() * 1000)
|
|
88
|
+
from_time = to_time - (60 * 60 * 1000) # Default to 1 hour
|
|
89
|
+
time_frame = {
|
|
90
|
+
"from": from_time,
|
|
91
|
+
"to": to_time
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if not rollup:
|
|
95
|
+
rollup = 60 # Default rollup to 60 seconds
|
|
96
|
+
|
|
97
|
+
# Create the request body
|
|
98
|
+
request_body = {
|
|
99
|
+
"metrics": metrics,
|
|
100
|
+
"plugin": plugin,
|
|
101
|
+
"rollup": rollup,
|
|
102
|
+
"query": query,
|
|
103
|
+
"timeFrame": time_frame,
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
# Add snapshot IDs if provided
|
|
107
|
+
if snapshot_ids:
|
|
108
|
+
if isinstance(snapshot_ids, str):
|
|
109
|
+
snapshot_ids = [snapshot_ids]
|
|
110
|
+
elif not isinstance(snapshot_ids, list):
|
|
111
|
+
logger.debug(f"Invalid snapshot_ids type: {type(snapshot_ids)}")
|
|
112
|
+
return {"error": "snapshot_ids must be a string or list of strings"}
|
|
113
|
+
request_body["snapshotIds"] = snapshot_ids
|
|
114
|
+
|
|
115
|
+
logger.debug("Sending request to Instana SDK with payload:")
|
|
116
|
+
logger.debug(json.dumps(request_body, indent=2))
|
|
117
|
+
|
|
118
|
+
# Create the InfrastructureMetricsApi object
|
|
119
|
+
get_combined_metrics = GetCombinedMetrics(**request_body)
|
|
120
|
+
|
|
121
|
+
# Call the get_infrastructure_metrics method from the SDK
|
|
122
|
+
result = api_client.get_infrastructure_metrics(
|
|
123
|
+
offline=offline,
|
|
124
|
+
get_combined_metrics=get_combined_metrics
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
# Convert the result to a dictionary
|
|
128
|
+
result_dict: Dict[str, Any] = {}
|
|
129
|
+
|
|
130
|
+
if hasattr(result, 'to_dict'):
|
|
131
|
+
result_dict = result.to_dict()
|
|
132
|
+
elif isinstance(result, dict):
|
|
133
|
+
result_dict = result
|
|
134
|
+
elif isinstance(result, list):
|
|
135
|
+
# If it's a list, wrap it in a dictionary
|
|
136
|
+
result_dict = {"items": result}
|
|
137
|
+
else:
|
|
138
|
+
# For any other type, convert to string and wrap
|
|
139
|
+
result_dict = {"result": str(result)}
|
|
140
|
+
|
|
141
|
+
# Limit the response size
|
|
142
|
+
if "items" in result_dict and isinstance(result_dict["items"], list):
|
|
143
|
+
# Limit items to top 3
|
|
144
|
+
items_list = result_dict["items"]
|
|
145
|
+
original_count = len(items_list)
|
|
146
|
+
if original_count > 3:
|
|
147
|
+
result_dict["items"] = items_list[:3]
|
|
148
|
+
logger.debug(f"Limited response items from {original_count} to 3")
|
|
149
|
+
|
|
150
|
+
# Remove any large nested structures to further reduce size
|
|
151
|
+
if isinstance(result_dict, dict):
|
|
152
|
+
for key, value in dict(result_dict).items():
|
|
153
|
+
if isinstance(value, list) and len(value) > 3 and key != "items":
|
|
154
|
+
original_count = len(value)
|
|
155
|
+
result_dict[key] = value[:3]
|
|
156
|
+
logger.debug(f"Limited {key} from {original_count} to 3")
|
|
157
|
+
|
|
158
|
+
try:
|
|
159
|
+
logger.debug(f"Result from get_infrastructure_metrics: {json.dumps(result_dict, indent=2)}")
|
|
160
|
+
except TypeError:
|
|
161
|
+
logger.debug(f"Result from get_infrastructure_metrics: {result_dict} (not JSON serializable)")
|
|
162
|
+
|
|
163
|
+
return result_dict
|
|
164
|
+
|
|
165
|
+
except Exception as e:
|
|
166
|
+
logger.error(f"Error in get_infrastructure_metrics: {e}", exc_info=True)
|
|
167
|
+
return {"error": f"Failed to get Infra metrics: {e!s}"}
|