Metadata-Version: 2.4
Name: bi-cli
Version: 1.1.0
Summary: Pacote BI - ferramentas de análise e visualização de dados
Author-email: Almir <almir@almirernanioconsultor.com.br>
License: MIT License
        
        Copyright (c) 2026 Almir Ernanio
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Keywords: bi,analytics,data
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: psutil
Requires-Dist: psycopg2-binary
Dynamic: license-file

# bi-cli

Monitor de stack direto do terminal. Verifique memória, CPU, disco, containers Docker e serviços HTTP com comandos simples.

## Instalação

```bash
pip install bi-cli
```

## Uso

```bash
bi --help
bi --version
```

---

## bi system

### `bi system memory` — Memória RAM

```bash
bi system memory              # uso de memória RAM
bi system memory -s           # inclui informações de swap
bi system memory --swap       # idem
bi system memory -t 5         # top 5 processos por memória
bi system memory --top 5      # idem
bi system memory -s -t 5      # swap + top 5
```

Exemplo de saída:
```
Total:      8.0 GB
Usado:      5.3 GB
Disponível: 2.7 GB
Uso:        66.2%

[Swap]
Total:      2.0 GB
Usado:      0.4 GB
Livre:      1.6 GB
Uso:        20.0%

[Top 5 processos por memória]
PID      Nome                           Memória (MB)
----------------------------------------------------
1234     chrome                              512.4
5678     python                              210.1
9012     code                                198.7
```

---

### `bi system cpu` — CPU

```bash
bi system cpu                 # uso geral de CPU
bi system cpu -t 5            # top 5 processos por CPU
bi system cpu --top 5         # idem
```

Exemplo de saída:
```
Núcleos físicos:  2
Núcleos lógicos:  2
Frequência:       2400 MHz
Uso total:        34.5%

[Top 5 processos por CPU]
PID      Nome                           CPU %
---------------------------------------------
1234     python                             45.2
5678     node                               12.1
```

---

### `bi system disk` — Armazenamento

```bash
bi system disk                # todas as partições
bi system disk -a 80          # alerta partições com uso acima de 80%
bi system disk --alert 80     # idem
```

Exemplo de saída:
```
Partição             Total    Usado    Livre    Uso
--------------------------------------------------------
/                   500.0G   430.0G    70.0G   86.0% ⚠️  acima de 80%
/boot/efi             0.5G     0.1G     0.4G   20.0%
```

---

## bi docker

### `bi docker status` — Lista containers

```bash
bi docker status
```

Exemplo de saída:
```
Nome                           Status       Portas
--------------------------------------------------------------------------
✅ airflow_webserver            Up 2 hours   127.0.0.1:8080->8080/tcp
✅ postgres_dw                  Up 2 hours   127.0.0.1:5432->5432/tcp
❌ metabase                     Exited (1)
```

---

### `bi docker logs` — Logs de um container

```bash
bi docker logs --nome airflow_scheduler          # últimas 50 linhas
bi docker logs --nome airflow_scheduler -l 100   # últimas 100 linhas
bi docker logs --nome airflow_scheduler --lines 100
bi docker logs --nome airflow_scheduler -f       # tempo real
bi docker logs --nome airflow_scheduler --follow
bi docker logs --nome airflow_scheduler -l 20 -f # 20 linhas + tempo real
```

---

### `bi docker restart` — Reinicia um container

```bash
bi docker restart --nome airflow_scheduler
bi docker restart --nome fastapi_gold
```

---

### `bi docker parar` — Para um container

```bash
bi docker parar --nome metabase
bi docker parar --nome postgres_dw
```

---

### `bi docker iniciar` — Inicia um container parado

```bash
bi docker iniciar --nome metabase
bi docker iniciar --nome postgres_dw
```

---

### `bi docker exec` — Executa um comando dentro de um container

```bash
bi docker exec --nome postgres_dw psql -U postgres
bi docker exec --nome airflow_scheduler bash
bi docker exec --nome fastapi_gold pip list
```

---

## bi postgres

Todos os comandos aceitam as mesmas flags de conexão ou variáveis de ambiente:

