Self-hosted | laravel-prometheus | Spatie

 SPATIE

  Laravel Prometheus
=====================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-prometheus](https://spatie.be/docs/laravel-prometheus/v1)  Setting-up-prometheus-and-grafana  Self-hosted

 Version   v1

 Other versions for crawler [v1](https://spatie.be/docs/laravel-prometheus/v1)

- [ Introduction ](https://spatie.be/docs/laravel-prometheus/v1/introduction)
- [ Support us ](https://spatie.be/docs/laravel-prometheus/v1/support-us)
- [ Requirements ](https://spatie.be/docs/laravel-prometheus/v1/requirements)
- [ Installation &amp; setup ](https://spatie.be/docs/laravel-prometheus/v1/installation-setup)
- [ Questions and issues ](https://spatie.be/docs/laravel-prometheus/v1/questions-issues)
- [ Changelog ](https://spatie.be/docs/laravel-prometheus/v1/changelog)
- [ About us ](https://spatie.be/docs/laravel-prometheus/v1/about-us)

Basic usage
-----------

- [ Creating gauges ](https://spatie.be/docs/laravel-prometheus/v1/basic-usage/creating-gauges)
- [ Using Horizon exporters ](https://spatie.be/docs/laravel-prometheus/v1/basic-usage/using-horizon-exporters)
- [ Using Queue exporters ](https://spatie.be/docs/laravel-prometheus/v1/basic-usage/using-queue-exporters)

Setting up Prometheus and Grafana
---------------------------------

- [ Introduction ](https://spatie.be/docs/laravel-prometheus/v1/setting-up-prometheus-and-grafana/introduction)
- [ Using grafana.com ](https://spatie.be/docs/laravel-prometheus/v1/setting-up-prometheus-and-grafana/using-grafana-com)
- [ Self-hosted ](https://spatie.be/docs/laravel-prometheus/v1/setting-up-prometheus-and-grafana/self-hosted)
- [ Using fly.io ](https://spatie.be/docs/laravel-prometheus/v1/setting-up-prometheus-and-grafana/using-fly-metrics)

Advanced usage
--------------

- [ Creating multiple endpoints ](https://spatie.be/docs/laravel-prometheus/v1/advance-usage/using-multiple-endpoints)
- [ Creating collectors ](https://spatie.be/docs/laravel-prometheus/v1/advance-usage/creating-collectors)
- [ Using counter type metric ](https://spatie.be/docs/laravel-prometheus/v1/advance-usage/using-counter-metric)

 Self-hosted
===========

###  On this page

1. [ 1. Provision a server on Laravel Forge and install Prometheus and Grafana on it ](#content-1-provision-a-server-on-laravel-forge-and-install-prometheus-and-grafana-on-it)
2. [ 2. Configure Prometheus to scrape the metrics from your application and store them in its database ](#content-2-configure-prometheus-to-scrape-the-metrics-from-your-application-and-store-them-in-its-database)
3. [ 3. Configure Grafana to connect to Prometheus and visualize the metrics: ](#content-3-configure-grafana-to-connect-to-prometheus-and-visualize-the-metrics)

To receive metrics from your applications using Prometheus, and visualize them using Grafana, you can use a docker image that is deployed on your server.

Here are the general steps to set up Prometheus and Grafana via Laravel Forge. This isn't meant as a full guide, but rather as a starting point for you to get started.

1. Provision a server on Laravel Forge and install Prometheus and Grafana on it
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

- Connect to your server via SSH.
- Install Prometheus by following [the official installation guide](https://prometheus.io/docs/prometheus/latest/installation/)
- Install Grafana by following [the official installation guide](https://grafana.com/docs/grafana/latest/installation/)

2. Configure Prometheus to scrape the metrics from your application and store them in its database
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

- Edit the Prometheus configuration file `/etc/prometheus/prometheus.yml` and add a new job to scrape metrics from your application. For example:

```
scrape_configs:
- job_name: laravel
  scrape_interval: 10s
  metrics_path: /prometheus
  static_configs:
    - targets: ['your-laravel-app.com']
```

This configuration tells Prometheus to scrape metrics from your application every 10 seconds and store them in its database.

3. Configure Grafana to connect to Prometheus and visualize the metrics:
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

- Open Grafana in your web browser by visiting http://your-server-ip:3000.
- Log in with the default credentials (username: admin, password: admin).
- Add a new Prometheus data source by clicking on the gear icon on the left sidebar, then selecting "Data Sources", then "Add data source".
- Fill in the form with the following details:

Name: Prometheus Type: Prometheus URL: http://localhost:9090

This configuration tells Grafana to connect to Prometheus at http://localhost:9090.

- Create a new dashboard by clicking on the plus icon on the left sidebar, then selecting "Dashboard", then "Add new panel".
- Choose a visualization type (e.g. graph, gauge, table) and configure it to display the metrics you want to monitor.
- Save the dashboard and view it to see the metrics in real-time.

That's it! You should now have Prometheus and Grafana set up to monitor your application's metrics.
