diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..2c6cc2dd --- /dev/null +++ b/.dockerignore @@ -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 diff --git a/.gitignore b/.gitignore index c5352436..f6700f61 100755 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ database.env .php-cs-fixer.cache .vscode influxdb.env +agent-linux-amd64 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..61d7325b --- /dev/null +++ b/Dockerfile @@ -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"] diff --git a/Procfile b/Procfile index 3d8471ba..9c20eab0 100644 --- a/Procfile +++ b/Procfile @@ -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 diff --git a/README.md b/README.md index 274ef9bd..c984df00 100755 --- a/README.md +++ b/README.md @@ -50,3 +50,13 @@ The exact PHP and MariaDB versions can be found in [XAMPP 8.1.6](https://www.apa - Open `anikultura-backend`, which is in Ubuntu again, using VS Code. - A more detailed article is available [here](https://laravel.com/docs/9.x/sail). - Done! + +## Metrics + +### Grafana Cloud Agent + +Send metrics via the agent. + +```bash +PROMETHEUS_PUSH_URL=http://localhost:9090/api/v1/write PROMETHEUS_TARGET_URL=localhost ./agent-linux-amd64 -config.file=agent-config.yml -config.expand-env +``` \ No newline at end of file diff --git a/agent-config.yml b/agent-config.yml new file mode 100644 index 00000000..0300b2af --- /dev/null +++ b/agent-config.yml @@ -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 diff --git a/app/Collectors/BatchCollector.php b/app/Collectors/BatchCollector.php new file mode 100644 index 00000000..5b440359 --- /dev/null +++ b/app/Collectors/BatchCollector.php @@ -0,0 +1,33 @@ +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 + { + } +} diff --git a/app/Collectors/CropCollector.php b/app/Collectors/CropCollector.php new file mode 100644 index 00000000..d49047e3 --- /dev/null +++ b/app/Collectors/CropCollector.php @@ -0,0 +1,33 @@ +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 + { + } +} diff --git a/app/Collectors/FarmerCollector.php b/app/Collectors/FarmerCollector.php new file mode 100644 index 00000000..0b2b6be1 --- /dev/null +++ b/app/Collectors/FarmerCollector.php @@ -0,0 +1,39 @@ +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 + { + } +} diff --git a/app/Collectors/FarmlandCollector.php b/app/Collectors/FarmlandCollector.php new file mode 100644 index 00000000..c8f345db --- /dev/null +++ b/app/Collectors/FarmlandCollector.php @@ -0,0 +1,33 @@ +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 + { + } +} diff --git a/app/Collectors/SiteCollector.php b/app/Collectors/SiteCollector.php new file mode 100644 index 00000000..55242a3f --- /dev/null +++ b/app/Collectors/SiteCollector.php @@ -0,0 +1,38 @@ +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 + { + } +} diff --git a/app/Helpers/InsightsHelper.php b/app/Helpers/InsightsHelper.php index 27b423ba..85a0c779 100644 --- a/app/Helpers/InsightsHelper.php +++ b/app/Helpers/InsightsHelper.php @@ -4,6 +4,16 @@ class InsightsHelper { + public static function incrementGauge(string $name, array $labels = [], float $increment = 1): void + { + app('prometheus')->getGauge($name)->incBy($increment, $labels); + } + + public static function decrementGauge(string $name, array $labels = [], float $decrement = 1): void + { + app('prometheus')->getGauge($name)->decBy($decrement, $labels); + } + public static function isInsightsEnabled(): bool { return config('influxdb.enabled'); diff --git a/app/Observers/Batch/BatchObserver.php b/app/Observers/Batch/BatchObserver.php index 7dd4c319..1d330c8a 100644 --- a/app/Observers/Batch/BatchObserver.php +++ b/app/Observers/Batch/BatchObserver.php @@ -2,39 +2,32 @@ namespace App\Observers\Batch; -use App\Actions\Insights\CreateCensusMetric; -use App\Actions\Insights\Farmer\CreateFarmerEnrollmentMetric; +use App\Helpers\InsightsHelper; use App\Models\Batch\Batch; -use App\Models\Farmer\Farmer; use App\Traits\AsInsightSender; +use Illuminate\Database\Eloquent\Model; class BatchObserver { use AsInsightSender; - private function sendInsights($model, bool $shouldIncrement) + private function sendInsights(Model $model, bool $shouldIncrement) { - CreateCensusMetric::dispatch( - [ - 'model' => [ - 'id' => $model->id, - 'class' => Batch::class, - ], - 'point' => [ - 'increment' => $shouldIncrement, - 'measurement' => 'census-batch', - 'tags' => [ - 'region' => 'id', - 'province' => 'id', - 'municity' => 'id', - ], - ], - ] - ); + $labels = [ + 'region' => $model->region->slug, + 'province' => $model->province->slug, + 'municity' => $model->municity->slug, + ]; + + if ($shouldIncrement) { + InsightsHelper::incrementGauge('batch_total', $labels); + } else { + InsightsHelper::decrementGauge('batch_total', $labels); + } } /** - * Farmer assigned to batch event. + * Handles the farmer assigned to batch event. */ public function belongsToManyAttached(string $relation, Batch $batch, array $farmerIds) { @@ -42,6 +35,30 @@ public function belongsToManyAttached(string $relation, Batch $batch, array $far return; } - CreateFarmerEnrollmentMetric::dispatch($batch, $farmerIds); + $farmerAssignedCount = count($farmerIds); + + InsightsHelper::incrementGauge('farmer_total', [ + 'region' => $batch->region->slug, + 'province' => $batch->province->slug, + 'municity' => $batch->municity->slug, + ], $farmerAssignedCount); + } + + /** + * Handles the farmer unassigned to batch event. + */ + public function belongsToManyDetached(string $relation, Batch $batch, array $farmerIds) + { + if ($relation != 'farmers') { + return; + } + + $farmerAssignedCount = count($farmerIds); + + InsightsHelper::decrementGauge('farmer_total', [ + 'region' => $batch->region->slug, + 'province' => $batch->province->slug, + 'municity' => $batch->municity->slug, + ], $farmerAssignedCount); } } diff --git a/app/Observers/Batch/BatchSeedAllocationObserver.php b/app/Observers/Batch/BatchSeedAllocationObserver.php index 6658a7b2..ea9a3495 100644 --- a/app/Observers/Batch/BatchSeedAllocationObserver.php +++ b/app/Observers/Batch/BatchSeedAllocationObserver.php @@ -2,38 +2,35 @@ namespace App\Observers\Batch; -use App\Actions\Insights\CreateCensusMetric; -use App\Models\Batch\BatchSeedAllocation; +use App\Helpers\InsightsHelper; use App\Traits\AsInsightSender; +use Illuminate\Database\Eloquent\Model; class BatchSeedAllocationObserver { use AsInsightSender; - private function sendInsights($model, bool $shouldIncrement) + private function sendInsights(Model $model, bool $shouldIncrement) { - CreateCensusMetric::dispatch( - [ - 'model' => [ - 'id' => $model->id, - 'class' => BatchSeedAllocation::class, - 'aggregation' => [ - 'type' => 'sum', - 'column' => 'seed_amount', - ], - ], - 'point' => [ - 'increment' => $shouldIncrement, - 'field' => 'seed-amount', - 'measurement' => 'census-seed-allocation', - 'tags' => [ - 'crop' => 'id', - 'batch.region' => 'id', - 'batch.province' => 'id', - 'batch.municity' => 'id', - ], - ], - ] - ); + $labels = [ + 'crop' => $model->crop->slug, + 'region' => $model->batch->region->slug, + 'province' => $model->batch->province->slug, + 'municity' => $model->batch->municity->slug, + ]; + + if ($shouldIncrement) { + InsightsHelper::incrementGauge( + 'batch_seed_allocation_total', + $labels, + $model->seed_amount + ); + } else { + InsightsHelper::decrementGauge( + 'batch_seed_allocation_total', + $labels, + $model->seed_amount + ); + } } } diff --git a/app/Observers/Crop/CropObserver.php b/app/Observers/Crop/CropObserver.php index 63478ece..8bd4cbfb 100644 --- a/app/Observers/Crop/CropObserver.php +++ b/app/Observers/Crop/CropObserver.php @@ -2,15 +2,35 @@ namespace App\Observers\Crop; -use App\Actions\Insights\Crop\CreateCropProfitMetric; +use App\Helpers\InsightsHelper; use App\Traits\AsInsightSender; +use Illuminate\Database\Eloquent\Model; class CropObserver { use AsInsightSender; - private function sendInsights($model, bool $shouldIncrement) + private function sendInsights(Model $model, bool $shouldIncrement) { - CreateCropProfitMetric::dispatch($model); + $profitPerKg = $model->profit_per_kg; + $netProfitCostRatio = $model->net_profit_cost_ratio; + + if ($shouldIncrement) { + InsightsHelper::incrementGauge('crop_profit_per_kg_pesos', [ + 'crop' => $model->slug, + ], $profitPerKg); + + InsightsHelper::incrementGauge('crop_net_profit_cost_ratio', [ + 'crop' => $model->slug, + ], $netProfitCostRatio); + } else { + InsightsHelper::decrementGauge('crop_profit_per_kg_pesos', [ + 'crop' => $model->slug, + ], $profitPerKg); + + InsightsHelper::decrementGauge('crop_net_profit_cost_ratio', [ + 'crop' => $model->slug, + ], $netProfitCostRatio); + } } } diff --git a/app/Observers/FarmerReport/FarmerReportObserver.php b/app/Observers/FarmerReport/FarmerReportObserver.php index f3ea3eb1..faa5cb52 100644 --- a/app/Observers/FarmerReport/FarmerReportObserver.php +++ b/app/Observers/FarmerReport/FarmerReportObserver.php @@ -2,44 +2,78 @@ namespace App\Observers\FarmerReport; -use App\Actions\Insights\CreateCensusMetric; -use App\Actions\Insights\Crop\CreateCropEstimationMetric; -use App\Models\FarmerReport\FarmerReport; +use App\Helpers\InsightsHelper; use App\Traits\AsInsightSender; +use Illuminate\Database\Eloquent\Model; class FarmerReportObserver { use AsInsightSender; - private function sendInsights($farmerReport, bool $shouldIncrement) + private function sendInsights(Model $model, bool $shouldIncrement) { - $this->dispatchCensusMetric($farmerReport, $shouldIncrement); + $this->createCensusMetric($model, $shouldIncrement); + $this->createEstimatedYieldMetric($model, $shouldIncrement); + } + + private function createCensusMetric(Model $model, bool $shouldIncrement): void + { + $labels = [ + 'crop' => $model->crop->slug, + 'seed_stage' => $model->seedStage->slug, + 'region' => $model->farmland->batch->region->slug, + 'province' => $model->farmland->batch->province->slug, + 'municity' => $model->farmland->batch->municity->slug, + ]; + + if ($shouldIncrement) { + InsightsHelper::incrementGauge('farmer_report_total', $labels); + } else { + InsightsHelper::decrementGauge('farmer_report_total', $labels); + } + } + + private function createEstimatedYieldMetric(Model $model, bool $shouldIncrement): void + { + if (! $model->isPlanted()) { + return; + } + + $estimatedYieldAmount = $this->convertKgToGrams($model->estimated_yield_amount); + $estimatedYieldDateLower = $model->estimated_yield_date_lower_bound; + $estimatedYieldDateUpper = $model->estimated_yield_date_upper_bound; + + $labels = [ + 'crop' => $model->crop->slug, + 'region' => $model->farmland->batch->region->slug, + 'province' => $model->farmland->batch->province->slug, + 'municity' => $model->farmland->batch->municity->slug, + 'yield_date_earliest' => $this->getEstimatedDateTag($estimatedYieldDateLower), + 'yield_date_latest' => $this->getEstimatedDateTag($estimatedYieldDateUpper), + ]; - if ($farmerReport->isPlanted()) { - CreateCropEstimationMetric::dispatch($farmerReport); + if ($shouldIncrement) { + InsightsHelper::incrementGauge( + 'farmer_report_estimated_yield_grams', + $labels, + $estimatedYieldAmount + ); + } else { + InsightsHelper::decrementGauge( + 'farmer_report_estimated_yield_grams', + $labels, + $estimatedYieldAmount + ); } } - private function dispatchCensusMetric($model, bool $shouldIncrement) + private function convertKgToGrams(float $kg): float + { + return $kg * 1000; + } + + private function getEstimatedDateTag(string $estimatedDate): string { - CreateCensusMetric::dispatch( - [ - 'model' => [ - 'id' => $model->id, - 'class' => FarmerReport::class, - ], - 'point' => [ - 'increment' => $shouldIncrement, - 'measurement' => 'census-farmer-report', - 'tags' => [ - 'crop' => 'id', - 'seed_stage' => 'id', - 'farmland.batch.region' => 'id', - 'farmland.batch.province' => 'id', - 'farmland.batch.municity' => 'id', - ], - ], - ] - ); + return date('m-Y', strtotime($estimatedDate)); } } diff --git a/app/Observers/Farmland/FarmlandObserver.php b/app/Observers/Farmland/FarmlandObserver.php index 782882fa..77839758 100644 --- a/app/Observers/Farmland/FarmlandObserver.php +++ b/app/Observers/Farmland/FarmlandObserver.php @@ -2,59 +2,32 @@ namespace App\Observers\Farmland; -use App\Actions\Insights\CreateCensusMetric; -use App\Models\Farmland\Farmland; +use App\Helpers\InsightsHelper; use App\Traits\AsInsightSender; +use Illuminate\Database\Eloquent\Model; class FarmlandObserver { use AsInsightSender; - private function sendInsights($model, bool $shouldIncrement) + private function sendInsights(Model $model, bool $shouldIncrement) { - CreateCensusMetric::dispatch( - [ - 'model' => [ - 'id' => $model->id, - 'class' => Farmland::class, - ], - 'point' => [ - 'increment' => $shouldIncrement, - 'measurement' => 'census-farmland', - 'tags' => [ - 'type' => 'id', - 'status' => 'id', - 'batch.region' => 'id', - 'batch.province' => 'id', - 'batch.municity' => 'id', - ], - ], - ] - ); + $labels = [ + 'type' => $model->type->slug, + 'status' => $model->status->slug, + 'region' => $model->batch->region->slug, + 'province' => $model->batch->province->slug, + 'municity' => $model->batch->municity->slug, + ]; - CreateCensusMetric::dispatch( - [ - 'model' => [ - 'id' => $model->id, - 'class' => Farmland::class, - 'aggregation' => [ - 'type' => 'sum', - 'column' => 'hectares_size', - ], - ], - 'point' => [ - 'increment' => $shouldIncrement, - 'field' => 'hectares-size', - 'measurement' => 'census-farmland', - 'tags' => [ - 'type' => 'id', - 'status' => 'id', - 'batch.region' => 'id', - 'batch.province' => 'id', - 'batch.municity' => 'id', - ], - ], - ] - ); + $hectares = $model->hectares_size; + + if ($shouldIncrement) { + InsightsHelper::incrementGauge('farmland_total', $labels); + InsightsHelper::incrementGauge('farmland_hectares', $labels, $hectares); + } else { + InsightsHelper::decrementGauge('farmland_total', $labels); + InsightsHelper::decrementGauge('farmland_hectares', $labels, $hectares); + } } } diff --git a/app/Observers/Site/MunicityObserver.php b/app/Observers/Site/MunicityObserver.php index 3af67127..aa3a4c04 100644 --- a/app/Observers/Site/MunicityObserver.php +++ b/app/Observers/Site/MunicityObserver.php @@ -2,8 +2,7 @@ namespace App\Observers\Site; -use App\Actions\Insights\CreateCensusMetric; -use App\Models\Site\Municity; +use App\Helpers\InsightsHelper; use App\Traits\AsInsightSender; class MunicityObserver @@ -12,21 +11,15 @@ class MunicityObserver private function sendInsights($model, bool $shouldIncrement) { - CreateCensusMetric::dispatch( - [ - 'model' => [ - 'id' => $model->id, - 'class' => Municity::class, - ], - 'point' => [ - 'increment' => $shouldIncrement, - 'measurement' => 'census-municipality-city', - 'tags' => [ - 'region' => 'id', - 'province' => 'id', - ], - ], - ] - ); + $labels = [ + 'region' => $model->region->slug, + 'province' => $model->province->slug, + ]; + + if ($shouldIncrement) { + InsightsHelper::incrementGauge('municipality_city_total', $labels); + } else { + InsightsHelper::decrementGauge('municipality_city_total', $labels); + } } } diff --git a/app/Observers/Site/ProvinceObserver.php b/app/Observers/Site/ProvinceObserver.php index d4739e6d..e7ce4b6b 100644 --- a/app/Observers/Site/ProvinceObserver.php +++ b/app/Observers/Site/ProvinceObserver.php @@ -2,30 +2,24 @@ namespace App\Observers\Site; -use App\Actions\Insights\CreateCensusMetric; -use App\Models\Site\Province; +use App\Helpers\InsightsHelper; use App\Traits\AsInsightSender; +use Illuminate\Database\Eloquent\Model; class ProvinceObserver { use AsInsightSender; - private function sendInsights($model, bool $shouldIncrement) + private function sendInsights(Model $model, bool $shouldIncrement) { - CreateCensusMetric::dispatch( - [ - 'model' => [ - 'id' => $model->id, - 'class' => Province::class, - ], - 'point' => [ - 'increment' => $shouldIncrement, - 'measurement' => 'census-province', - 'tags' => [ - 'region' => 'id', - ], - ], - ] - ); + $labels = [ + 'region' => $model->region->slug, + ]; + + if ($shouldIncrement) { + InsightsHelper::incrementGauge('province_total', $labels); + } else { + InsightsHelper::decrementGauge('province_total', $labels); + } } } diff --git a/app/Observers/Site/RegionObserver.php b/app/Observers/Site/RegionObserver.php index 3b977174..b39e22db 100644 --- a/app/Observers/Site/RegionObserver.php +++ b/app/Observers/Site/RegionObserver.php @@ -2,8 +2,7 @@ namespace App\Observers\Site; -use App\Actions\Insights\CreateCensusMetric; -use App\Models\Site\Region; +use App\Helpers\InsightsHelper; use App\Traits\AsInsightSender; class RegionObserver @@ -12,17 +11,10 @@ class RegionObserver private function sendInsights($model, bool $shouldIncrement) { - CreateCensusMetric::dispatch( - [ - 'model' => [ - 'id' => $model->id, - 'class' => Region::class, - ], - 'point' => [ - 'increment' => $shouldIncrement, - 'measurement' => 'census-region', - ], - ] - ); + if ($shouldIncrement) { + InsightsHelper::incrementGauge('region_total'); + } else { + InsightsHelper::decrementGauge('region_total'); + } } } diff --git a/app/Orchid/Screens/Batch/BatchSeedAllocationEditScreen.php b/app/Orchid/Screens/Batch/BatchSeedAllocationEditScreen.php index 67a9c6e0..2e0c7779 100644 --- a/app/Orchid/Screens/Batch/BatchSeedAllocationEditScreen.php +++ b/app/Orchid/Screens/Batch/BatchSeedAllocationEditScreen.php @@ -8,8 +8,11 @@ use App\Models\Batch\BatchSeedAllocation; use App\Orchid\Layouts\Batch\BatchSeedAllocationEditLayout; use Illuminate\Http\Request; +use Illuminate\Support\Arr; +use Illuminate\Support\Facades\Route; use Orchid\Screen\Actions\Button; use Orchid\Screen\Screen; +use Orchid\Support\Facades\Dashboard; use Orchid\Support\Facades\Layout; class BatchSeedAllocationEditScreen extends Screen @@ -22,6 +25,34 @@ public function __construct() $this->description = __('Create a new batch seed allocation'); } + public function handle(Request $request, ...$parameters) + { + Dashboard::setCurrentScreen($this); + + abort_unless($this->checkAccess($request), 403); + + if ($request->isMethod('GET')) { + return $this->redirectOnGetMethodCallOrShowView($parameters); + } + + $method = Route::current()->parameter('method', Arr::last($parameters)); + + $prepare = collect($parameters) + ->merge($request->query()) + ->diff($method) + ->all(); + + return $this->callMethod($method, $prepare) ?? back(); + } + + private function callMethod(string $method, array $parameters = []) + { + return call_user_func_array( + [$this, $method], + $this->resolveDependencies($method, $parameters) + ); + } + /** * Query data. * diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index cc570d1e..273b96f0 100755 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -30,7 +30,6 @@ class AppServiceProvider extends ServiceProvider */ public function register() { - // } /** diff --git a/app/Traits/AsInsightSender.php b/app/Traits/AsInsightSender.php index a3bff00a..9873d7e2 100644 --- a/app/Traits/AsInsightSender.php +++ b/app/Traits/AsInsightSender.php @@ -3,6 +3,7 @@ namespace App\Traits; use App\Helpers\InsightsHelper; +use Illuminate\Database\Eloquent\Model; trait AsInsightSender { @@ -24,5 +25,5 @@ public function saved($model) $this->sendInsights($model, true); } - abstract private function sendInsights($model, bool $shouldIncrement); + abstract private function sendInsights(Model $model, bool $shouldIncrement); } diff --git a/composer.json b/composer.json index 809797c7..23415ea3 100755 --- a/composer.json +++ b/composer.json @@ -10,6 +10,7 @@ "require": { "php": "^8.0.2", "ext-redis": "*", + "arquivei/laravel-prometheus-exporter": "^3.0", "chelout/laravel-relationship-events": "^1.5", "cloudinary-labs/cloudinary-laravel": "^1.0", "cviebrock/eloquent-sluggable": "^9.0", @@ -55,6 +56,9 @@ "post-root-package-install": [ "@php -r \"file_exists('.env') || copy('.env.example', '.env');\"" ], + "post-install-cmd": [ + "./setup-agent.sh" + ], "post-create-project-cmd": [ "@php artisan key:generate --ansi" ], @@ -83,4 +87,4 @@ }, "minimum-stability": "dev", "prefer-stable": true -} +} \ No newline at end of file diff --git a/composer.lock b/composer.lock index c4ca016d..72f767d2 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,62 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "893ad73330b31a625fe113e4f1dc7692", + "content-hash": "49cbda24ad2ff86be58f68dd8f03643f", "packages": [ + { + "name": "arquivei/laravel-prometheus-exporter", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/arquivei/laravel-prometheus-exporter.git", + "reference": "5ed64a48c4616086c5e7a6da3be89c08d09caa98" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/arquivei/laravel-prometheus-exporter/zipball/5ed64a48c4616086c5e7a6da3be89c08d09caa98", + "reference": "5ed64a48c4616086c5e7a6da3be89c08d09caa98", + "shasum": "" + }, + "require": { + "guzzlehttp/guzzle": "^7.4.2", + "illuminate/routing": "^9.0", + "illuminate/support": "^9.0", + "php": "^8.0 || ^8.1", + "promphp/prometheus_client_php": "^2.6.0" + }, + "require-dev": { + "mockery/mockery": "^1.5.0", + "orchestra/testbench": "^7.5.0", + "phpunit/phpunit": "^9.5.20" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "Arquivei\\LaravelPrometheusExporter\\": "src/", + "Arquivei\\LaravelPrometheusExporter\\Tests\\": "tests/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Arquivei" + } + ], + "description": "A Prometheus exporter for Laravel and Lumen", + "support": { + "issues": "https://github.com/arquivei/laravel-prometheus-exporter/issues", + "source": "https://github.com/arquivei/laravel-prometheus-exporter/tree/3.0.0" + }, + "time": "2022-05-19T21:50:13+00:00" + }, { "name": "asm89/stack-cors", "version": "v2.1.1", @@ -4275,6 +4329,73 @@ ], "time": "2022-07-30T15:51:26+00:00" }, + { + "name": "promphp/prometheus_client_php", + "version": "v2.6.2", + "source": { + "type": "git", + "url": "https://github.com/PromPHP/prometheus_client_php.git", + "reference": "df77bbcc65bd173f2ffaf40ab4e1ca8716da8ce6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PromPHP/prometheus_client_php/zipball/df77bbcc65bd173f2ffaf40ab4e1ca8716da8ce6", + "reference": "df77bbcc65bd173f2ffaf40ab4e1ca8716da8ce6", + "shasum": "" + }, + "require": { + "ext-json": "*", + "php": "^7.2|^8.0" + }, + "replace": { + "endclothing/prometheus_client_php": "*", + "jimdo/prometheus_client_php": "*", + "lkaemmerling/prometheus_client_php": "*" + }, + "require-dev": { + "guzzlehttp/guzzle": "^6.3|^7.0", + "phpstan/extension-installer": "^1.0", + "phpstan/phpstan": "^1.5.4", + "phpstan/phpstan-phpunit": "^1.1.0", + "phpstan/phpstan-strict-rules": "^1.1.0", + "phpunit/phpunit": "^9.4", + "squizlabs/php_codesniffer": "^3.6", + "symfony/polyfill-apcu": "^1.6" + }, + "suggest": { + "ext-apc": "Required if using APCu.", + "ext-redis": "Required if using Redis.", + "promphp/prometheus_push_gateway_php": "An easy client for using Prometheus PushGateway.", + "symfony/polyfill-apcu": "Required if you use APCu on PHP8.0+" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "Prometheus\\": "src/Prometheus/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Lukas Kämmerling", + "email": "kontakt@lukas-kaemmerling.de" + } + ], + "description": "Prometheus instrumentation library for PHP applications.", + "support": { + "issues": "https://github.com/PromPHP/prometheus_client_php/issues", + "source": "https://github.com/PromPHP/prometheus_client_php/tree/v2.6.2" + }, + "time": "2022-06-30T03:46:23+00:00" + }, { "name": "psr/cache", "version": "3.0.0", diff --git a/config/app.php b/config/app.php index b52b3d52..d04edb69 100755 --- a/config/app.php +++ b/config/app.php @@ -175,6 +175,7 @@ App\Providers\EventServiceProvider::class, App\Providers\RouteServiceProvider::class, PHPOpenSourceSaver\JWTAuth\Providers\LaravelServiceProvider::class, + Arquivei\LaravelPrometheusExporter\PrometheusServiceProvider::class, ], /* diff --git a/config/prometheus.php b/config/prometheus.php new file mode 100644 index 00000000..6fd0c8be --- /dev/null +++ b/config/prometheus.php @@ -0,0 +1,121 @@ + env('PROMETHEUS_NAMESPACE', 'app'), + + /* + |-------------------------------------------------------------------------- + | Metrics Route Enabled? + |-------------------------------------------------------------------------- + | + | If enabled, a /metrics route will be registered to export prometheus + | metrics. + | + */ + + 'metrics_route_enabled' => env('PROMETHEUS_METRICS_ROUTE_ENABLED', true), + + /* + |-------------------------------------------------------------------------- + | Metrics Route Path + |-------------------------------------------------------------------------- + | + | The path at which prometheus metrics are exported. + | + | This is only applicable if metrics_route_enabled is set to true. + | + */ + + 'metrics_route_path' => env('PROMETHEUS_METRICS_ROUTE_PATH', 'metrics'), + + /* + |-------------------------------------------------------------------------- + | Storage Adapter + |-------------------------------------------------------------------------- + | + | The storage adapter to use. + | + | Supported: "memory", "redis", "apc" + | + */ + + 'storage_adapter' => env('PROMETHEUS_STORAGE_ADAPTER', 'memory'), + + /* + |-------------------------------------------------------------------------- + | Storage Adapters + |-------------------------------------------------------------------------- + | + | The storage adapter configs. + | + */ + + 'storage_adapters' => [ + + 'redis' => [ + 'host' => env('PROMETHEUS_REDIS_HOST', 'localhost'), + 'port' => env('PROMETHEUS_REDIS_PORT', 6379), + 'database' => env('PROMETHEUS_REDIS_DATABASE', 0), + 'timeout' => env('PROMETHEUS_REDIS_TIMEOUT', 0.1), + 'read_timeout' => env('PROMETHEUS_REDIS_READ_TIMEOUT', 10), + 'persistent_connections' => env('PROMETHEUS_REDIS_PERSISTENT_CONNECTIONS', false), + 'prefix' => env('PROMETHEUS_REDIS_PREFIX', 'PROMETHEUS_'), + 'prefix_dynamic' => env('PROMETHEUS_REDIS_PREFIX_DYNAMIC', true), + ], + + ], + + /* + |-------------------------------------------------------------------------- + | Collect full SQL query + |-------------------------------------------------------------------------- + | + | Indicates whether we should collect the full SQL query or not. + | + */ + + 'collect_full_sql_query' => env('PROMETHEUS_COLLECT_FULL_SQL_QUERY', true), + + /* + |-------------------------------------------------------------------------- + | Collectors + |-------------------------------------------------------------------------- + | + | The collectors specified here will be auto-registered in the exporter. + | + */ + + 'collectors' => [ + App\Collectors\BatchCollector::class, + App\Collectors\CropCollector::class, + App\Collectors\FarmerCollector::class, + App\Collectors\FarmlandCollector::class, + App\Collectors\SiteCollector::class, + ], + + /* + |-------------------------------------------------------------------------- + | Buckets config + |-------------------------------------------------------------------------- + | + | The buckets config specified here will be passed to the histogram generator + | in the prometheus client. You can configure it as an array of time bounds. + | Default value is null. + | + */ + + 'routes_buckets' => null, + 'sql_buckets' => null, + 'guzzle_buckets' => null, +]; diff --git a/docker-compose.yml b/docker-compose.yml index 409a8b1e..5cd3e010 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -63,6 +63,21 @@ services: - redis-data:/data networks: - sail + prometheus: + image: prom/prometheus:v2.38.0 + command: + - "--config.file=/etc/prometheus/prometheus.yml" + - "--storage.tsdb.path=/prometheus" + - "--web.console.libraries=/usr/share/prometheus/console_libraries" + - "--web.console.templates=/usr/share/prometheus/consoles" + - "--web.enable-remote-write-receiver" + ports: + - "9090:9090" + volumes: + - ./prometheus-config.yml:/etc/prometheus/prometheus.yml + - prometheus-data:/prometheus + networks: + - sail networks: sail: driver: bridge @@ -71,3 +86,4 @@ volumes: influxdb-data: grafana-data: redis-data: + prometheus-data: diff --git a/grafana/batches-dashboard.json b/grafana/batches-dashboard.json new file mode 100644 index 00000000..a201020e --- /dev/null +++ b/grafana/batches-dashboard.json @@ -0,0 +1,674 @@ +{ + "__inputs": [ + { + "name": "DS_PROMETHEUS", + "label": "Prometheus", + "description": "", + "type": "datasource", + "pluginId": "prometheus", + "pluginName": "Prometheus" + } + ], + "__elements": {}, + "__requires": [ + { + "type": "grafana", + "id": "grafana", + "name": "Grafana", + "version": "9.1.0" + }, + { + "type": "datasource", + "id": "prometheus", + "name": "Prometheus", + "version": "1.0.0" + }, + { + "type": "panel", + "id": "stat", + "name": "Stat", + "version": "" + }, + { + "type": "panel", + "id": "timeseries", + "name": "Time series", + "version": "" + } + ], + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": { + "type": "grafana", + "uid": "-- Grafana --" + }, + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "target": { + "limit": 100, + "matchAny": false, + "tags": [], + "type": "dashboard" + }, + "type": "dashboard" + } + ] + }, + "editable": true, + "fiscalYearStartMonth": 0, + "graphTooltip": 0, + "id": null, + "links": [], + "liveNow": false, + "panels": [ + { + "collapsed": false, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 8 + }, + "id": 11, + "panels": [], + "title": "Summary", + "type": "row" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 7, + "w": 8, + "x": 0, + "y": 9 + }, + "id": 3, + "options": { + "colorMode": "background", + "graphMode": "none", + "justifyMode": "center", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "9.1.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "builder", + "exemplar": false, + "expr": "sum by(region) (app_batch_total{region=~\"$region\"})", + "instant": false, + "legendFormat": "__auto", + "range": true, + "refId": "A" + } + ], + "title": "No. of batches per region", + "transparent": true, + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "description": "", + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 7, + "w": 8, + "x": 8, + "y": 9 + }, + "id": 4, + "options": { + "colorMode": "background", + "graphMode": "none", + "justifyMode": "center", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "9.1.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "builder", + "exemplar": false, + "expr": "sum by(region, province) (app_batch_total{region=~\"$region\", province=~\"$province\"})", + "instant": false, + "legendFormat": "{{region}}, {{province}}", + "range": true, + "refId": "A" + } + ], + "title": "No. of batches per province", + "transparent": true, + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 7, + "w": 8, + "x": 16, + "y": 9 + }, + "id": 6, + "options": { + "colorMode": "background", + "graphMode": "none", + "justifyMode": "center", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "9.1.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "builder", + "exemplar": false, + "expr": "sum by(region, province, municity) (app_batch_total{region=~\"$region\", province=~\"$province\", municity=~\"$municity\"})", + "instant": false, + "legendFormat": "{{municity}}", + "range": true, + "refId": "A" + } + ], + "title": "No. of batches per municipality or city", + "transparent": true, + "type": "stat" + }, + { + "collapsed": false, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 16 + }, + "id": 9, + "panels": [], + "title": "Trend", + "type": "row" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 14, + "gradientMode": "opacity", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineStyle": { + "fill": "solid" + }, + "lineWidth": 2, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 7, + "w": 8, + "x": 0, + "y": 17 + }, + "id": 2, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "builder", + "exemplar": false, + "expr": "sum by(region) (app_batch_total{region=~\"$region\"})", + "instant": false, + "legendFormat": "__auto", + "range": true, + "refId": "A" + } + ], + "title": "No. of batches per region", + "transparent": true, + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 14, + "gradientMode": "opacity", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 2, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "none" + }, + "overrides": [] + }, + "gridPos": { + "h": 7, + "w": 8, + "x": 8, + "y": 17 + }, + "id": 5, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "builder", + "exemplar": false, + "expr": "sum by(region, province) (app_batch_total{region=~\"$region\", province=~\"$province\"})", + "instant": false, + "legendFormat": "{{region}}, {{province}}", + "range": true, + "refId": "A" + } + ], + "title": "No. of batches per province", + "transparent": true, + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 14, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 2, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 7, + "w": 8, + "x": 16, + "y": 17 + }, + "id": 7, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "9.1.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "builder", + "exemplar": false, + "expr": "sum by(region, province, municity) (app_batch_total{region=~\"$region\", province=~\"$province\", municity=~\"$municity\"})", + "instant": false, + "legendFormat": "{{municity}}", + "range": true, + "refId": "A" + } + ], + "title": "No. of batches per municipality or city", + "transparent": true, + "type": "timeseries" + } + ], + "schemaVersion": 37, + "style": "dark", + "tags": [], + "templating": { + "list": [ + { + "current": {}, + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "definition": "label_values(app_batch_total, region)", + "hide": 0, + "includeAll": false, + "multi": true, + "name": "region", + "options": [], + "query": { + "query": "label_values(app_batch_total, region)", + "refId": "StandardVariableQuery" + }, + "refresh": 2, + "regex": "", + "skipUrlSync": false, + "sort": 0, + "type": "query" + }, + { + "current": {}, + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "definition": "label_values(app_batch_total{region=~\"$region\"}, province)", + "hide": 0, + "includeAll": false, + "multi": true, + "name": "province", + "options": [], + "query": { + "query": "label_values(app_batch_total{region=~\"$region\"}, province)", + "refId": "StandardVariableQuery" + }, + "refresh": 2, + "regex": "", + "skipUrlSync": false, + "sort": 0, + "type": "query" + }, + { + "current": {}, + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "definition": "label_values(app_batch_total{region=~\"$region\", province=~\"$province\"}, municity)", + "hide": 0, + "includeAll": false, + "label": "municipality-city", + "multi": true, + "name": "municity", + "options": [], + "query": { + "query": "label_values(app_batch_total{region=~\"$region\", province=~\"$province\"}, municity)", + "refId": "StandardVariableQuery" + }, + "refresh": 2, + "regex": "", + "skipUrlSync": false, + "sort": 0, + "type": "query" + } + ] + }, + "time": { + "from": "now-15m", + "to": "now" + }, + "timepicker": {}, + "timezone": "", + "title": "Batch Insights", + "uid": "oRNVAEMVk", + "version": 4, + "weekStart": "" +} \ No newline at end of file diff --git a/grafana/crops-profit-dashboard.json b/grafana/crops-profit-dashboard.json new file mode 100644 index 00000000..73fc3b8e --- /dev/null +++ b/grafana/crops-profit-dashboard.json @@ -0,0 +1,473 @@ +{ + "__inputs": [ + { + "name": "DS_PROMETHEUS", + "label": "Prometheus", + "description": "", + "type": "datasource", + "pluginId": "prometheus", + "pluginName": "Prometheus" + } + ], + "__elements": {}, + "__requires": [ + { + "type": "grafana", + "id": "grafana", + "name": "Grafana", + "version": "9.1.0" + }, + { + "type": "datasource", + "id": "prometheus", + "name": "Prometheus", + "version": "1.0.0" + }, + { + "type": "panel", + "id": "stat", + "name": "Stat", + "version": "" + }, + { + "type": "panel", + "id": "timeseries", + "name": "Time series", + "version": "" + } + ], + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": { + "type": "grafana", + "uid": "-- Grafana --" + }, + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "target": { + "limit": 100, + "matchAny": false, + "tags": [], + "type": "dashboard" + }, + "type": "dashboard" + } + ] + }, + "editable": true, + "fiscalYearStartMonth": 0, + "graphTooltip": 0, + "id": null, + "links": [], + "liveNow": false, + "panels": [ + { + "collapsed": false, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 0 + }, + "id": 11, + "panels": [], + "title": "Summary", + "type": "row" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "decimals": 2, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "currencyPHP" + }, + "overrides": [] + }, + "gridPos": { + "h": 7, + "w": 8, + "x": 0, + "y": 1 + }, + "id": 3, + "options": { + "colorMode": "background", + "graphMode": "none", + "justifyMode": "center", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "textMode": "value_and_name" + }, + "pluginVersion": "9.1.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "builder", + "exemplar": false, + "expr": "sum by(crop) (app_crop_profit_per_kg_pesos{crop=~\"$crop\"})", + "instant": false, + "legendFormat": "{{crop}}", + "range": true, + "refId": "A" + } + ], + "title": "Profit per kilogram of crop", + "transparent": true, + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "description": "", + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "decimals": 2, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "percentunit" + }, + "overrides": [] + }, + "gridPos": { + "h": 7, + "w": 8, + "x": 8, + "y": 1 + }, + "id": 4, + "options": { + "colorMode": "background", + "graphMode": "none", + "justifyMode": "center", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "textMode": "value_and_name" + }, + "pluginVersion": "9.1.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "builder", + "exemplar": false, + "expr": "sum by(crop) (app_crop_net_profit_cost_ratio{crop=~\"$crop\"})", + "instant": false, + "legendFormat": "{{crop}}", + "range": true, + "refId": "A" + } + ], + "title": "Net-profit cost ratio of crop", + "transparent": true, + "type": "stat" + }, + { + "collapsed": false, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 8 + }, + "id": 9, + "panels": [], + "title": "Trend", + "type": "row" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 14, + "gradientMode": "opacity", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineStyle": { + "fill": "solid" + }, + "lineWidth": 2, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "decimals": 2, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "currencyPHP" + }, + "overrides": [] + }, + "gridPos": { + "h": 7, + "w": 8, + "x": 0, + "y": 9 + }, + "id": 2, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "builder", + "exemplar": false, + "expr": "sum by(crop) (app_crop_profit_per_kg_pesos{crop=~\"$crop\"})", + "instant": false, + "legendFormat": "{{crop}}", + "range": true, + "refId": "A" + } + ], + "title": "Profit per kilogram of crop", + "transparent": true, + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu", + "seriesBy": "last" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 14, + "gradientMode": "opacity", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 2, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "decimals": 2, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "percentunit" + }, + "overrides": [] + }, + "gridPos": { + "h": 7, + "w": 8, + "x": 8, + "y": 9 + }, + "id": 5, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "builder", + "exemplar": false, + "expr": "sum by(crop) (app_crop_net_profit_cost_ratio{crop=~\"$crop\"})", + "instant": false, + "legendFormat": "{{crop}}", + "range": true, + "refId": "A" + } + ], + "title": "Net-profit cost ratio of crop", + "transparent": true, + "type": "timeseries" + } + ], + "schemaVersion": 37, + "style": "dark", + "tags": [], + "templating": { + "list": [ + { + "current": {}, + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "definition": "label_values(app_crop_profit_per_kg_pesos, crop)", + "hide": 0, + "includeAll": false, + "multi": true, + "name": "crop", + "options": [], + "query": { + "query": "label_values(app_crop_profit_per_kg_pesos, crop)", + "refId": "StandardVariableQuery" + }, + "refresh": 2, + "regex": "", + "skipUrlSync": false, + "sort": 0, + "type": "query" + } + ] + }, + "time": { + "from": "now-15m", + "to": "now" + }, + "timepicker": {}, + "timezone": "", + "title": "Crop Profitability Insights", + "uid": "Ofdv08M4z", + "version": 8, + "weekStart": "" +} \ No newline at end of file diff --git a/grafana/farmer-reports-dashboard.json b/grafana/farmer-reports-dashboard.json new file mode 100644 index 00000000..b16bbf1e --- /dev/null +++ b/grafana/farmer-reports-dashboard.json @@ -0,0 +1,701 @@ +{ + "__inputs": [ + { + "name": "DS_PROMETHEUS", + "label": "Prometheus", + "description": "", + "type": "datasource", + "pluginId": "prometheus", + "pluginName": "Prometheus" + } + ], + "__elements": {}, + "__requires": [ + { + "type": "grafana", + "id": "grafana", + "name": "Grafana", + "version": "9.1.0" + }, + { + "type": "datasource", + "id": "prometheus", + "name": "Prometheus", + "version": "1.0.0" + }, + { + "type": "panel", + "id": "stat", + "name": "Stat", + "version": "" + }, + { + "type": "panel", + "id": "timeseries", + "name": "Time series", + "version": "" + } + ], + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": { + "type": "grafana", + "uid": "-- Grafana --" + }, + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "target": { + "limit": 100, + "matchAny": false, + "tags": [], + "type": "dashboard" + }, + "type": "dashboard" + } + ] + }, + "editable": true, + "fiscalYearStartMonth": 0, + "graphTooltip": 0, + "id": null, + "links": [], + "liveNow": false, + "panels": [ + { + "collapsed": false, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 0 + }, + "id": 11, + "panels": [], + "title": "Summary", + "type": "row" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "masskg" + }, + "overrides": [] + }, + "gridPos": { + "h": 7, + "w": 8, + "x": 0, + "y": 1 + }, + "id": 3, + "options": { + "colorMode": "background", + "graphMode": "none", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "textMode": "value_and_name" + }, + "pluginVersion": "9.1.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "builder", + "exemplar": false, + "expr": "sum by(region, crop, yield_date_earliest, yield_date_latest) (app_farmer_report_estimated_yield_grams{region=~\"$region\", crop=~\"$crop\"}) / 1000", + "instant": false, + "legendFormat": "{{region}} - {{crop}} ({{yield_date_earliest}} to {{yield_date_latest}})", + "range": true, + "refId": "A" + } + ], + "title": "Estimated kilogram yield per region", + "transparent": true, + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "description": "", + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "masskg" + }, + "overrides": [] + }, + "gridPos": { + "h": 7, + "w": 8, + "x": 8, + "y": 1 + }, + "id": 4, + "options": { + "colorMode": "background", + "graphMode": "none", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "textMode": "value_and_name" + }, + "pluginVersion": "9.1.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "builder", + "exemplar": false, + "expr": "sum by(region, province, crop, yield_date_earliest, yield_date_latest) (app_farmer_report_estimated_yield_grams{region=~\"$region\", province=~\"$province\", crop=~\"$crop\"}) / 1000", + "instant": false, + "legendFormat": "{{province}} - {{crop}} ({{yield_date_earliest}} to {{yield_date_latest}})", + "range": true, + "refId": "A" + } + ], + "title": "Estimated kilogram yield per province", + "transparent": true, + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "masskg" + }, + "overrides": [] + }, + "gridPos": { + "h": 7, + "w": 8, + "x": 16, + "y": 1 + }, + "id": 6, + "options": { + "colorMode": "background", + "graphMode": "none", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "textMode": "value_and_name" + }, + "pluginVersion": "9.1.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "builder", + "exemplar": false, + "expr": "sum by(region, province, municity, crop, yield_date_earliest, yield_date_latest) (app_farmer_report_estimated_yield_grams{region=~\"$region\", province=~\"$province\", municity=~\"$municity\", crop=~\"$crop\"}) / 1000", + "instant": false, + "legendFormat": "{{municity}} - {{crop}} ({{yield_date_earliest}} to {{yield_date_latest}})", + "range": true, + "refId": "A" + } + ], + "title": "Estimated kilogram yield per municipality or city", + "transparent": true, + "type": "stat" + }, + { + "collapsed": false, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 8 + }, + "id": 9, + "panels": [], + "title": "Trend", + "type": "row" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 14, + "gradientMode": "opacity", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineStyle": { + "fill": "solid" + }, + "lineWidth": 2, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "masskg" + }, + "overrides": [] + }, + "gridPos": { + "h": 7, + "w": 8, + "x": 0, + "y": 9 + }, + "id": 2, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "builder", + "exemplar": false, + "expr": "sum by(region, crop, yield_date_earliest, yield_date_latest) (app_farmer_report_estimated_yield_grams{region=~\"$region\", crop=~\"$crop\"}) / 1000", + "instant": false, + "legendFormat": "{{region}} - {{crop}} ({{yield_date_earliest}} to {{yield_date_latest}})", + "range": true, + "refId": "A" + } + ], + "title": "Estimated kilogram yield per region", + "transparent": true, + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 14, + "gradientMode": "opacity", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 2, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "masskg" + }, + "overrides": [] + }, + "gridPos": { + "h": 7, + "w": 8, + "x": 8, + "y": 9 + }, + "id": 5, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "builder", + "exemplar": false, + "expr": "sum by(region, province, crop, yield_date_earliest, yield_date_latest) (app_farmer_report_estimated_yield_grams{region=~\"$region\", province=~\"$province\", crop=~\"$crop\"}) / 1000", + "instant": false, + "legendFormat": "{{province}} - {{crop}} ({{yield_date_earliest}} to {{yield_date_latest}})", + "range": true, + "refId": "A" + } + ], + "title": "Estimated kilogram yield per province", + "transparent": true, + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 14, + "gradientMode": "opacity", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 2, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "masskg" + }, + "overrides": [] + }, + "gridPos": { + "h": 7, + "w": 8, + "x": 16, + "y": 9 + }, + "id": 7, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "9.1.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "builder", + "exemplar": false, + "expr": "sum by(region, province, municity, crop, yield_date_earliest, yield_date_latest) (app_farmer_report_estimated_yield_grams{region=~\"$region\", province=~\"$province\", municity=~\"$municity\", crop=~\"$crop\"}) / 1000", + "instant": false, + "legendFormat": "{{municity}} - {{crop}} ({{yield_date_earliest}} to {{yield_date_latest}})", + "range": true, + "refId": "A" + } + ], + "title": "Estimated kilogram yield per municipality or city", + "transparent": true, + "type": "timeseries" + } + ], + "schemaVersion": 37, + "style": "dark", + "tags": [], + "templating": { + "list": [ + { + "current": {}, + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "definition": "label_values(app_farmer_report_estimated_yield_grams, region)", + "hide": 0, + "includeAll": false, + "multi": true, + "name": "region", + "options": [], + "query": { + "query": "label_values(app_farmer_report_estimated_yield_grams, region)", + "refId": "StandardVariableQuery" + }, + "refresh": 2, + "regex": "", + "skipUrlSync": false, + "sort": 0, + "type": "query" + }, + { + "current": {}, + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "definition": "label_values(app_farmer_report_estimated_yield_grams{region=~\"$region\"}, province)", + "hide": 0, + "includeAll": false, + "multi": true, + "name": "province", + "options": [], + "query": { + "query": "label_values(app_farmer_report_estimated_yield_grams{region=~\"$region\"}, province)", + "refId": "StandardVariableQuery" + }, + "refresh": 2, + "regex": "", + "skipUrlSync": false, + "sort": 0, + "type": "query" + }, + { + "current": {}, + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "definition": "label_values(app_farmer_report_estimated_yield_grams{region=~\"$region\", province=~\"$province\"}, municity)", + "hide": 0, + "includeAll": false, + "label": "municipality-city", + "multi": true, + "name": "municity", + "options": [], + "query": { + "query": "label_values(app_farmer_report_estimated_yield_grams{region=~\"$region\", province=~\"$province\"}, municity)", + "refId": "StandardVariableQuery" + }, + "refresh": 2, + "regex": "", + "skipUrlSync": false, + "sort": 0, + "type": "query" + }, + { + "current": {}, + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "definition": "label_values(app_farmer_report_estimated_yield_grams, crop)", + "hide": 0, + "includeAll": false, + "multi": true, + "name": "crop", + "options": [], + "query": { + "query": "label_values(app_farmer_report_estimated_yield_grams, crop)", + "refId": "StandardVariableQuery" + }, + "refresh": 2, + "regex": "", + "skipUrlSync": false, + "sort": 0, + "type": "query" + } + ] + }, + "time": { + "from": "now-15m", + "to": "now" + }, + "timepicker": {}, + "timezone": "", + "title": "Farmer Report Insights", + "uid": "zdMXyuM4z", + "version": 13, + "weekStart": "" +} \ No newline at end of file diff --git a/grafana/farmers-dashboard.json b/grafana/farmers-dashboard.json new file mode 100644 index 00000000..0be00858 --- /dev/null +++ b/grafana/farmers-dashboard.json @@ -0,0 +1,674 @@ +{ + "__inputs": [ + { + "name": "DS_PROMETHEUS", + "label": "Prometheus", + "description": "", + "type": "datasource", + "pluginId": "prometheus", + "pluginName": "Prometheus" + } + ], + "__elements": {}, + "__requires": [ + { + "type": "grafana", + "id": "grafana", + "name": "Grafana", + "version": "9.1.0" + }, + { + "type": "datasource", + "id": "prometheus", + "name": "Prometheus", + "version": "1.0.0" + }, + { + "type": "panel", + "id": "stat", + "name": "Stat", + "version": "" + }, + { + "type": "panel", + "id": "timeseries", + "name": "Time series", + "version": "" + } + ], + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": { + "type": "grafana", + "uid": "-- Grafana --" + }, + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "target": { + "limit": 100, + "matchAny": false, + "tags": [], + "type": "dashboard" + }, + "type": "dashboard" + } + ] + }, + "editable": true, + "fiscalYearStartMonth": 0, + "graphTooltip": 0, + "id": null, + "links": [], + "liveNow": false, + "panels": [ + { + "collapsed": false, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 0 + }, + "id": 11, + "panels": [], + "title": "Summary", + "type": "row" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 7, + "w": 8, + "x": 0, + "y": 1 + }, + "id": 3, + "options": { + "colorMode": "background", + "graphMode": "none", + "justifyMode": "center", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "9.1.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "builder", + "exemplar": false, + "expr": "sum by(region) (app_farmer_total{region=~\"$region\"})", + "instant": false, + "legendFormat": "__auto", + "range": true, + "refId": "A" + } + ], + "title": "No. of farmers per region", + "transparent": true, + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "description": "", + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 7, + "w": 8, + "x": 8, + "y": 1 + }, + "id": 4, + "options": { + "colorMode": "background", + "graphMode": "none", + "justifyMode": "center", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "9.1.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "builder", + "exemplar": false, + "expr": "sum by(region, province) (app_farmer_total{region=~\"$region\", province=~\"$province\"})", + "instant": false, + "legendFormat": "{{region}}, {{province}}", + "range": true, + "refId": "A" + } + ], + "title": "No. of farmers per province", + "transparent": true, + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 7, + "w": 8, + "x": 16, + "y": 1 + }, + "id": 6, + "options": { + "colorMode": "background", + "graphMode": "none", + "justifyMode": "center", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "9.1.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "builder", + "exemplar": false, + "expr": "sum by(region, province, municity) (app_farmer_total{region=~\"$region\", province=~\"$province\", municity=~\"$municity\"})", + "instant": false, + "legendFormat": "{{municity}}", + "range": true, + "refId": "A" + } + ], + "title": "No. of farmers per municipality or city", + "transparent": true, + "type": "stat" + }, + { + "collapsed": false, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 8 + }, + "id": 9, + "panels": [], + "title": "Trend", + "type": "row" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 14, + "gradientMode": "opacity", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineStyle": { + "fill": "solid" + }, + "lineWidth": 2, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 7, + "w": 8, + "x": 0, + "y": 9 + }, + "id": 2, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "builder", + "exemplar": false, + "expr": "sum by(region) (app_farmer_total{region=~\"$region\"})", + "instant": false, + "legendFormat": "__auto", + "range": true, + "refId": "A" + } + ], + "title": "No. of farmers per region", + "transparent": true, + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 14, + "gradientMode": "opacity", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 2, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "none" + }, + "overrides": [] + }, + "gridPos": { + "h": 7, + "w": 8, + "x": 8, + "y": 9 + }, + "id": 5, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "builder", + "exemplar": false, + "expr": "sum by(region, province) (app_farmer_total{region=~\"$region\", province=~\"$province\"})", + "instant": false, + "legendFormat": "{{region}}, {{province}}", + "range": true, + "refId": "A" + } + ], + "title": "No. of farmers per province", + "transparent": true, + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 14, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 2, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 7, + "w": 8, + "x": 16, + "y": 9 + }, + "id": 7, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "9.1.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "builder", + "exemplar": false, + "expr": "sum by(region, province, municity) (app_farmer_total{region=~\"$region\", province=~\"$province\", municity=~\"$municity\"})", + "instant": false, + "legendFormat": "{{municity}}", + "range": true, + "refId": "A" + } + ], + "title": "No. of farmers per municipality or city", + "transparent": true, + "type": "timeseries" + } + ], + "schemaVersion": 37, + "style": "dark", + "tags": [], + "templating": { + "list": [ + { + "current": {}, + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "definition": "label_values(app_farmer_total, region)", + "hide": 0, + "includeAll": false, + "multi": true, + "name": "region", + "options": [], + "query": { + "query": "label_values(app_farmer_total, region)", + "refId": "StandardVariableQuery" + }, + "refresh": 2, + "regex": "", + "skipUrlSync": false, + "sort": 0, + "type": "query" + }, + { + "current": {}, + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "definition": "label_values(app_farmer_total{region=~\"$region\"}, province)", + "hide": 0, + "includeAll": false, + "multi": true, + "name": "province", + "options": [], + "query": { + "query": "label_values(app_farmer_total{region=~\"$region\"}, province)", + "refId": "StandardVariableQuery" + }, + "refresh": 2, + "regex": "", + "skipUrlSync": false, + "sort": 0, + "type": "query" + }, + { + "current": {}, + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "definition": "label_values(app_farmer_total{region=~\"$region\", province=~\"$province\"}, municity)", + "hide": 0, + "includeAll": false, + "label": "municipality-city", + "multi": true, + "name": "municity", + "options": [], + "query": { + "query": "label_values(app_farmer_total{region=~\"$region\", province=~\"$province\"}, municity)", + "refId": "StandardVariableQuery" + }, + "refresh": 2, + "regex": "", + "skipUrlSync": false, + "sort": 0, + "type": "query" + } + ] + }, + "time": { + "from": "now-15m", + "to": "now" + }, + "timepicker": {}, + "timezone": "", + "title": "Farmer Enrollment Insights", + "uid": "JHp2mEGVz", + "version": 22, + "weekStart": "" +} \ No newline at end of file diff --git a/grafana/farmlands-dashboard.json b/grafana/farmlands-dashboard.json new file mode 100644 index 00000000..499a4339 --- /dev/null +++ b/grafana/farmlands-dashboard.json @@ -0,0 +1,1173 @@ +{ + "__inputs": [ + { + "name": "DS_PROMETHEUS", + "label": "Prometheus", + "description": "", + "type": "datasource", + "pluginId": "prometheus", + "pluginName": "Prometheus" + } + ], + "__elements": {}, + "__requires": [ + { + "type": "grafana", + "id": "grafana", + "name": "Grafana", + "version": "9.1.0" + }, + { + "type": "datasource", + "id": "prometheus", + "name": "Prometheus", + "version": "1.0.0" + }, + { + "type": "panel", + "id": "stat", + "name": "Stat", + "version": "" + }, + { + "type": "panel", + "id": "timeseries", + "name": "Time series", + "version": "" + } + ], + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": { + "type": "grafana", + "uid": "-- Grafana --" + }, + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "target": { + "limit": 100, + "matchAny": false, + "tags": [], + "type": "dashboard" + }, + "type": "dashboard" + } + ] + }, + "editable": true, + "fiscalYearStartMonth": 0, + "graphTooltip": 0, + "id": null, + "links": [], + "liveNow": false, + "panels": [ + { + "collapsed": false, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 0 + }, + "id": 11, + "panels": [], + "title": "Summary", + "type": "row" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 5, + "w": 8, + "x": 0, + "y": 1 + }, + "id": 3, + "options": { + "colorMode": "background", + "graphMode": "none", + "justifyMode": "center", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "9.1.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "builder", + "exemplar": false, + "expr": "sum by(region) (app_farmland_total{region=~\"$region\"})", + "instant": false, + "legendFormat": "__auto", + "range": true, + "refId": "A" + } + ], + "title": "No. of farmlands per province", + "transparent": true, + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "description": "", + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 5, + "w": 8, + "x": 8, + "y": 1 + }, + "id": 4, + "options": { + "colorMode": "background", + "graphMode": "none", + "justifyMode": "center", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "9.1.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "builder", + "exemplar": false, + "expr": "sum by(region, province) (app_farmland_total{region=~\"$region\", province=~\"$province\"})", + "instant": false, + "legendFormat": "{{region}}, {{province}}", + "range": true, + "refId": "A" + } + ], + "title": "No. of farmlands per province", + "transparent": true, + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 5, + "w": 8, + "x": 16, + "y": 1 + }, + "id": 6, + "options": { + "colorMode": "background", + "graphMode": "none", + "justifyMode": "center", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "9.1.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "builder", + "exemplar": false, + "expr": "sum by(region, province, municity) (app_farmland_total{region=~\"$region\", province=~\"$province\", municity=~\"$municity\"})", + "instant": false, + "legendFormat": "{{municity}}", + "range": true, + "refId": "A" + } + ], + "title": "No. of farmlands per municipality or city", + "transparent": true, + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "areaM2" + }, + "overrides": [] + }, + "gridPos": { + "h": 5, + "w": 8, + "x": 0, + "y": 6 + }, + "id": 12, + "options": { + "colorMode": "background", + "graphMode": "none", + "justifyMode": "center", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "9.1.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "builder", + "exemplar": false, + "expr": "sum by(region) (app_farmland_hectares{region=~\"$region\"}) * 1000", + "instant": false, + "legendFormat": "__auto", + "range": true, + "refId": "A" + } + ], + "title": "Sqm. area of farmlands per region", + "transparent": true, + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "areaM2" + }, + "overrides": [] + }, + "gridPos": { + "h": 5, + "w": 8, + "x": 8, + "y": 6 + }, + "id": 13, + "options": { + "colorMode": "background", + "graphMode": "none", + "justifyMode": "center", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "9.1.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "builder", + "exemplar": false, + "expr": "sum by(region, province) (app_farmland_hectares{region=~\"$region\", province=~\"$province\"}) * 1000", + "instant": false, + "legendFormat": "{{region}}, {{province}}", + "range": true, + "refId": "A" + } + ], + "title": "Sqm. area of farmlands per province", + "transparent": true, + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "areaM2" + }, + "overrides": [] + }, + "gridPos": { + "h": 5, + "w": 8, + "x": 16, + "y": 6 + }, + "id": 14, + "options": { + "colorMode": "background", + "graphMode": "none", + "justifyMode": "center", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "9.1.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "builder", + "exemplar": false, + "expr": "sum by(region, province, municity) (app_farmland_hectares{region=~\"$region\", province=~\"$province\", municity=~\"$municity\"}) * 1000", + "instant": false, + "legendFormat": "{{municity}}", + "range": true, + "refId": "A" + } + ], + "title": "Sqm. area of farmlands per municipality or province", + "transparent": true, + "type": "stat" + }, + { + "collapsed": false, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 11 + }, + "id": 9, + "panels": [], + "title": "Trend", + "type": "row" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 14, + "gradientMode": "opacity", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineStyle": { + "fill": "solid" + }, + "lineWidth": 2, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 5, + "w": 8, + "x": 0, + "y": 12 + }, + "id": 2, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "builder", + "exemplar": false, + "expr": "sum by(region) (app_farmland_total{region=~\"$region\"})", + "instant": false, + "legendFormat": "__auto", + "range": true, + "refId": "A" + } + ], + "title": "No. of farmlands per region", + "transparent": true, + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 14, + "gradientMode": "opacity", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 2, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "none" + }, + "overrides": [] + }, + "gridPos": { + "h": 5, + "w": 8, + "x": 8, + "y": 12 + }, + "id": 5, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "builder", + "exemplar": false, + "expr": "sum by(region, province) (app_farmland_total{region=~\"$region\", province=~\"$province\"})", + "instant": false, + "legendFormat": "{{region}}, {{province}}", + "range": true, + "refId": "A" + } + ], + "title": "No. of farmlands per province", + "transparent": true, + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 14, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 2, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 5, + "w": 8, + "x": 16, + "y": 12 + }, + "id": 7, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "9.1.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "builder", + "exemplar": false, + "expr": "sum by(region, province, municity) (app_farmland_total{region=~\"$region\", province=~\"$province\", municity=~\"$municity\"})", + "instant": false, + "legendFormat": "{{municity}}", + "range": true, + "refId": "A" + } + ], + "title": "No. of farmlands per municipality or city", + "transparent": true, + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 14, + "gradientMode": "opacity", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineStyle": { + "fill": "solid" + }, + "lineWidth": 2, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "areaM2" + }, + "overrides": [] + }, + "gridPos": { + "h": 5, + "w": 8, + "x": 0, + "y": 17 + }, + "id": 15, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "builder", + "exemplar": false, + "expr": "sum by(region) (app_farmland_hectares{region=~\"$region\"}) * 1000", + "instant": false, + "legendFormat": "__auto", + "range": true, + "refId": "A" + } + ], + "title": "Sqm. area of farmlands per region", + "transparent": true, + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 14, + "gradientMode": "opacity", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 2, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "areaM2" + }, + "overrides": [] + }, + "gridPos": { + "h": 5, + "w": 8, + "x": 8, + "y": 17 + }, + "id": 16, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "builder", + "exemplar": false, + "expr": "sum by(region, province) (app_farmland_hectares{region=~\"$region\", province=~\"$province\"}) * 1000", + "instant": false, + "legendFormat": "{{region}}, {{province}}", + "range": true, + "refId": "A" + } + ], + "title": "Sqm. area of farmlands per province", + "transparent": true, + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 14, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 2, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "sqm" + }, + "overrides": [] + }, + "gridPos": { + "h": 5, + "w": 8, + "x": 16, + "y": 17 + }, + "id": 17, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "9.1.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "builder", + "exemplar": false, + "expr": "sum by(region, province, municity) (app_farmland_hectares{region=~\"$region\", province=~\"$province\", municity=~\"$municity\"}) * 1000", + "instant": false, + "legendFormat": "{{municity}}", + "range": true, + "refId": "A" + } + ], + "title": "No. of farmlands per municipality or city", + "transparent": true, + "type": "timeseries" + } + ], + "schemaVersion": 37, + "style": "dark", + "tags": [], + "templating": { + "list": [ + { + "current": {}, + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "definition": "label_values(app_farmland_total, region)", + "hide": 0, + "includeAll": false, + "multi": true, + "name": "region", + "options": [], + "query": { + "query": "label_values(app_farmland_total, region)", + "refId": "StandardVariableQuery" + }, + "refresh": 2, + "regex": "", + "skipUrlSync": false, + "sort": 0, + "type": "query" + }, + { + "current": {}, + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "definition": "label_values(app_farmland_total{region=~\"$region\"}, province)", + "hide": 0, + "includeAll": false, + "multi": true, + "name": "province", + "options": [], + "query": { + "query": "label_values(app_farmland_total{region=~\"$region\"}, province)", + "refId": "StandardVariableQuery" + }, + "refresh": 2, + "regex": "", + "skipUrlSync": false, + "sort": 0, + "type": "query" + }, + { + "current": {}, + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "definition": "label_values(app_farmland_total{region=~\"$region\", province=~\"$province\"}, municity)", + "hide": 0, + "includeAll": false, + "label": "municipality-city", + "multi": true, + "name": "municity", + "options": [], + "query": { + "query": "label_values(app_farmland_total{region=~\"$region\", province=~\"$province\"}, municity)", + "refId": "StandardVariableQuery" + }, + "refresh": 2, + "regex": "", + "skipUrlSync": false, + "sort": 0, + "type": "query" + } + ] + }, + "time": { + "from": "now-15m", + "to": "now" + }, + "timepicker": {}, + "timezone": "", + "title": "Farmland Insights", + "uid": "hCe-f8M4z", + "version": 15, + "weekStart": "" +} \ No newline at end of file diff --git a/grafana/seed-allocations-dashboard.json b/grafana/seed-allocations-dashboard.json new file mode 100644 index 00000000..a4bcff7a --- /dev/null +++ b/grafana/seed-allocations-dashboard.json @@ -0,0 +1,696 @@ +{ + "__inputs": [ + { + "name": "DS_PROMETHEUS", + "label": "Prometheus", + "description": "", + "type": "datasource", + "pluginId": "prometheus", + "pluginName": "Prometheus" + } + ], + "__elements": {}, + "__requires": [ + { + "type": "grafana", + "id": "grafana", + "name": "Grafana", + "version": "9.1.0" + }, + { + "type": "datasource", + "id": "prometheus", + "name": "Prometheus", + "version": "1.0.0" + }, + { + "type": "panel", + "id": "stat", + "name": "Stat", + "version": "" + }, + { + "type": "panel", + "id": "timeseries", + "name": "Time series", + "version": "" + } + ], + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": { + "type": "grafana", + "uid": "-- Grafana --" + }, + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "target": { + "limit": 100, + "matchAny": false, + "tags": [], + "type": "dashboard" + }, + "type": "dashboard" + } + ] + }, + "editable": true, + "fiscalYearStartMonth": 0, + "graphTooltip": 0, + "id": null, + "links": [], + "liveNow": false, + "panels": [ + { + "collapsed": false, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 0 + }, + "id": 11, + "panels": [], + "title": "Summary", + "type": "row" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 7, + "w": 8, + "x": 0, + "y": 1 + }, + "id": 3, + "options": { + "colorMode": "background", + "graphMode": "none", + "justifyMode": "center", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "textMode": "value_and_name" + }, + "pluginVersion": "9.1.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "builder", + "exemplar": false, + "expr": "sum by(region, crop) (app_batch_seed_allocation_total{region=~\"$region\", crop=~\"$crop\"})", + "instant": false, + "legendFormat": "{{region}} - {{crop}}", + "range": true, + "refId": "A" + } + ], + "title": "No. of seed allocations per region", + "transparent": true, + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "description": "", + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 7, + "w": 8, + "x": 8, + "y": 1 + }, + "id": 4, + "options": { + "colorMode": "background", + "graphMode": "none", + "justifyMode": "center", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "textMode": "value_and_name" + }, + "pluginVersion": "9.1.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "builder", + "exemplar": false, + "expr": "sum by(region, province, crop) (app_batch_seed_allocation_total{region=~\"$region\", province=~\"$province\", crop=~\"$crop\"})", + "instant": false, + "legendFormat": "{{province}} - {{crop}}", + "range": true, + "refId": "A" + } + ], + "title": "No. of seed allocations per province", + "transparent": true, + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 7, + "w": 8, + "x": 16, + "y": 1 + }, + "id": 6, + "options": { + "colorMode": "background", + "graphMode": "none", + "justifyMode": "center", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "textMode": "value_and_name" + }, + "pluginVersion": "9.1.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "builder", + "exemplar": false, + "expr": "sum by(region, province, municity, crop) (app_batch_seed_allocation_total{region=~\"$region\", province=~\"$province\", municity=~\"$municity\", crop=~\"$crop\"})", + "instant": false, + "legendFormat": "{{municity}} - {{crop}}", + "range": true, + "refId": "A" + } + ], + "title": "No. of seed allocations per municipality or city", + "transparent": true, + "type": "stat" + }, + { + "collapsed": false, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 8 + }, + "id": 9, + "panels": [], + "title": "Trend", + "type": "row" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 14, + "gradientMode": "opacity", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineStyle": { + "fill": "solid" + }, + "lineWidth": 2, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 7, + "w": 8, + "x": 0, + "y": 9 + }, + "id": 2, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "builder", + "exemplar": false, + "expr": "sum by(region, crop) (app_batch_seed_allocation_total{region=~\"$region\", crop=~\"$crop\"})", + "instant": false, + "legendFormat": "{{region}} - {{crop}}", + "range": true, + "refId": "A" + } + ], + "title": "No. of seeds allocations per region", + "transparent": true, + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 14, + "gradientMode": "opacity", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 2, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "none" + }, + "overrides": [] + }, + "gridPos": { + "h": 7, + "w": 8, + "x": 8, + "y": 9 + }, + "id": 5, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "builder", + "exemplar": false, + "expr": "sum by(region, province, crop) (app_batch_seed_allocation_total{region=~\"$region\", province=~\"$province\", crop=~\"$crop\"})", + "instant": false, + "legendFormat": "{{province}} - {{crop}}", + "range": true, + "refId": "A" + } + ], + "title": "No. of seed allocations per province", + "transparent": true, + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 14, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 2, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 7, + "w": 8, + "x": 16, + "y": 9 + }, + "id": 7, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "9.1.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "builder", + "exemplar": false, + "expr": "sum by(region, province, municity, crop) (app_batch_seed_allocation_total{region=~\"$region\", province=~\"$province\", municity=~\"$municity\", crop=~\"$crop\"})", + "instant": false, + "legendFormat": "{{municity}} - {{crop}}", + "range": true, + "refId": "A" + } + ], + "title": "No. of seed allocations per municipality or city", + "transparent": true, + "type": "timeseries" + } + ], + "schemaVersion": 37, + "style": "dark", + "tags": [], + "templating": { + "list": [ + { + "current": {}, + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "definition": "label_values(app_batch_seed_allocation_total, region)", + "hide": 0, + "includeAll": false, + "multi": true, + "name": "region", + "options": [], + "query": { + "query": "label_values(app_batch_seed_allocation_total, region)", + "refId": "StandardVariableQuery" + }, + "refresh": 2, + "regex": "", + "skipUrlSync": false, + "sort": 0, + "type": "query" + }, + { + "current": {}, + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "definition": "label_values(app_batch_seed_allocation_total{region=~\"$region\"}, province)", + "hide": 0, + "includeAll": false, + "multi": true, + "name": "province", + "options": [], + "query": { + "query": "label_values(app_batch_seed_allocation_total{region=~\"$region\"}, province)", + "refId": "StandardVariableQuery" + }, + "refresh": 2, + "regex": "", + "skipUrlSync": false, + "sort": 0, + "type": "query" + }, + { + "current": {}, + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "definition": "label_values(app_batch_seed_allocation_total{region=~\"$region\", province=~\"$province\"}, municity)", + "hide": 0, + "includeAll": false, + "label": "municipality-city", + "multi": true, + "name": "municity", + "options": [], + "query": { + "query": "label_values(app_batch_seed_allocation_total{region=~\"$region\", province=~\"$province\"}, municity)", + "refId": "StandardVariableQuery" + }, + "refresh": 2, + "regex": "", + "skipUrlSync": false, + "sort": 0, + "type": "query" + }, + { + "current": {}, + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "definition": "label_values(app_batch_seed_allocation_total, crop)", + "hide": 0, + "includeAll": false, + "multi": true, + "name": "crop", + "options": [], + "query": { + "query": "label_values(app_batch_seed_allocation_total, crop)", + "refId": "StandardVariableQuery" + }, + "refresh": 2, + "regex": "", + "skipUrlSync": false, + "sort": 0, + "type": "query" + } + ] + }, + "time": { + "from": "now-15m", + "to": "now" + }, + "timepicker": {}, + "timezone": "", + "title": "Seed Allocation Insights", + "uid": "3J380EGVz", + "version": 10, + "weekStart": "" +} \ No newline at end of file diff --git a/grafana/sites-dashboard.json b/grafana/sites-dashboard.json new file mode 100644 index 00000000..42c18a55 --- /dev/null +++ b/grafana/sites-dashboard.json @@ -0,0 +1,651 @@ +{ + "__inputs": [ + { + "name": "DS_PROMETHEUS", + "label": "Prometheus", + "description": "", + "type": "datasource", + "pluginId": "prometheus", + "pluginName": "Prometheus" + } + ], + "__elements": {}, + "__requires": [ + { + "type": "grafana", + "id": "grafana", + "name": "Grafana", + "version": "9.1.0" + }, + { + "type": "datasource", + "id": "prometheus", + "name": "Prometheus", + "version": "1.0.0" + }, + { + "type": "panel", + "id": "stat", + "name": "Stat", + "version": "" + }, + { + "type": "panel", + "id": "timeseries", + "name": "Time series", + "version": "" + } + ], + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": { + "type": "grafana", + "uid": "-- Grafana --" + }, + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "target": { + "limit": 100, + "matchAny": false, + "tags": [], + "type": "dashboard" + }, + "type": "dashboard" + } + ] + }, + "editable": true, + "fiscalYearStartMonth": 0, + "graphTooltip": 0, + "id": null, + "links": [], + "liveNow": false, + "panels": [ + { + "collapsed": false, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 0 + }, + "id": 11, + "panels": [], + "title": "Summary", + "type": "row" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 7, + "w": 8, + "x": 0, + "y": 1 + }, + "id": 3, + "options": { + "colorMode": "background", + "graphMode": "none", + "justifyMode": "center", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "9.1.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "builder", + "exemplar": false, + "expr": "sum by(region) (app_region_total)", + "instant": false, + "legendFormat": "__auto", + "range": true, + "refId": "A" + } + ], + "title": "No. of site regions", + "transparent": true, + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "description": "", + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 7, + "w": 8, + "x": 8, + "y": 1 + }, + "id": 4, + "options": { + "colorMode": "background", + "graphMode": "none", + "justifyMode": "center", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "textMode": "value_and_name" + }, + "pluginVersion": "9.1.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "builder", + "exemplar": false, + "expr": "sum by(region) (app_province_total{region=~\"$region\"})", + "instant": false, + "legendFormat": "{{region}}", + "range": true, + "refId": "A" + } + ], + "title": "No. of site provinces per region", + "transparent": true, + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 7, + "w": 8, + "x": 16, + "y": 1 + }, + "id": 6, + "options": { + "colorMode": "background", + "graphMode": "none", + "justifyMode": "center", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "textMode": "value_and_name" + }, + "pluginVersion": "9.1.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "builder", + "exemplar": false, + "expr": "sum by(region, province, municity) (app_municipality_city_total{region=~\"$region\", province=~\"$province\"})", + "instant": false, + "legendFormat": "{{province}}", + "range": true, + "refId": "A" + } + ], + "title": "No. of site municipalities or cities per province", + "transparent": true, + "type": "stat" + }, + { + "collapsed": false, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 8 + }, + "id": 9, + "panels": [], + "title": "Trend", + "type": "row" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 14, + "gradientMode": "opacity", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineStyle": { + "fill": "solid" + }, + "lineWidth": 2, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 7, + "w": 8, + "x": 0, + "y": 9 + }, + "id": 2, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "builder", + "exemplar": false, + "expr": "sum by(region) (app_region_total)", + "instant": false, + "legendFormat": "count", + "range": true, + "refId": "A" + } + ], + "title": "No. of site regions", + "transparent": true, + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 14, + "gradientMode": "opacity", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 2, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "none" + }, + "overrides": [] + }, + "gridPos": { + "h": 7, + "w": 8, + "x": 8, + "y": 9 + }, + "id": 5, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "builder", + "exemplar": false, + "expr": "sum by(region, province) (app_province_total{region=~\"$region\"})", + "instant": false, + "legendFormat": "{{region}}", + "range": true, + "refId": "A" + } + ], + "title": "No. of site provinces per region", + "transparent": true, + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-BlPu" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 14, + "gradientMode": "opacity", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 2, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 7, + "w": 8, + "x": 16, + "y": 9 + }, + "id": 7, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "9.1.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "builder", + "exemplar": false, + "expr": "sum by(region, province, municity) (app_municipality_city_total{region=~\"$region\", province=~\"$province\"})", + "instant": false, + "legendFormat": "{{province}}", + "range": true, + "refId": "A" + } + ], + "title": "No. of site municipalities or cities per province", + "transparent": true, + "type": "timeseries" + } + ], + "schemaVersion": 37, + "style": "dark", + "tags": [], + "templating": { + "list": [ + { + "current": {}, + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "definition": "label_values(app_province_total, region)", + "hide": 0, + "includeAll": false, + "multi": false, + "name": "region", + "options": [], + "query": { + "query": "label_values(app_province_total, region)", + "refId": "StandardVariableQuery" + }, + "refresh": 1, + "regex": "", + "skipUrlSync": false, + "sort": 0, + "type": "query" + }, + { + "current": {}, + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "definition": "label_values(app_municipality_city_total{region=~\"$region\"}, province)", + "hide": 0, + "includeAll": false, + "multi": true, + "name": "province", + "options": [], + "query": { + "query": "label_values(app_municipality_city_total{region=~\"$region\"}, province)", + "refId": "StandardVariableQuery" + }, + "refresh": 1, + "regex": "", + "skipUrlSync": false, + "sort": 0, + "type": "query" + } + ] + }, + "time": { + "from": "now-15m", + "to": "now" + }, + "timepicker": {}, + "timezone": "", + "title": "Site Insights", + "uid": "5lz6NCGVk", + "version": 13, + "weekStart": "" +} \ No newline at end of file diff --git a/prometheus-config.yml b/prometheus-config.yml new file mode 100644 index 00000000..ff299796 --- /dev/null +++ b/prometheus-config.yml @@ -0,0 +1,24 @@ +# my global config +global: + scrape_interval: 1m # Set the scrape interval to every 15 seconds. Default is every 1 minute. + evaluation_interval: 1m # Evaluate rules every 15 seconds. The default is every 1 minute. + # scrape_timeout is set to the global default (10s). + +# Alertmanager configuration +alerting: + alertmanagers: + - static_configs: + - targets: + # - alertmanager:9093 + +# Load rules once and periodically evaluate them according to the global 'evaluation_interval'. +rule_files: + # - "first_rules.yml" + # - "second_rules.yml" + +# A scrape configuration containing exactly one endpoint to scrape: +# Here it's Prometheus itself. +scrape_configs: + - job_name: laravel + static_configs: + - targets: ["laravel"] diff --git a/setup-agent.sh b/setup-agent.sh new file mode 100755 index 00000000..1717e971 --- /dev/null +++ b/setup-agent.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +AGENT_BINARY=agent-linux-amd64 +VERSION=0.27.0 + +if test -f "$AGENT_BINARY"; then + echo "$AGENT_BINARY already exists." + exit 1; +fi + +curl -O -L https://github.com/grafana/agent/releases/download/v$VERSION/$AGENT_BINARY.zip +unzip $AGENT_BINARY.zip +rm $AGENT_BINARY.zip +chmod a+x $AGENT_BINARY