Skip to content

Commit 5a10ad0

Browse files
committed
FOUR-20535 Initial Setup (Laravel + Prometheus Integration)
1 parent b06ef14 commit 5a10ad0

5 files changed

Lines changed: 361 additions & 3 deletions

File tree

README.md

Lines changed: 220 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -439,11 +439,228 @@ npm run dev-font
439439
```
440440

441441

442-
# Message broker driver, possible values: rabbitmq, kafka, this is optional, if not exists or is empty, the Nayra will be work as normally with local execution
443-
MESSAGE_BROKER_DRIVER=rabbitmq
442+
# Install Prometheus and Grafana with Docker
443+
444+
This guide explains how to install and run **Prometheus** and **Grafana** using Docker. Both tools complement each other: Prometheus collects and monitors metrics, while Grafana visualizes them with interactive dashboards.
445+
446+
## Install Docker
447+
Ensure Docker is installed on your system. Verify the installation:
448+
```bash
449+
docker --version
450+
```
451+
If not installed, follow the [official Docker documentation](https://docs.docker.com/get-docker/).
452+
453+
## Prometheus Installation
454+
455+
### 1. Pull the Prometheus Docker Image
456+
Download the official Prometheus image from Docker Hub:
457+
```bash
458+
docker pull prom/prometheus
459+
```
460+
461+
### 2. Create a Prometheus Configuration File
462+
Prometheus requires a configuration file (`prometheus.yml`) to define the metrics it will collect. Example:
463+
```yaml
464+
# prometheus.yml
465+
global:
466+
scrape_interval: 15s # Metrics collection interval
467+
468+
scrape_configs:
469+
- job_name: "prometheus"
470+
static_configs:
471+
- targets: ["localhost:9090"] # Monitor Prometheus itself
472+
```
473+
474+
### 3. Run Prometheus with Docker
475+
Use the following command to start Prometheus with the configuration file:
476+
```bash
477+
docker run -d \
478+
--name prometheus \
479+
-p 9090:9090 \
480+
-v $(pwd)/prometheus.yml:/etc/prometheus/prometheus.yml \
481+
prom/prometheus
482+
```
483+
- `-d`: Run the container in detached mode.
484+
- `--name`: Name of the container.
485+
- `-p 9090:9090`: Map port 9090 of the container to port 9090 of your machine.
486+
- `-v`: Mount the `prometheus.yml` file into the container.
487+
488+
### 4. Optional: Persistent Data
489+
To retain Prometheus data after stopping the container, use a Docker volume:
490+
```bash
491+
docker run -d \
492+
--name prometheus \
493+
-p 9090:9090 \
494+
-v $(pwd)/prometheus.yml:/etc/prometheus/prometheus.yml \
495+
-v prometheus_data:/prometheus \
496+
prom/prometheus
497+
```
498+
This creates a volume named `prometheus_data` to store data.
499+
500+
### 5. Access Prometheus
501+
Open your browser and visit:
502+
```
503+
http://localhost:9090
504+
```
505+
From here, you can explore collected metrics and configure custom queries.
506+
507+
### 6. Container Management
508+
- View container logs:
509+
```bash
510+
docker logs prometheus
511+
```
512+
- Stop the container:
513+
```bash
514+
docker stop prometheus
515+
```
516+
- Remove the container:
517+
```bash
518+
docker rm prometheus
519+
```
520+
521+
## Grafana Installation
522+
523+
### 1. Pull the Grafana Docker Image
524+
Download the official Grafana image from Docker Hub:
525+
```bash
526+
docker pull grafana/grafana
527+
```
528+
529+
### 2. Run Grafana
530+
Run Grafana in a container:
531+
```bash
532+
docker run -d \
533+
--name grafana \
534+
-p 3000:3000 \
535+
grafana/grafana
536+
```
537+
- `-d`: Run the container in detached mode.
538+
- `--name`: Assign a name to the container.
539+
- `-p 3000:3000`: Map port 3000 of the container to port 3000 of your machine.
540+
541+
### 3. Persistent Data for Grafana
542+
To avoid losing configurations or data after restarting the container, mount a volume:
543+
```bash
544+
docker run -d \
545+
--name grafana \
546+
-p 3000:3000 \
547+
-v grafana_data:/var/lib/grafana \
548+
grafana/grafana
549+
```
550+
This creates a volume named `grafana_data` to store Grafana data.
551+
552+
### 4. Access Grafana
553+
Open your browser and navigate to:
554+
```
555+
http://localhost:3000
556+
```
557+
Default credentials:
558+
- **Username**: `admin`
559+
- **Password**: `admin`
560+
561+
You will be prompted to change the password on the first login.
562+
563+
### 5. Integrate Grafana with Prometheus
564+
To connect Grafana with Prometheus:
565+
1. Open **Settings** in Grafana.
566+
2. Select **Data Sources**.
567+
3. Click **Add data source**.
568+
4. Choose **Prometheus** as the data source.
569+
5. Set the Prometheus Service URL (e.g., `http://localhost:9090`).
570+
6. If Prometheus and Grafana run on the same machine:
571+
- Use `http://host.docker.internal:9090` (for Docker Desktop).
572+
- Use `http://<your-machine-IP>:9090`.
573+
7. If they share the same network (e.g., Docker Compose):
574+
- Use the container name as the host: `http://prometheus:9090`.
575+
8. Click **Save & Test** to verify the connection.
576+
577+
### 6. Container Management
578+
- View container logs:
579+
```bash
580+
docker logs grafana
581+
```
582+
- Restart the container:
583+
```bash
584+
docker restart grafana
585+
```
586+
- Stop the container:
587+
```bash
588+
docker stop grafana
589+
```
590+
- Remove the container:
591+
```bash
592+
docker rm grafana
593+
```
594+
595+
### 7. Install Optional Plugins
596+
To install plugins in Grafana, use environment variables when starting the container:
597+
```bash
598+
docker run -d \
599+
--name grafana \
600+
-p 3000:3000 \
601+
-v grafana_data:/var/lib/grafana \
602+
-e "GF_INSTALL_PLUGINS=grafana-piechart-panel,grafana-clock-panel" \
603+
grafana/grafana
604+
```
605+
606+
## Examples of Using Grafana in ProcessMaker
607+
608+
### **Configure Prometheus With Your Application**
609+
610+
Add the `/metrics` endpoint from your ProcessMaker application to the `metrics/prometheus.yml` file, make the following change:
611+
612+
```yaml
613+
scrape_configs:
614+
- job_name: 'laravel_app'
615+
static_configs:
616+
- targets: ['https://processmaker.net:8000'] # host and port of application
617+
```
618+
619+
Restart Prometheus:
620+
621+
```bash
622+
docker restart prometheus
623+
```
624+
625+
### **Use the Facade in Your Application**
626+
627+
Now you can use the `Metrics` Facade anywhere in your application to manage metrics.
628+
629+
#### **Example: Incrementing a Counter**
630+
631+
In a controller:
632+
633+
```php
634+
namespace App\Http\Controllers;
635+
636+
use ProcessMaker\Facades\Metrics;
637+
638+
class ExampleController extends Controller
639+
{
640+
public function index()
641+
{
642+
Metrics::registerCounter('requests_total', 'Total number of requests', ['method']);
643+
Metrics::incrementCounter('requests_total', ['GET']);
644+
645+
return response()->json(['message' => 'Hello, world!']);
646+
}
647+
}
648+
```
649+
650+
#### **Example: Registering and Using a Histogram**
651+
652+
```php
653+
Metrics::registerHistogram(
654+
'request_duration_seconds',
655+
'Request duration time',
656+
['method'],
657+
[0.1, 0.5, 1, 5]
658+
);
659+
$histogram = Metrics::incrementHistogram('request_duration_seconds', ['GET'], microtime(true) - LARAVEL_START);
660+
```
444661

