This repository has been archived by the owner on Nov 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Chore] Add Prometheus support for insights (#96)
* Install prometheus exporter * Add prometheus service provider * Add census metrics * Add setup agent script * Ignore agent * Add production dockerfile * Add agent config * Add install agent composer task * Add agent worker * Move setup agent to post install * Add prometheus service to compose * Run linter * Implement collectors * Fix prometheus network * Add agent doc * Add laravel scrape config * Run lint fix * Add gauge helpers * Convert site insights to gauge * Override screen handle to fix save method params Used the workaround proposed in this [PR](orchidsoftware/platform#2299) * Add seed allocation gauge * Add model typehint * Convert batch insights to gauge * Remove redundant crop metric * Convert crop insights to gauge * Add Grafana dashboard export jsons * Change values to float * Remove unnecessary cast * Add crop profit dashboard * Convert farmland insights to gauge * Run lint fix * Add farmland dashboard * Add estimated yield amount metric * Convert farmer report insights to gauge * Add farmer report dashboard * Add site dashboard
- Loading branch information
Showing
37 changed files
with
5,833 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
.git | ||
.gitignore | ||
.github | ||
/node_modules | ||
/public/hot | ||
/public/storage | ||
/storage/*.key | ||
/storage/framework/cache | ||
/storage/framework/views | ||
/storage/app | ||
/docker | ||
/tests | ||
/vendor | ||
.env | ||
.env.ci | ||
.devcontainer | ||
.vscode | ||
.editorconfig | ||
.styleci.yml | ||
docker-compose.yml | ||
pint.json | ||
phpcs.xml | ||
phpunit.xml | ||
.phpunit.result.cache | ||
.phpstorm.meta.php | ||
.editorconfig | ||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,4 @@ database.env | |
.php-cs-fixer.cache | ||
.vscode | ||
influxdb.env | ||
agent-linux-amd64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
FROM richarvey/nginx-php-fpm:1.7.2 | ||
|
||
COPY . . | ||
|
||
# Image config | ||
ENV SKIP_COMPOSER 1 | ||
ENV WEBROOT /var/www/html/public | ||
ENV PHP_ERRORS_STDERR 1 | ||
ENV RUN_SCRIPTS 1 | ||
ENV REAL_IP_HEADER 1 | ||
|
||
# Laravel config | ||
ENV APP_ENV production | ||
ENV APP_DEBUG false | ||
ENV LOG_CHANNEL stderr | ||
|
||
# Allow composer to run as root | ||
ENV COMPOSER_ALLOW_SUPERUSER 1 | ||
|
||
CMD ["/start.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
web: vendor/bin/heroku-php-apache2 public/ | ||
worker: php artisan queue:restart && php artisan queue:work --tries=3 | ||
agent: ./agent-linux-amd64 -config.file=agent-config.yml -config.expand-env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
metrics: | ||
configs: | ||
- name: integrations | ||
remote_write: | ||
- basic_auth: | ||
password: ${PROMETHEUS_PASSWORD} | ||
username: ${PROMETHEUS_USERNAME} | ||
url: ${PROMETHEUS_PUSH_URL} | ||
scrape_configs: | ||
- job_name: app | ||
static_configs: | ||
- targets: ["${PROMETHEUS_TARGET_URL}"] | ||
global: | ||
scrape_interval: 60s | ||
wal_directory: /tmp/grafana-agent-wal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace App\Collectors; | ||
|
||
use Arquivei\LaravelPrometheusExporter\CollectorInterface; | ||
use Arquivei\LaravelPrometheusExporter\PrometheusExporter; | ||
|
||
class BatchCollector implements CollectorInterface | ||
{ | ||
public function getName(): string | ||
{ | ||
return 'batches'; | ||
} | ||
|
||
public function registerMetrics(PrometheusExporter $exporter): void | ||
{ | ||
$exporter->registerGauge( | ||
'batch_total', | ||
'The total number of batches.', | ||
['region', 'province', 'municity'] | ||
); | ||
|
||
$exporter->registerGauge( | ||
'batch_seed_allocation_total', | ||
'The total number of batch seed allocations.', | ||
['crop', 'region', 'province', 'municity'] | ||
); | ||
} | ||
|
||
public function collect(): void | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace App\Collectors; | ||
|
||
use Arquivei\LaravelPrometheusExporter\CollectorInterface; | ||
use Arquivei\LaravelPrometheusExporter\PrometheusExporter; | ||
|
||
class CropCollector implements CollectorInterface | ||
{ | ||
public function getName(): string | ||
{ | ||
return 'crops'; | ||
} | ||
|
||
public function registerMetrics(PrometheusExporter $exporter): void | ||
{ | ||
$exporter->registerGauge( | ||
'crop_profit_per_kg_pesos', | ||
'The total profit per kilogram of crops.', | ||
['crop'] | ||
); | ||
|
||
$exporter->registerGauge( | ||
'crop_net_profit_cost_ratio', | ||
'The total net profit cost ratio of crops.', | ||
['crop'] | ||
); | ||
} | ||
|
||
public function collect(): void | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace App\Collectors; | ||
|
||
use Arquivei\LaravelPrometheusExporter\CollectorInterface; | ||
use Arquivei\LaravelPrometheusExporter\PrometheusExporter; | ||
|
||
class FarmerCollector implements CollectorInterface | ||
{ | ||
public function getName(): string | ||
{ | ||
return 'farmers'; | ||
} | ||
|
||
public function registerMetrics(PrometheusExporter $exporter): void | ||
{ | ||
$exporter->registerGauge( | ||
'farmer_total', | ||
'The total number of farmers.', | ||
['region', 'province', 'municity'] | ||
); | ||
|
||
$exporter->registerGauge( | ||
'farmer_report_total', | ||
'The total number of farmer reports.', | ||
['crop', 'seed_stage', 'region', 'province', 'municity'] | ||
); | ||
|
||
$exporter->registerGauge( | ||
'farmer_report_estimated_yield_grams', | ||
'The estimated yield in grams from farmer reports.', | ||
['crop', 'region', 'province', 'municity', 'yield_date_earliest', 'yield_date_latest'] | ||
); | ||
} | ||
|
||
public function collect(): void | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace App\Collectors; | ||
|
||
use Arquivei\LaravelPrometheusExporter\CollectorInterface; | ||
use Arquivei\LaravelPrometheusExporter\PrometheusExporter; | ||
|
||
class FarmlandCollector implements CollectorInterface | ||
{ | ||
public function getName(): string | ||
{ | ||
return 'farmlands'; | ||
} | ||
|
||
public function registerMetrics(PrometheusExporter $exporter): void | ||
{ | ||
$exporter->registerGauge( | ||
'farmland_total', | ||
'The total number of farmlands.', | ||
['type', 'status', 'region', 'province', 'municity'] | ||
); | ||
|
||
$exporter->registerGauge( | ||
'farmland_hectares', | ||
'The total hectares of farmlands.', | ||
['type', 'status', 'region', 'province', 'municity'] | ||
); | ||
} | ||
|
||
public function collect(): void | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace App\Collectors; | ||
|
||
use Arquivei\LaravelPrometheusExporter\CollectorInterface; | ||
use Arquivei\LaravelPrometheusExporter\PrometheusExporter; | ||
|
||
class SiteCollector implements CollectorInterface | ||
{ | ||
public function getName(): string | ||
{ | ||
return 'sites'; | ||
} | ||
|
||
public function registerMetrics(PrometheusExporter $exporter): void | ||
{ | ||
$exporter->registerGauge( | ||
'municipality_city_total', | ||
'The total number of site municipalities and cities.', | ||
['region', 'province'] | ||
); | ||
|
||
$exporter->registerGauge( | ||
'province_total', | ||
'The total number of site provinces.', | ||
['region'] | ||
); | ||
|
||
$exporter->registerGauge( | ||
'region_total', | ||
'The total number of site regions.' | ||
); | ||
} | ||
|
||
public function collect(): void | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.