[[monitoring-with-elastic-agent]]
=== Collect {ls} monitoring data for stack monitoring
[subs="attributes"]
++++
<titleabbrev>Collect monitoring data for stack monitoring</titleabbrev>
++++

{agent} collects monitoring data from your {ls} instance and sends it directly to your monitoring cluster.
With {agent} collection the monitoring agent remains active even if the {ls} instance does not. 

You can enroll {agent} in {fleet-guide}/install-fleet-managed-elastic-agent.html[{fleet}] for management 
from a central location, or you can run {fleet-guide}/install-standalone-elastic-agent.html[{agent} standalone]. 

**Prerequisites**

Complete these steps as you prepare to collect and ship monitoring data for stack monitoring:

[[disable-default-include-ea]]
.Disable default collection of {ls} monitoring metrics
[%collapsible]
====
include::monitoring-prereq-disable-default.asciidoc[]
====

[[define-cluster__uuid-ea]]
.Specify the target cluster_uuid (optional)
[%collapsible]
====
include::monitoring-prereq-define-cluster.asciidoc[]
====

[[set-up-monitoring-ea]]
.Set up {es} monitoring 
[%collapsible]
====
include::monitoring-prereq-setup-es.asciidoc[]
====

[[create-user-ea]]
.Create a monitoring user (standalone agent only)
[%collapsible]
====
include::monitoring-prereq-create-user.asciidoc[]
====

[discrete]
[[install-and-configure-mon]]
=== Install and configure {agent}

When you have completed the prerequisites, install and configure {agent} to monitor host logs and metrics.
We'll walk you through the process in these steps:

* <<add-logstash-integration-ea>>
* <<add-agent-to-fleet-ea>>
* <<view-assets>>
* <<view-data-stack>>

Check out {fleet-guide}/elastic-agent-installation.html[Installing {agent}] in the _Fleet and Elastic Agent Guide_ for more info. 

[discrete]
[[add-logstash-integration-ea]]
==== Add the {agent} {ls} integration

. Go to the {kib} home page, and click **Add integrations**.
+
--
[role="screenshot"]
image::images/kibana-home.png[{kib} home page]
--

. In the query bar, search for **{ls}** and select the integration to see more
details about it.

. Click **Add {ls}**.

. Configure the integration name and optionally add a description.

. Configure the integration to collect logs.
* Make sure that **Logs** is turned on if you want to collect logs from your {ls} instance, ensuring that the required settings are correctly configured:
* Under **Logs**, modify the log paths
to match your {ls} environment.

. Configure the integration to collect metrics
* Make sure that **Metrics (Stack Monitoring)** is turned on, and **Metrics (Technical Preview)** is turned off, if you
want to collect metrics from your {ls} instance
* Under **Metrics (Stack Monitoring)**, make sure the hosts setting
points to your {ls} host URLs. By default, the integration collects {ls}
monitoring metrics from `localhost:9600`. If that host and port number are not
correct, update the `hosts` setting. If you configured {ls} to use encrypted
communications, you must access it via HTTPS. For example, use a `hosts` setting
like
`https://localhost:9600`.

. Choose where to add the integration policy. +
Click **New hosts** to add it to new agent policy or **Existing hosts** to add it to an existing agent policy.
. In the popup, click **Add {agent} to your hosts** to open the **Add agent**
flyout.
+
TIP: If you accidentally close the popup, go to **{fleet} > Agents**, then click
**Add agent** to access the flyout.

[discrete]
[[add-agent-to-fleet-ea]]
==== Install and run an {agent} on your machine
// Include section about installing agents
include::monitoring-install.asciidoc[tag=install-agent-widget]

[discrete]
[[view-assets]]
=== View assets
// Include section about viewing assets
include::monitoring-view.asciidoc[]

[discrete]
[[view-data-stack]]
==== Monitor {ls} logs and metrics (Stack Monitoring)

{kibana-ref}/monitoring-data.html[View the monitoring data in {kib}], and navigate to the <<logstash-monitoring-ui, monitoring UI>>.
