Running Hawkular Agent

A blog post by John Mazzitelli

agent | metrics | prometheus



Now that Hawkular is moving towards integraton with Prometheus as its metrics collection and storage system, the agent has had some changes. This document will discuss those changes and how to run the Hawkular Agent, specifically version 2.0.0.Final.

First, the Hawkular Agent now only runs as a javaagent (no longer does it run inside WildFly as a subsystem extension). So to run the agent, simply attach it as a javaagent to whatever JVM you want to monitor (be it a WildFly or EAP app server or any JVM application that exposes metrics via JMX). For example, add this command line option to the command that starts the JVM:

-javaagent:hawkular-javaagent.jar=config=hawkular-javaagent-config.yaml,delay=10

The configuration file contains all the settings necessary to start the agent and connect to the Hawkular Server. Once connected, the agent will pull down additional configuration settings from the server.

Running in WildFly

If you are attaching the agent to a WildFly server, you must configure some additional settings.

If you are running WildFly in standalone mode, the standalone.conf you should have something like:

JBOSS_MODULES_SYSTEM_PKGS="org.jboss.byteman,org.jboss.logmanager"
...
JAVA_OPTS="$JAVA_OPTS -Djava.util.logging.manager=org.jboss.logmanager.LogManager"
...
JAVA_OPTS="$JAVA_OPTS -javaagent:$JBOSS_HOME/bin/hawkular-javaagent.jar=config=$JBOSS_HOME/standalone/configuration/hawkular-javaagent-config.yaml,delay=10"

If you are running WildFly in domain mode, the host controller’s domain.conf file should have something like:

HOST_CONTROLLER_JAVA_OPTS="$HOST_CONTROLLER_JAVA_OPTS -Dhawkular.agent.metadata.domain=true \
   -Djboss.modules.system.pkgs=org.jboss.byteman,org.jboss.logmanager \
   -Djava.util.logging.manager=org.jboss.logmanager.LogManager \
   -Djboss.host.server-excluded-properties=jboss.modules.system.pkgs,java.util.logging.manager,hawkular.agent.metadata.domain \
   -javaagent:$JBOSS_HOME/bin/hawkular-javaagent.jar=config=$JBOSS_HOME/domain/configuration/hawkular-javaagent-config-domain.yaml,delay=10"

Running in WildFly Domain Mode

When running WildFly in domain mode, a Hawkular Agent runs in the host controller. There also needs to be a Hawkular Agent running in each of the slave servers spawned by the host controller. You ensure an agent is attached to each slave server by adding the proper -javaagent command line option to the server JVM command found in the host controller’s host.xml. Note also that you also have to tell each slave server’s agent what port it should bind the metrics exporter endpoint to. For example:

  <jvms>
    <jvm name="default">
      <jvm-options>
        ...
        <!-- HAWKULAR SETTINGS -->
        <option value="-Djboss.modules.system.pkgs=org.jboss.byteman,org.jboss.logmanager"/>
        <option value="-Djava.util.logging.manager=org.jboss.logmanager.LogManager"/>
        <option value="-javaagent:${jboss.home.dir}/bin/hawkular-javaagent.jar=config=${jboss.domain.config.dir}/hawkular-javaagent-config-metrics-only.yaml,delay=10"/>
      </jvm-options>
    </jvm>
  </jvms>
  <servers>
    <server name="server-one" group="main-server-group">
      <jvm name="default">
        <jvm-options>
          <!-- HAWKULAR SETTINGS -->
          <option value="-Dhawkular.agent.metrics.port=9780"/>
        </jvm-options>
      </jvm>
    </server>
  </servers>
  ...

The slave server agents are to be run in metrics-only mode (that is, no managed-servers section is defined in their configuration files).

Example

