Metadata-Version: 2.2
Name: resource-reporter
Version: 0.1.1
Summary: A library for monitoring and reporting resource usage in containerized applications
Home-page: https://github.com/yourusername/resource-reporter
Author: Your Name
Author-email: your.email@example.com
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.6
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests>=2.25.0
Requires-Dist: psutil>=5.8.0
Requires-Dist: google-cloud-pubsub>=2.0.0
Provides-Extra: gpu
Requires-Dist: pynvml>=11.0.0; extra == "gpu"
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: provides-extra
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

# Resource Reporter

A Python library for monitoring and reporting resource usage in containerized applications, with support for asynchronous event reporting and command listening.

## Features

- Regular resource usage reporting (CPU, memory, network, GPU)
- Asynchronous event reporting
- Command listening via Google PubSub for remote control of containers
- Support for graceful shutdown and restart

## Installation

### Basic Installation

```bash
pip install resource-reporter
```

### With GPU Support
```bash
pip install resource-reporter[gpu]
```

### Quick Start
```Python
from resource_reporter import ResourceReporter

# Initialize the reporter
reporter = ResourceReporter(
    metrics_endpoint_url="http://monitoring-service/api/metrics",
    events_endpoint_url="http://monitoring-service/api/events",
    interval=30,
    consumer_id="consumer-1",
    group_consumer="production"
)

# Start reporting
reporter.start()

# Report an event
reporter.async_report_event({
    "status": 200,
    "error_code": 0,
    "error_message": "",
    "result": {"processed": True},
    "stats_data": {"duration_ms": 120},
    "task_id": "task-123"
})

# Update job stats
reporter.update_job_stats({
    "processed": 1000,
    "errors": 5
})

# Stop the reporter when done
reporter.stop()
```
### Documentation
## Environment Variables

The Resource Reporter library uses several environment variables for configuration. While most parameters can be passed directly to the constructor, environment variables provide a convenient way to configure the reporter, especially in containerized environments.

### Required Environment Variables

None of the environment variables are strictly required, as all configuration can be passed directly to the constructor. However, the following are commonly used:

### Optional Environment Variables

| Variable | Description | Default |
|----------|-------------|---------|
| `GROUP_CONSUMER` | Group identifier for the consumer | `"default"` |
| `API_KEY` | API key for authentication with metrics and events endpoints | None |
| `GOOGLE_APPLICATION_CREDENTIALS` | Path to Google Cloud credentials JSON file | None |

### Google Cloud Authentication

For PubSub command listening functionality, the reporter requires Google Cloud authentication. There are several ways to provide this:

1. **Service Account JSON** (recommended for non-GCP environments):
   ```bash
   export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account-key.json
License
MIT
