Skip to content

Latest commit

 

History

History
150 lines (131 loc) · 4.93 KB

README.md

File metadata and controls

150 lines (131 loc) · 4.93 KB

Prometheus Metrics Exporter

Description

PME is a simple application to scrape values from JSON or HTML HTTP endpoints and push metrics to a prometheus pushgateway. The application might come in handy e.g. when:

  • your scrape targets are behind a NAT firewall and cannot be reached from the outside by your prometheus instance.
  • for some reason you cannot or will not set up a prometheus client on the systems you wish to monitor.

The tool is neither a service nor a daemon. If you want continuous export of metrics, deploy a container with a CRON job executing the binary.

Currently PME supports following prometheus instruments:

  • counter
  • gauge

There are currently no plans on adding support for the reamining instruments.

Values can be extracted from JSON by dot-notation or from HTML by XPath.

Command line flags

-config=path/to/configFile

Configuration

The configuration format is JSON.

Configuration overview:

Configuration diagram

Configuration example:

{
  "pushGatewayUrl": "http://pushgateway.url:port",
  "scrapeTargets": [
    {
      "url": "http://some.url/path",
      "basicAuth": {
                    "username": "username1",
                    "password": "password123"
                   },
      "mimeType": "json",
      "jobName": "jobNameGoesHere",
      "timeoutInSecs": 10,
      "metrics": [
        {
          "name": "name_goes_here",
          "help": "help text goes here",
          "path": "json.path.to.value",
          "instrumentType": "gauge",
          "regex": "(\\d+)"
        },
        {
          "name": "name_goes_here",
          "help": "help text goes here",
          "path": "some.other.path",
          "instrumentType": "counter",
          "regex": "(\\d+)"
        }
      ],
      "labels": [
        {
          "name": "nameOfLabel",
          "value": "valueOfLabel"
        },
        {
          "name": "nameOfLabel2",
          "value": "valueOfLabel2"
        }
      ]
    },
    {
      "url": "http://another.url/path",
      "mimeType": "html",
      "jobName": "anotherJobName",
      "timeoutInSecs": 10,
      "metrics": [
        {
          "name": "name_goes_here",
          "help": "help text goes here",
          "path": "/xpath/to/some[1]/value",
          "instrumentType": "gauge",
          "regex": "*(\\d+)"
        },
        {
          "name": "name_goes_here",
          "help": "help text goes here",
          "path": "/xpath/to/another/value",
          "instrumentType": "counter",
          "regex": "*(\\d+)"
        }
      ],
      "labels": [
        {
          "name": "nameOfLabel",
          "value": "valueOfLabel"
        },
        {
          "name": "nameOfLabel2",
          "value": "valueOfLabel2"
        }
      ]
    }
  ]
}

Global entries

  • pushGatewayUrl: the url of the pushgateway. It is global for the entire configuration.
  • scrapeTargets: a list of targets to scrape from. (Documented below)

ScrapeTargets

  • url: the url to scrape from
  • basicAuth (optional) : information for authentication with the specific scrape target (Documented below)
  • mimeType: the content type of the scrape url. JSON and HTML are supported.
  • jobName: the job name to display in the pushgateway.
  • timeoutInSecs: the time to wait for response from the scrape target before timing out.
  • metrics: a list of metrics to pull from the scrape target response. (Documented below)
  • labels: a list of labels for the current job. (Documented below)

BasicAuth (optional)

  • username: the basic auth username
  • password: the basic auth password

Metrics

  • name: the name for the instrument.
  • help: the help text for the instrument.
  • path: the path of the value for the instrument. (dot notation or xpath)
  • instrumentType: the type of the instrument. Counter and gauge are supported.
  • regex (optional): the regex to apply to the path content.
    • An empty regex will return the entire path content as a float.
    • An omitted regex will return the entire path content as a float.
    • A nonempty regex must include a single capture group.

Labels

  • name: the name of the label.
  • value: the value of the label.

Build/test

The application was originally written in go 1.11.2. Latest tested under 1.11.13

A makefile is available with rules for both building and testing the application.

External libraries and/or modules

The following libraries and/or modules are directly used in the project. Note that other modules might be indirectly included.