445662

446-
#### License
663+
# License
447664

448665
Distributed under the [AGPL Version 3](https://www.gnu.org/licenses/agpl-3.0.en.html)
449666

metrics/README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
## Compose sample
2+
### Prometheus & Grafana
3+
4+
Project structure:
5+
```
6+
.
7+
├── compose.yaml
8+
├── grafana
9+
│   └── datasource.yml
10+
├── prometheus
11+
│   └── prometheus.yml
12+
└── README.md
13+
```
14+
15+
[_compose.yaml_](compose.yaml)
16+
```
17+
services:
18+
prometheus:
19+
image: prom/prometheus
20+
...
21+
ports:
22+
- 9090:9090
23+
grafana:
24+
image: grafana/grafana
25+
...
26+
ports:
27+
- 3000:3000
28+
```
29+
The compose file defines a stack with two services `prometheus` and `grafana`.
30+
When deploying the stack, docker compose maps port the default ports for each service to the equivalent ports on the host in order to inspect easier the web interface of each service.
31+
Make sure the ports 9090 and 3000 on the host are not already in use.
32+
33+
## Deploy with docker compose
34+
35+
```
36+
$ docker compose up -d
37+
Creating network "prometheus-grafana_default" with the default driver
38+
Creating volume "prometheus-grafana_prom_data" with default driver
39+
...
40+
Creating grafana ... done
41+
Creating prometheus ... done
42+
Attaching to prometheus, grafana
43+
44+
```
45+
46+
## Expected result
47+
48+
Listing containers must show two containers running and the port mapping as below:
49+
```
50+
$ docker ps
51+
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
52+
dbdec637814f prom/prometheus "/bin/prometheus --c…" 8 minutes ago Up 8 minutes 0.0.0.0:9090->9090/tcp prometheus
53+
79f667cb7dc2 grafana/grafana "/run.sh" 8 minutes ago Up 8 minutes 0.0.0.0:3000->3000/tcp grafana
54+
```
55+
56+
Navigate to `http://localhost:3000` in your web browser and use the login credentials specified in the compose file to access Grafana. It is already configured with prometheus as the default datasource.
57+
58+
![page]
59+
60+
Navigate to `http://localhost:9090` in your web browser to access directly the web interface of prometheus.
61+
62+
Stop and remove the containers. Use `-v` to remove the volumes if looking to erase all data.
63+
```
64+
$ docker compose down -v
65+
```

metrics/compose.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
services:
2+
prometheus:
3+
image: prom/prometheus
4+
container_name: prometheus
5+
command:
6+
- '--config.file=/etc/prometheus/prometheus.yml'
7+
ports:
8+
- 9090:9090
9+
restart: unless-stopped
10+
volumes:
11+
- ./prometheus:/etc/prometheus
12+
- prom_data:/prometheus
13+
grafana:
14+
image: grafana/grafana
15+
container_name: grafana
16+
ports:
17+
- 3000:3000
18+
restart: unless-stopped
19+
environment:
20+
- GF_SECURITY_ADMIN_USER=admin
21+
- GF_SECURITY_ADMIN_PASSWORD=grafana
22+
volumes:
23+
- ./grafana:/etc/grafana/provisioning/datasources
24+
volumes:
25+
prom_data:

metrics/grafana/datasource.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Global configuration settings for Grafana
2+
apiVersion: 1
3+
4+
# Grafana datasource configuration for Prometheus
5+
datasources:
6+
- name: Prometheus
7+
type: prometheus
8+
url: http://prometheus:9090
9+
isDefault: true
10+
access: proxy
11+
editable: true

metrics/prometheus/prometheus.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Global configuration settings for Prometheus
2+
global:
3+
scrape_interval: 15s
4+
scrape_timeout: 10s
5+
evaluation_interval: 15s
6+
7+
# Scrape configurations
8+
scrape_configs:
9+
# For Prometheus
10+
- job_name: prometheus
11+
honor_timestamps: true
12+
scrape_interval: 15s
13+
scrape_timeout: 10s
14+
metrics_path: /metrics
15+
scheme: http
16+
static_configs:
17+
- targets:
18+
- localhost:9090
19+
20+
# For ProcessMaker https://127.0.0.5:8092/metrics
21+
- job_name: processmaker
22+
honor_timestamps: true
23+
scrape_interval: 15s
24+
scrape_timeout: 10s
25+
metrics_path: /metrics
26+
scheme: https
27+
tls_config:
28+
insecure_skip_verify: true # Ignore the certificate validation (for development only, remove for production).
29+
static_configs:
30+
- targets:
31+
- 127.0.0.5:8092 # Replace with the address of your application.
32+
33+
# Alerting configuration for Prometheus.
34+
#alerting:
35+
# alertmanagers:
36+
# - static_configs:
37+
# - targets: []
38+
# scheme: http
39+
# timeout: 10s
40+
# api_version: v1

0 commit comments

Comments
 (0)