To see an example WildFly distribution configured to run the Hawkular Agent in either standalone or domain mode, build from source or grab from a Maven repository the Maven artifact "org.hawkular.agent:hawkular-javaagent-wildfly-dist". Look at its bin/ directory for the domain.conf and standalone.conf files and look in the standalone/configuration and domain/configuration directories for the different agent configuration files. Note also the host-hawkular.xml that is to be used with the --host-config option when running in domain mode.

How It Works

When the agent starts, it reads its configuration file from disk. The agent then attempts to connect to the Hawkular Server. The agent will download some additional configuration from the Hawkular Server that it overlays on top of its existing configuration (this pulls down specific metadata for the types of resources it is to manage).

The agent will also pull down a separate configuration file that is used to configure the Prometheus JMX Exporter which is started by the agent. This is called the "Metrics Exporter". Thus you will get an agent that collects inventory and stores it in Hawkular, but you will also have a metrics exporter that will be used to expose metrics for collection by Hawkular’s Prometheus Server.

The agent determines what configuration files to pull down via the settings in the local agent configuration file. The local agent configuration file is the one referred to in the javaagent command line - it is where you told the agent to find the configuration file. e.g. javaagent:hawkular-javaagent.jar=config=this-config-file.yaml,delay=10:

subsystem:
  type-version: WF10
...
metrics-exporter:
  config-file: WF10

As an example, if the agent is to monitor EAP6, you would replace "WF10" with "EAP6". As more supported products are added, additional configuration files are loaded on the Hawkular Server which can then be pulled down by the agent by simply changing the values of these type-version and config-file settings.

Note
Note that a WildFly host controller agent must be told to download the metrics exporter config file of "WF10-DOMAIN" while the type-version should still be "WF10". See the WildFly+Agent distro (Maven artifact org.hawkular.agent:hawkular-javaagent-wildfly-dist) as an example.

When an agent itself is registered in inventory on the Hawkular Server, Hawkular’s Prometheus Server will be told to scrape the agent’s metrics exporter endpoint, thus the agent’s metrics are collected automatically.

How It Works with WildFly Domain Mode

The agent runs in the host controller. The host controller’s agent can get all of the inventory for the host controller and its slave servers. There is also a metrics exporter running in the host controller’s agent as well (so metrics for the host controller can be collected).

An agent runs in each slave server as well, but those agents run in "metrics-only" mode. No inventory is collected by these agents, but they do start a metrics exporter so metrics from each slave server can be collected.

To configure the Prometheus JMX Exporter in the slave server’s agent, you must turn it on in "slave proxy mode" via these settings within the local agent configuration file. This is the agent configuration file you told the slave server to use in their -javaagent command line argument. See the host.xml entry you added for the slave servers. e.g.:

<jvms>
  <jvm name="default">
    <jvm-options>
      <option value="-javaagent:${jboss.home.dir}/bin/hawkular-javaagent.jar=config=${jboss.domain.config.dir}/hawkular-javaagent-config-metrics-only.yaml,delay=10"/>
metrics-exporter:
  proxy:
    mode: slave
    data-dir: ${jboss.domain.base.dir}/data/hawkular-metrics-exporter

The host controller’s agent must turn on the Prometheus JMX Exporter in "master proxy mode" in the host controller agent’s local configuration file (this is the configuration file you told the host controller agent to use in its -javaagent command line option within the domain.conf file):

metrics-exporter:
  proxy:
    mode: master
    data-dir: ${jboss.domain.data.dir}/hawkular-metrics-exporter

Note the data directories between the slaves and master must be the same. It is recommended to use a subdirectory under WildFly’s domain/data directory as you see in the examples above.

What happens under the covers is the slave server will write a file to the data directory describing the metrics exporter endpoint it started. The master will collect this information from all slaves and makes sure the Hawkular Server will tell the Prometheus Server to scrape those slave endpoints as well as the host controller agent’s own metrics exporter endpoint.




Published by John Mazzitelli on 11 December 2017

redhatlogo-white

© 2016 | Hawkular is released under Apache License v2.0