# -*- coding: utf-8 -*-
from setuptools import setup

packages = \
['pyctuator',
 'pyctuator.environment',
 'pyctuator.health',
 'pyctuator.httptrace',
 'pyctuator.impl',
 'pyctuator.logfile',
 'pyctuator.logging',
 'pyctuator.metrics',
 'pyctuator.threads']

package_data = \
{'': ['*']}

extras_require = \
{'aiohttp': ['aiohttp>=3.6.2,<4.0.0'],
 'db': ['sqlalchemy>=1.3,<2.0',
        'PyMySQL>=0.9.3,<0.10.0',
        'cryptography>=2.8,<4.0'],
 'fastapi': ['fastapi>=0.41.0,<0.42.0', 'uvicorn>=0.9.0,<0.10.0'],
 'flask': ['flask>=1.1,<2.0'],
 'psutil': ['psutil>=5.6,<6.0'],
 'redis': ['redis>=3.3,<4.0'],
 'tornado': ['tornado>=6.0.4,<7.0.0']}

setup_kwargs = {
    'name': 'pyctuator',
    'version': '0.18.1',
    'description': 'A Python implementation of the Spring Actuator API for popular web frameworks',
    'long_description': '[![PyPI](https://img.shields.io/pypi/v/pyctuator?color=green&style=plastic)](https://pypi.org/project/pyctuator/)\n[![build](https://github.com/SolarEdgeTech/pyctuator/workflows/build/badge.svg)](https://github.com/SolarEdgeTech/pyctuator/)\n[![Codecov](https://img.shields.io/codecov/c/github/SolarEdgeTech/pyctuator?style=plastic)](https://codecov.io/gh/SolarEdgeTech/pyctuator)\n\n# Pyctuator\n\nMonitor Python web apps using \n[Spring Boot Admin](https://github.com/codecentric/spring-boot-admin). \n\nPyctuator supports **[Flask](https://palletsprojects.com/p/flask/)**, **[FastAPI](https://fastapi.tiangolo.com/)**, **[aiohttp](docs.aiohttp.org)** and **[Tornado](https://www.tornadoweb.org/)**. **Django** support is planned as well.\n\nThe following video shows a FastAPI web app being monitored and controled using Spring Boot Admin.\n \n![Pyctuator Example](examples/images/Pyctuator_Screencast.gif)\n\nThe complete example can be found in [Advanced example](examples/Advanced/README.md).\n\n## Requirements\nPython 3.7+\n\nPyctuator has zero hard dependencies.\n\n## Installing\nInstall Pyctuator using pip: `pip3 install pyctuator`\n\n## Why?\nMany Java shops use Spring Boot as their main web framework for developing\nmicroservices. \nThese organizations often use Spring Actuator together with Spring Boot Admin\nto monitor their microservices\' status, gain access to applications\'\n state and configuration, manipulate log levels, etc.\n \nWhile Spring Boot is suitable for many use-cases, it is very common for organizations \nto also have a couple of Python microservices, as Python is often more suitable for \nsome types of applications. The most common examples are Data Science and Machine Learning\napplications.\n\nSetting up a proper monitoring tool for these microservices is a complex task, and might\nnot be justified for just a few Python microservices in a sea of Java microservices.\n\nThis is where Pyctuator comes in. It allows you to easily integrate your Python\nmicroservices into your existing Spring Boot Admin deployment.\n\n## Main Features\nPyctuator is a partial Python implementation of the \n[Spring Actuator API](https://docs.spring.io/spring-boot/docs/2.1.8.RELEASE/actuator-api/html/)  . \n\nIt currently supports the following Actuator features:\n\n* **Application details**\n* **Metrics**\n    * Memory usage\n    * Disk usage \n    * Custom metrics\n* **Health monitors**\n    * Built in MySQL health monitor\n    * Built in Redis health monitor\n    * Custom health monitors\n* **Environment**\n* **Loggers** - Easily change log levels during runtime\n* **Log file** - Tail the application\'s log file\n* **Thread dump** - See which threads are running\n* **HTTP traces** - Tail recent HTTP requests, including status codes and latency\n\n## Quickstart\nThe examples below show a minimal integration of **FastAPI**, **Flask** and **aiohttp** applications with **Pyctuator**.\n\nAfter installing Flask/FastAPI/aiohttp and Pyctuator, start by launching a local Spring Boot Admin instance:\n\n```sh\ndocker run --rm -p 8080:8080 --add-host=host.docker.internal:host-gateway michayaak/spring-boot-admin:2.2.3-1\n```\n\nThen go to `http://localhost:8080` to get to the web UI.\n\n### Flask\nThe following example is complete and should run as is.\n\n```python\nfrom flask import Flask\nfrom pyctuator.pyctuator import Pyctuator\n\napp_name = "Flask App with Pyctuator"\napp = Flask(app_name)\n\n\n@app.route("/")\ndef hello():\n    return "Hello World!"\n\n\nPyctuator(\n    app,\n    app_name,\n    app_url="http://host.docker.internal:5000",\n    pyctuator_endpoint_url="http://host.docker.internal:5000/pyctuator",\n    registration_url="http://localhost:8080/instances"\n)\n\napp.run(debug=False, port=5000)\n```\n\nThe application will automatically register with Spring Boot Admin upon start up.\n\nLog in to the Spring Boot Admin UI at `http://localhost:8080` to interact with the application. \n\n### FastAPI\nThe following example is complete and should run as is.\n\n```python\nfrom fastapi import FastAPI\nfrom uvicorn import Server\n\nfrom uvicorn.config import Config\nfrom pyctuator.pyctuator import Pyctuator\n\n\napp_name = "FastAPI App with Pyctuator"\napp = FastAPI(title=app_name)\n\n\n@app.get("/")\ndef hello():\n    return "Hello World!"\n\n\nPyctuator(\n    app,\n    "FastAPI Pyctuator",\n    app_url="http://host.docker.internal:8000",\n    pyctuator_endpoint_url="http://host.docker.internal:8000/pyctuator",\n    registration_url="http://localhost:8080/instances"\n)\n\nServer(config=(Config(app=app, loop="asyncio"))).run()\n```\n\nThe application will automatically register with Spring Boot Admin upon start up.\n\nLog in to the Spring Boot Admin UI at `http://localhost:8080` to interact with the application. \n\n### aiohttp\nThe following example is complete and should run as is.\n\n```python\nfrom aiohttp import web\nfrom pyctuator.pyctuator import Pyctuator\n\napp = web.Application()\nroutes = web.RouteTableDef()\n\n@routes.get("/")\ndef hello():\n    return web.Response(text="Hello World!")\n\nPyctuator(\n    app,\n    "aiohttp Pyctuator",\n    app_url="http://host.docker.internal:8888",\n    pyctuator_endpoint_url="http://host.docker.internal:8888/pyctuator",\n    registration_url="http://localhost:8080/instances"\n)\n\napp.add_routes(routes)\nweb.run_app(app, port=8888)\n```\n\nThe application will automatically register with Spring Boot Admin upon start up.\n\nLog in to the Spring Boot Admin UI at `http://localhost:8080` to interact with the application.\n\n### Registration Notes\nWhen registering a service in Spring Boot Admin, note that:\n* **Docker** - If the Spring Boot Admin is running in a container while the managed service is running in the docker-host directly, the `app_url` and `pyctuator_endpoint_url` should use `host.docker.internal` as the url\'s host so Spring Boot Admin will be able to connect to the monitored service.\n* **Http Traces** - In order for the "Http Traces" tab to be able to hide requests sent by Spring Boot Admin to the Pyctuator endpoint, `pyctuator_endpoint_url` must be using the same host and port as `app_url`.\n* **HTTPS** - If Pyctuator is to be registered with Spring Boot Admin using HTTPS and the default SSL context is inappropriate, you can provide your own `ssl.SSLContext` using the `ssl_context` optional parameter of the `Pyctuator` constructor.\n* **Insecure HTTPS** - If Spring Boot Admin is using HTTPS with self-signed certificate, set the `PYCTUATOR_REGISTRATION_NO_CERT` environment variable so Pyctuator will disable certificate validation when registering (and deregistering).\n\n## Advanced Configuration\nThe following sections are intended for advanced users who want to configure advanced Pyctuator features.\n\n### Application Info\nWhile Pyctuator only needs to know the application\'s name, we recommend that applications monitored by Spring \nBoot Admin will show additional build and git details. \nThis becomes handy when scaling out a service to multiple instances by showing the version of each instance.\nTo do so, you can provide additional build and git info using methods of the Pyctuator object:\n\n```python\npyctuator = Pyctuator(...)  # arguments removed for brevity\n\npyctuator.set_build_info(\n    name="app",\n    version="1.3.1",\n    time=datetime.fromisoformat("2019-12-21T10:09:54.876091"),\n)\n\npyctuator.set_git_info(\n    commit="7d4fef3",\n    time=datetime.fromisoformat("2019-12-24T14:18:32.123432"),\n    branch="origin/master",\n)\n```\n\nOnce you configure build and git info, you should see them in the Details tab of Spring Boot Admin:\n\n![Detailed Build Info](examples/images/Main_Details_BuildInfo.png)\n\n### Additional Application Info\nIn addition to adding build and git info, Pyctuator allows adding arbitrary application details to the "Info" section in SBA.\n\nThis is done by initializing the `additional_app_info` parameter with an arbitrary dictionary.\nFor example, you can provide links to your application\'s metrics:\n```python\nPyctuator(\n  app,\n  "Flask Pyctuator",\n  app_url=f"http://172.18.0.1:5000",\n  pyctuator_endpoint_url=f"http://172.18.0.1:5000/pyctuator",\n  registration_url=f"http://localhost:8080/instances",\n  app_description="Demonstrate Spring Boot Admin Integration with Flask",\n  additional_app_info=dict(\n    serviceLinks=dict(\n      metrics="http://xyz/service/metrics"\n    ),\n    podLinks=dict(\n      metrics=["http://xyz/pod/metrics/memory", "http://xyz/pod/metrics/cpu"]\n    )\n  )\n)\n```\n\nThis will result with the following Info page in SBA:\n![img.png](examples/images/Additional_App_Info.png)\n\n### DB Health\nFor services that use SQL database via SQLAlchemy, Pyctuator can easily monitor and expose the connection\'s health \nusing the DbHealthProvider class as demonstrated below:\n\n```python\nengine = create_engine("mysql+pymysql://root:root@localhost:3306")\npyctuator = Pyctuator(...)  # arguments removed for brevity\npyctuator.register_health_provider(DbHealthProvider(engine))\n```\n\nOnce you configure the health provider, you should see DB health info in the Details tab of Spring Boot Admin:\n\n![DB Health](examples/images/Main_DB_Health.png)\n\n### Redis health\nIf your service is using Redis, Pyctuator can monitor the connection to Redis by simply initializing a `RedisHealthProvider`:\n\n```python\nr = redis.Redis()\npyctuator = Pyctuator(...)  # arguments removed for brevity\npyctuator.register_health_provider(RedisHealthProvider(r))\n```\n\n### Custom Environment\nOut of the box, Pyctuator exposes Python\'s environment variables to Spring Boot Admin.\n\nIn addition, an application may register an environment provider to provide additional configuration that should be exposed via Spring Boot Admin. \n\nWhen the environment provider is called it should return a dictionary describing the environment. The returned dictionary is exposed to Spring Boot Admin.\n\nSince Spring Boot Admin doesn\'t support hierarchical environment (only a flat key/value mapping), the provided environment is flattened as dot-delimited keys.\n\nPyctuator tries to hide secrets from being exposed to Spring Boot Admin by replacing the values of "suspicious" keys with ***.\n\nSuspicious keys are keys that contain the words "secret", "password" and some forms of "key".\n\nFor example, if an application\'s configuration looks like this:\n\n```python\nconfig = {\n    "a": "s1",\n    "b": {\n        "secret": "ha ha",\n        "c": 625,\n    },\n    "d": {\n        "e": True,\n        "f": "hello",\n        "g": {\n            "h": 123,\n            "i": "abcde"\n        }\n    }\n}\n```\n\nAn environment provider can be registered like so:\n\n```python\npyctuator.register_environment_provider("config", lambda: config)\n```\n\n### Filesystem and Memory Metrics\nPyctuator can provide filesystem and memory metrics.\n\nTo enable these metrics, install [psutil](https://github.com/giampaolo/psutil)\n\nNote that the `psutil` dependency is **optional** and is only required if you want to enable filesystem and memory monitoring.\n\n### Loggers\nPyctuator leverages Python\'s builtin `logging` framework and allows controlling log levels at runtime.\n \nNote that in order to control uvicorn\'s log level, you need to provide a logger object when instantiating it. For example:\n```python\nmyFastAPIServer = Server(\n    config=Config(\n        logger=logging.getLogger("uvi"), \n        app=app, \n        loop="asyncio"\n    )\n)\n```\n\n### Spring Boot Admin Using Basic Authentication\nPyctuator supports registration with Spring Boot Admin that requires basic authentications. The credentials are provided when initializing the Pyctuator instance as follows:\n```python\n# NOTE: Never include secrets in your code !!!\nauth = BasicAuth(os.getenv("sba-username"), os.getenv("sba-password"))\n\nPyctuator(\n    app,\n    "Flask Pyctuator",\n    app_url="http://localhost:5000",\n    pyctuator_endpoint_url=f"http://localhost:5000/pyctuator",\n    registration_url=f"http://spring-boot-admin:8080/instances",\n    registration_auth=auth,\n)\n``` \n\n### Protecting Pyctuator with authentication\nSince there are numerous standard approaches to protect an API, Pyctuator doesn\'t explicitly support any of them. Instead, Pyctuator allows to customize its integration with the web-framework.\nSee the example in [fastapi_with_authentication_example_app.py](examples/FastAPI/fastapi_with_authentication_example_app.py).\n\n## Full blown examples\nThe `examples` folder contains full blown Python projects that are built using [Poetry](https://python-poetry.org/).\n\nTo run these examples, you\'ll need to have Spring Boot Admin running in a local docker container. A Spring Boot Admin Docker image is available [here](https://hub.docker.com/r/michayaak/spring-boot-admin).\n\nUnless the example includes a docker-compose file, you\'ll need to start Spring Boot Admin using docker directly:\n```sh\ndocker run --rm -p 8080:8080 --add-host=host.docker.internal:host-gateway michayaak/spring-boot-admin:2.2.3-1\n```\n(the docker image\'s tag represents the version of Spring Boot Admin, so if you need to use version `2.0.0`, use `michayaak/spring-boot-admin:2.0.0` instead, note it accepts connections on port 8082).\n\nThe examples include\n* [FastAPI Example](examples/FastAPI/README.md) - demonstrates integrating Pyctuator with the FastAPI web framework.\n* [Flask Example](examples/Flask/README.md) - demonstrates integrating Pyctuator with the Flask web framework.\n* [Advanced Example](examples/Advanced/README.md) - demonstrates configuring and using all the advanced features of Pyctuator.\n\n## Contributing\nTo set up a development environment, make sure you have Python 3.7 or newer installed, and run `make bootstrap`.\n\nUse `make check` to run static analysis tools.\n\nUse `make test` to run tests.\n',
    'author': 'Michael Yakobi',
    'author_email': 'michael.yakobi@solaredge.com',
    'maintainer': 'Matan Rubin',
    'maintainer_email': 'matan.rubin@solaredge.com',
    'url': 'https://github.com/SolarEdgeTech/pyctuator',
    'packages': packages,
    'package_data': package_data,
    'extras_require': extras_require,
    'python_requires': '>=3.7,<4.0',
}


setup(**setup_kwargs)
