Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding data to host_env #205

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 71 additions & 2 deletions agentops/host_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,78 @@
import psutil
import socket
from .helpers import get_agentops_version
import importlib.metadata
import os
import sys


def get_sdk_details():
try:
return {
"AgentOps SDK Version": get_agentops_version(),
"Python Version": platform.python_version(),
"System Packages": get_sys_packages()
}
except:
return {}


def get_python_details():
try:
return {
"Python Version": platform.python_version()
}
except:
return {}


def get_agentops_details():
try:
return {
"AgentOps SDK Version": get_agentops_version()
}
except:
return {}


def get_sys_packages():
sys_packages = {}
for module in sys.modules:
try:
version = importlib.metadata.version(module)
sys_packages[module] = version
except importlib.metadata.PackageNotFoundError:
# Skip built-in modules and those without package metadata
continue

return sys_packages


def get_installed_packages():

try:
return {
# TODO: test
# TODO: add to opt out
"Installed Packages": {dist.metadata['Name']: dist.version for dist in importlib.metadata.distributions()}
}
except:
return {}


def get_current_directory():
try:
return {
"Project Working Directory": os.getcwd()
}
except:
return {}


def get_virtual_env():
try:
return {
"Virtual Environment": os.environ.get('VIRTUAL_ENV', None)
}
except:
return {}
Expand Down Expand Up @@ -51,7 +116,6 @@ def get_ram_details():
return {}



def get_disk_details():
partitions = psutil.disk_partitions()
disk_info = {}
Expand All @@ -71,7 +135,9 @@ def get_host_env(opt_out: bool = False):
if opt_out:
return {
"SDK": get_sdk_details(),
"OS": get_os_details()
"OS": get_os_details(),
"Project Working Directory": get_current_directory(),
"Virtual Environment": get_virtual_env()
}
else:
return {
Expand All @@ -80,4 +146,7 @@ def get_host_env(opt_out: bool = False):
"CPU": get_cpu_details(),
"RAM": get_ram_details(),
"Disk": get_disk_details(),
"Installed Packages": get_installed_packages(),
"Project Working Directory": get_current_directory(),
"Virtual Environment": get_virtual_env()
}
Loading