Skip to content

Commit

Permalink
Init project
Browse files Browse the repository at this point in the history
  • Loading branch information
butschster committed Dec 26, 2022
1 parent 5193c4d commit 05caaa5
Show file tree
Hide file tree
Showing 39 changed files with 1,873 additions and 2 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true

[*.yml]
indent_size = 2

[*.yaml]
indent_size = 2
16 changes: 16 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
APP_ENV=production

# Debug mode set to TRUE disables view caching and enables higher verbosity.
DEBUG=true
VERBOSITY_LEVEL=verbose

# Available levels: DEBUG, INFO, NOTICE, WARNING, ERROR, CRITICAL, ALERT, EMERGENCY
MONOLOG_DEFAULT_LEVEL=DEBUG

QUEUE_DRIVER=roadrunner
QUEUE_PIPELINE=memory

CACHE_STORAGE=local

# Packagist repository names to follow (comma separated)
PACKAGIST_REPOSITORIES=
36 changes: 36 additions & 0 deletions .github/workflows/docker-dev-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Docker Dev Image CI

on:
push:
branches:
- master

jobs:
build-release:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ secrets.GHCR_LOGIN }}
password: ${{ secrets.GHCR_PASSWORD }}

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2

- name: Build and push
id: docker_build
uses: docker/build-push-action@v3
with:
context: ./
file: ./docker/Dockerfile
push: true
build-args:
APP_VERSION=dev
tags:
ghcr.io/metrixio/docker:dev
43 changes: 43 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Docker Image CI

on:
release:
types:
- created

jobs:
build-release:
if: "!github.event.release.prerelease"
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: 'Get Previous tag'
id: previoustag
uses: "WyriHaximus/github-action-get-previous-tag@v1"
with:
fallback: v0.1

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ secrets.GHCR_LOGIN }}
password: ${{ secrets.GHCR_PASSWORD }}

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2

- name: Build and push
id: docker_build
uses: docker/build-push-action@v3
with:
context: ./
file: ./docker/Dockerfile
push: true
build-args:
APP_VERSION=${{ steps.previoustag.outputs.tag }}
tags:
ghcr.io/metrixio/docker:latest, ghcr.io/metrixio/docker:${{ steps.previoustag.outputs.tag }}
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.idea
vendor
runtime
rr*
spiral*
.env
.phpunit.result.cache
.deptrac.cache
composer.lock
29 changes: 29 additions & 0 deletions .rr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version: '2.7'

rpc:
listen: tcp://127.0.0.1:6001

logs:
level: info

server:
command: "php app.php"
relay: pipes

kv:
local:
driver: memory
config: {}

jobs:
pool:
num_workers: 2

service:
collector:
command: "php app.php collect:start"
remain_after_exit: true
restart_sec: 1

metrics:
address: 0.0.0.0:2112
18 changes: 18 additions & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
risky: false
preset: psr12
enabled:
# Risky Fixers
# - declare_strict_types
# - void_return
- ordered_class_elements
- linebreak_after_opening_tag
- single_quote
- no_blank_lines_after_phpdoc
- unary_operator_spaces
- no_useless_else
- no_useless_return
- trailing_comma_in_multiline_array
finder:
exclude:
- "tests"
- "public"
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License
The MIT License (MIT)

Copyright (c) 2022 metrix.io
Copyright (c) 2020 Spiral Scout

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
83 changes: 83 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Packagist metrics collector