| Flag | Variável de ambiente | Padrão |
|---|---|---|
| `--host` | `BI_PG_HOST` | `localhost` |
| `--port` | `BI_PG_PORT` | `5432` |
| `--user` | `BI_PG_USER` | `postgres` |
| `--senha` | `BI_PG_PASSWORD` | _(vazio)_ |
| `--database` | `BI_PG_DATABASE` | `postgres` |

> **Dependência:** requer `psycopg2` instalado (`pip install psycopg2-binary`).

### `bi postgres status` — Verifica conexão

```bash
bi postgres status --host localhost --port 5432 --user airflow --senha airflow --database airflow
```

Exemplo de saída:
```
Conectando em localhost:5432 (database: airflow)...

✅ Conectado com sucesso (12 ms)
   PostgreSQL 15.3
```

Em caso de falha, exibe dicas contextuais:
```
❌ Falha ao conectar: Connection refused

💡 Dica: a porta do Postgres pode não estar exposta para fora do Docker.
   Verifique se o docker-compose mapeia a porta:
   ports:
     - "5432:5432"
```

---

### `bi postgres conectado` — Lista conexões ativas

```bash
bi postgres conectado --host localhost --user airflow --senha airflow --database airflow
```

Exemplo de saída:
```
Database             Estado               Conexões
----------------------------------------------------
airflow              active                      8
airflow              idle                        3
postgres             idle                        1

✅ Total: 12/100 conexões (12.0%)
```

Ícones de alerta:
- ✅ Abaixo de 70% das conexões máximas
- ⚠️ Entre 70% e 89%
- 🔴 90% ou mais — crítico

---

### `bi postgres volume` — Tamanho dos databases

```bash
bi postgres volume --host localhost --user airflow --senha airflow
```

Exemplo de saída:
```
Database                  Tamanho
--------------------------------------
airflow                    142 MB
postgres                     8192 bytes
```

---

## bi services

### `bi services status` — Verifica serviços HTTP

Checa os principais serviços da stack e classifica cada um em três categorias:

- ✅ Respondendo normalmente
- ⚠️ Com problema (timeout ou erro 5xx)
- ➖ Não encontrado na stack

```bash
bi services status              # timeout padrão de 5s
bi services status -t 10        # timeout de 10s por serviço
bi services status --timeout 10
```

Exemplo de saída:
```
Verificando serviços...

Serviço        URL                                      Status
----------------------------------------------------------------------
✅ Airflow      http://localhost:8080/airflow/health     200
✅ FastAPI      http://localhost:8000                    200
✅ MinIO        http://localhost:9001                    200

⚠️  Com problema:
----------------------------------------------------------------------
⚠️  Metabase    http://localhost:3000                    timeout

➖ Não encontrados na stack:
----------------------------------------------------------------------
➖ Grafana      http://localhost:3001                    não encontrado
➖ Jupyter      http://localhost:8888                    não encontrado

──────────────────────────────────────────────────────────────────────
✅ Respondendo: 3   ⚠️  Com problema: 1   ➖ Ausentes: 2

⚠️  Atenção: verifique os serviços com problema.
```

---

### `bi services ssl` — Verifica certificados SSL

```bash
bi services ssl --dominio bisobmedida.tech
bi services ssl --dominio bisobmedida.tech almirernanioconsultor.com.br
```

Exemplo de saída:
```
Domínio                                  Status     Expira
---------------------------------------------------------------------------
✅ bisobmedida.tech                       válido · expira em 42 dias (10/08/2026)
⚠️  almirernanioconsultor.com.br          atenção · expira em 18 dias (16/07/2026)
```

Níveis de alerta:
- ✅ Mais de 30 dias restantes
- ⚠️ Entre 8 e 30 dias restantes
- 🔴 7 dias ou menos — crítico

---

## Desenvolvimento

```bash
# Clonar e instalar em modo editável
git clone https://github.com/seu-usuario/pacote_bi
cd pacote_bi
python -m venv .venv
source .venv/bin/activate
pip install -e .

# Testar
bi --help
```

---

## Licença

MIT License — Copyright (c) 2026 Almir Ernani. Consulte o arquivo [LICENSE](LICENSE) para mais detalhes.
