|  Download Docker Poller for LaravelThis package allows laravel applications to interact with the Docker Engine API. The Docker Engine API is an HTTP API served by Docker Engine. It is the API the Docker client uses 
to communicate with the Engine, so everything the Docker client can do can be done with the API. InstallationYou can install the package via composer and then publish the assets: 
composer require acamposm/docker-poller
php artisan vendor:publish --provider="Acamposm\DockerEngineApiPoller\DockerPollerServiceProvider"
 *Note:* We try to follow SemVer v2.0.0. RequirementsTo use this packet, you must enable first the Docker Engine API, normally the Engine API listens on 
port 2375, but it is configurable. *Note:* In production environments, you must always secure the API with SSL encryption and 
control who can perform request to this API. UsageBasic InitializationFirst, create a DockerServer instance with the details of the docker server hosts.  *Note:* By default, the DockerServer class, has as a default parameters the default port of Docker Engine API (2375) and the protocol (http). Docker Engine API over HTTPuse Acamposm\DockerEngineApiPoller\DockerServer;
$server = (new DockerServer())->server('localhost');
 or use Acamposm\DockerEngineApiPoller\DockerServer;
$server = (new DockerServer())->insecure()->port(12375)->server('localhost');
 Docker Engine API over HTTPSuse Acamposm\DockerEngineApiPoller\DockerServer;
$server = (new DockerServer())->secure()->server('localhost');
 or  use Acamposm\DockerEngineApiPoller\DockerServer;
$server = (new DockerServer())->secure()->port(12375)->server('localhost');
 API ResourcesContainersGet Containers ListGet a list of the running containers in the docker host. use Acamposm\DockerEngineApiPoller\DockerServer;
use Acamposm\DockerEngineApiPoller\DockerApiRequest;
use Acamposm\DockerEngineApiPoller\Enums\ResourceMethods;
$server = (new DockerServer())->server('192.168.10.101');
$containers_list = (new DockerApiRequest($server))
  ->containers(ResourceMethods::CONTAINERS_LIST)
  ->get();
 Get Container DetailsTo get the full details of a container... use Acamposm\DockerEngineApiPoller\DockerServer;
use Acamposm\DockerEngineApiPoller\DockerApiRequest;
use Acamposm\DockerEngineApiPoller\Enums\ResourceMethods;
$server = (new DockerServer())->server('192.168.10.101');
$container_details = (new DockerApiRequest($server))
  ->containers(ResourceMethods::CONTAINERS_INSPECT, 'container_name')
  ->get();
 Get Container StatsGet the resources used by a single container, then use the class ContainerMetrics to get the usage of a container. use Acamposm\DockerEngineApiPoller\ContainerMetrics;
use Acamposm\DockerEngineApiPoller\DockerServer;
use Acamposm\DockerEngineApiPoller\DockerApiRequest;
use Acamposm\DockerEngineApiPoller\Enums\ResourceMethods;
$server = (new DockerServer())->server('192.168.10.101');
$container_stats = (new DockerApiRequest($server))
  ->containers(ResourceMethods::CONTAINERS_STATS, 'container_name')
  ->get();
$metrics = (new ContainerMetrics($container_stats))->metrics();
var_dump($metrics);
 The result will be a json object with the container statistics, ready to save to a database. {
  "timestamp": "2020-09-20T19:00:05.491127778Z",
  "id": "2206b35c6fecc6ce320effb68492d8a79fd5f2e5f230dda9371fca8c822428df",
  "name": "/nextcloud",
  "cpu": {
    "count": 2,
    "percent_free": 99.9960912,
    "percent_used": 0.0039088
  },
  "memory": {
    "free": 8236134400,
    "used": 105889792,
    "total": 8342024192,
    "percent_free": 98.730646308823,
    "percent_used": 1.2693536911766
  },
  "network": [
    {
      "eth0": {
        "rx_bytes": 3337270,
        "rx_packets": 3306,
        "rx_errors": 0,
        "rx_dropped": 0,
        "tx_bytes": 1002431,
        "tx_packets": 2090,
        "tx_errors": 0,
        "tx_dropped": 0
      }
    }
  ]
}
 ImagesGet Images ListTo get a list with all images on the docker host. use Acamposm\DockerEngineApiPoller\DockerServer;
use Acamposm\DockerEngineApiPoller\DockerApiRequest;
use Acamposm\DockerEngineApiPoller\Enums\ResourceMethods;
$server = (new DockerServer())->server('192.168.10.101');
$images = (new DockerApiRequest($server))
  ->images(ResourceMethods::IMAGES_LIST)
  ->get();
 Get Image DetailsTo get the full details of an image. use Acamposm\DockerEngineApiPoller\DockerServer;
use Acamposm\DockerEngineApiPoller\DockerApiRequest;
use Acamposm\DockerEngineApiPoller\Enums\ResourceMethods;
$server = (new DockerServer())->server('192.168.10.101');
$image_details = (new DockerApiRequest($server))
  ->images(ResourceMethods::IMAGES_INSPECT, 'image_name')
  ->get();
 NetworksGet Networks Listuse Acamposm\DockerEngineApiPoller\DockerServer;
use Acamposm\DockerEngineApiPoller\DockerApiRequest;
use Acamposm\DockerEngineApiPoller\Enums\ResourceMethods;
$server = (new DockerServer())->server('192.168.10.101');
$networks = (new DockerApiRequest($server))
  ->networks(ResourceMethods::NETWORKS_LIST)
  ->get();
 Get Network DetailsTo get the full details of a network in the docker host. use Acamposm\DockerEngineApiPoller\DockerServer;
use Acamposm\DockerEngineApiPoller\DockerApiRequest;
use Acamposm\DockerEngineApiPoller\Enums\ResourceMethods;
$server = (new DockerServer())->server('192.168.10.101');
$network_details = (new DockerApiRequest($server))
  ->networks(ResourceMethods::NETWORKS_INSPECT, 'network_name')
  ->get();
 VolumesGet Volumes ListGet a list of volumes in the docker host. use Acamposm\DockerEngineApiPoller\DockerServer;
use Acamposm\DockerEngineApiPoller\DockerApiRequest;
use Acamposm\DockerEngineApiPoller\Enums\ResourceMethods;
$server = (new DockerServer())->server('192.168.10.101');
$volumes = (new DockerApiRequest($server))
  ->volumes(ResourceMethods::VOLUMES_LIST)
  ->get();
 Get Volume DetailsGet a list of volumes in the docker host. use Acamposm\DockerEngineApiPoller\DockerServer;
use Acamposm\DockerEngineApiPoller\DockerApiRequest;
use Acamposm\DockerEngineApiPoller\Enums\ResourceMethods;
$server = (new DockerServer())->server('192.168.10.101');
$volume_details = (new DockerApiRequest($server))
  ->volumes(ResourceMethods::VOLUMES_INSPECT, 'volume_name')
  ->get();
 Testing
composer test
 ChangelogPlease see CHANGELOG for more information what has changed recently. ContributingThank you for considering contributing to the improvement of the package. Please see CONTRIBUTING for details. Security VulnerabilitiesIf you discover any security related issues, please send an e-mail to Angel Campos via [email protected] instead of using the issue tracker. All security vulnerabilities will be promptly addressed. CreditsLicenseThe package Ping is open-source package and is licensed under The MIT License (MIT). Please see License File for more information. |