![packagist](https://user-images.githubusercontent.com/773481/209584409-3275bfa7-f131-44de-b4c1-341d4b0cd3d3.png)

This tool lets you easily gather data about downloads from Packagist.

It works with Prometheus and Grafana to collect data from Packagist, store it in Prometheus, and create visualizations
with Grafana. You can use Grafana to customize the data you collect and create dashboards that fit your needs.

We hope you find it helpful!

## Dashboard

![image](https://user-images.githubusercontent.com/773481/209584323-9f673696-f235-4737-b7ea-719da8c3ada3.png)

## Usage

Check out the documentation in the [dashboard](https://github.com/metrixio/dashboard) repository. That should give you
all the details you need to get going.

```dotenv
# Packagist repository names to follow (comma separated)
PACKAGIST_REPOSITORIES=...
```

### Docker

```yaml
version: "3.7"

services:
docker-metrics:
image: ghcr.io/metrixio/packagist:latest
environment:
PACKAGIST_REPOSITORIES: ...
restart: on-failure

prometheus:
image: prom/prometheus
volumes:
- ./runtime/prometheus:/prometheus
restart: always

grafana:
image: grafana/grafana
depends_on:
- prometheus
ports:
- 3000:3000
volumes:
- ./runtime/grafana:/var/lib/grafana
restart: always
```
### Local server
```bash
composer create-project metrixio/packagist
```

Define the repositories you want to track in `.env` file

```dotenv
PACKAGIST_REPOSITORIES=spiral/framework,...
```

Once the project is installed and configured you can start application server:

```bash
./rr serve
```

Metrics will be available on http://127.0.0.1:2112.

> **Note**:
> To fix unable to open metrics page, change metrics address in RoadRunner config file to `127.0.0.1:2112`.
-----

The package is built with some of the best tools out there for PHP. It's powered
by [Spiral Framework](https://github.com/spiral/framework/), which makes it super fast and efficient, and it
uses [RoadRunner](https://github.com/roadrunner-server/roadrunner) as the server, which is a really great tool for
collecting metrics data for Prometheus.
30 changes: 30 additions & 0 deletions app.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

use App\Application\Kernel;
use App\Application\Service\ErrorHandler\Handler;

// If you forgot to configure some of this in your php.ini file,
// then don't worry, we will set the standard environment
// settings for you.

\mb_internal_encoding('UTF-8');
\error_reporting(E_ALL | E_STRICT ^ E_DEPRECATED);
\ini_set('display_errors', 'stderr');

// Register Composer's auto loader.
require __DIR__ . '/vendor/autoload.php';


// Initialize shared container, bindings, directories and etc.
$app = Kernel::create(
directories: ['root' => __DIR__],
)->run();

if ($app === null) {
exit(255);
}

$code = (int)$app->serve();
exit($code);
19 changes: 19 additions & 0 deletions app/config/cache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

use Spiral\Cache\Storage\ArrayStorage;
use Spiral\Cache\Storage\FileStorage;

return [
'default' => env('CACHE_STORAGE', 'local'),
'aliases' => [
'repositories' => 'local',
],
'storages' => [
'local' => [
'type' => 'roadrunner',
'driver' => 'local',
],
],
];
16 changes: 16 additions & 0 deletions app/config/monolog.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

use Monolog\Handler\ErrorLogHandler;
use Monolog\Logger;

return [
'default' => 'roadrunner',
'globalLevel' => Logger::toMonologLevel(env('MONOLOG_DEFAULT_LEVEL', Logger::DEBUG)),
'handlers' => [
'roadrunner' => [
\Spiral\RoadRunnerBridge\Logger\Handler::class,
]
],
];
7 changes: 7 additions & 0 deletions app/config/packagist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

declare(strict_types=1);

return [
'repositories' => [],
];
34 changes: 34 additions & 0 deletions app/config/queue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

use Spiral\RoadRunner\Jobs\Queue\MemoryCreateInfo;
use Spiral\RoadRunnerBridge\Queue\Queue;

return [
'default' => env('QUEUE_DRIVER', 'roadrunner'),
'aliases' => [],
'connections' => [
'roadrunner' => [
'driver' => 'roadrunner',
'default' => env('QUEUE_PIPELINE', 'memory'),
'pipelines' => [
'memory' => [
'connector' => new MemoryCreateInfo('local'),
'consume' => true,
],
],
],
],

'registry' => [
'handlers' => [],
],

'interceptors' => [
'push' => [],
'consume' => [
\Spiral\Queue\Interceptor\Consume\ErrorHandlerInterceptor::class,
],
],
];
Loading

0 comments on commit 05caaa5

Please sign in to comment.