Metadata-Version: 2.4
Name: flexmetric
Version: 0.1.2
Summary: A flexible Prometheus exporter for commands, databases, functions, and scripts.
Home-page: https://github.com/nikhillingadhal1999/custom_prometheus_agent
Author: Nikhil Lingadhal
License: MIT
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.7
Description-Content-Type: text/markdown
Requires-Dist: prometheus_client
Requires-Dist: PyYAML
Requires-Dist: psutil
Requires-Dist: setuptools
Requires-Dist: wheel
Requires-Dist: twine
Dynamic: author
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: license
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

# FlexMetric

FlexMetric is a lightweight, flexible, and extensible Prometheus exporter that allows you to expose system metrics, database query results, script outputs, and Python function outputs as Prometheus-compatible metrics with minimal setup and maximum customization.

---

## Features

- Run shell commands and expose the results as Prometheus metrics.
- Execute SQL queries (e.g., SQLite) and monitor database statistics.
- Automatically discover and expose Python function outputs.
- Run custom shell scripts and monitor their outputs.
- Modular and easy to extend—add your own integrations.
- Built-in Prometheus HTTP server (`/metrics`) with configurable port.

---

## Installation

Install from PyPI:

```bash
pip install flexmetric
```
## Usage

Run FlexMetric from the command line:

```bash
flexmetric --commands --commands-config commands.yaml --port 8000
```

## Available Modes

FlexMetric supports multiple modes that can be used individually or combined to expose metrics:

| Mode           | Description                                      | Required Configuration File(s)           |
|---------------|--------------------------------------------------|------------------------------------------|
| `--commands`   | Runs system commands and exports outputs as Prometheus metrics.         | `commands.yaml`                          |
| `--database`   | Executes SQL queries on databases and exports results.                 | `database.yaml` and `queries.yaml`       |
| `--functions`  | Discovers and runs user-defined Python functions and exports outputs.   | `executable_functions.txt`               |
| `--scripts`    | Executes custom shell scripts and exports outputs.                     | `scripts.yaml`                           |

### Example of Using Multiple Modes Together

```bash
flexmetric --commands --commands-config commands.yaml --database --database-config database.yaml --queries-config queries.yaml
```

## Configuration File Examples

Below are example configurations for each supported mode.

### commands.yaml

```yaml
commands:
  - name: disk_usage
    command: df -h
    label: path
    timeout_seconds: 60
```
```yaml
databases:
  - name: mydb
    db_type: sqlite
    db_connection: /path/to/my.db
````
```yaml
queries:
  - name: user_count
    db_type: sqlite
    db_name: mydb
    query: "SELECT COUNT(*) FROM users;"
    label: table
    label_value: users
```
executable_functions.txt 
```
function_name_1
function_name_2
```

## Command-Line Options

The following command-line options are available when running FlexMetric:

| Option              | Description                                              | Default                    |
|---------------------|----------------------------------------------------------|----------------------------|
| `--port`            | Port for the Prometheus metrics server                    | `8000`                     |
| `--commands`        | Enable commands mode                                      |                            |
| `--commands-config` | Path to commands YAML file                                | `commands.yaml`            |
| `--database`        | Enable database mode                                      |                            |
| `--database-config` | Path to database YAML file                                | `database.yaml`            |
| `--queries-config`  | Path to queries YAML file                                 | `queries.yaml`             |
| `--functions`       | Enable Python functions mode                              |                            |
| `--functions-file`  | Path to functions file                                    | `executable_functions.txt` |
| `--scripts`         | Enable shell scripts mode                                 |                            |
| `--scripts-config`  | Path to scripts YAML file                                 | `scripts.yaml`             |

### Example Command:

```bash
flexmetric --commands --commands-config commands.yaml --port 8000
```
## Example Prometheus Output

Once FlexMetric is running, the `/metrics` endpoint will expose metrics in the Prometheus format.

Example output:
```bash
disk_usage_gauge{path="/"} 45.0
```

Each metric includes labels and numeric values that Prometheus can scrape and visualize.

---

## Future Enhancements

The following features are planned or under consideration to improve FlexMetric:

- Support for additional databases such as PostgreSQL and MySQL.
- Enhanced support for more complex scripts and richer label extraction.
