vlamug / ratibor

Ratibor is a service for making metrics from data

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ratibor

This app plows data via several ways(syslog, api, client) and exposes metrics based on this data readable for Prometheus. Metrics are configurable via config file flexibly, see examples below.

Config

The example of config:

input:
  api:
  - name: "some_api_input"
    listenAddr: 9999
    path: /some/api
template:
  type: plain
  pattern: "{{.http_code}} | {{.duration}} | {{.request}} | {{.method}}"
  delimiter: "|"
metrics:
- name: requests_total
  type: counter
  help: "Total requests"
  expr: '{{if ne .http_code "1"}}12{{else}}{{end}}'
  value: "1"
  labels:
  - name: "http_code"
    value: {{.http_code}}
  - name: "method"
    value: {{.method}}
- name: errors_total
  type: counter
  help: "Total Errors"
  expr: '{{if ne .http_code "200"}}1{{end}}'
  value: "1"
- name: response_time_milliseconds
  type: summary
  value: "{{.duration}}"

Supported types

Ratibor supports the following types of templates:

  • plain: is a one line data, the values in which are separated by delimiter. For example: value 1 | value 2 | value 3. The delimiter is |.

Metric value evaluation

To evaluate metric value the two fields are used: expr and value. There are 3 cases of using this fields:

  1. expr and value are not empty. In this case if evaluated expr is not empty, then if value can be considered as float64 value, it will be as metric value, else if value is not empty(i.e. it is some string), it will be as float(1) as metric value, else float(0):

Examples:

# http_code=200

- name: errors_total
  type: counter
  help: "Total Errors"
  expr: '{{if ne .http_code "200"}}1{{end}}'
  value: "1"

# nothing will be used as metric value
# http_code=100

- name: errors_total
  type: counter
  help: "Total Errors"
  expr: '{{if ne .http_code "200"}}1{{end}}'
  value: "1"

# float64(1) will be used as metric value
# http_code=100, page=/search

- name: errors_total
  type: counter
  help: "Total Errors"
  expr: '{{if ne .http_code "200"}}1{{end}}'
  value: "{{if eq .page "/page"}}2{{else}}3{{end}}"

# float64(2) will be used as metric value
# http_code=100, page=/product

- name: errors_total
  type: counter
  help: "Total Errors"
  expr: '{{if ne .http_code "200"}}1{{end}}'
  value: "{{if eq .page "/page"}}2{{else}}3{{end}}"

# float64(3) will be used as metric value
# http_code=100, page=/product

- name: errors_total
  type: counter
  help: "Total Errors"
  expr: '{{if ne .http_code "200"}}1{{end}}'
  value: "{{if eq .page "/page"}}some_value{{else}}another_value{{end}}"

# float64(1) will be used as metric value
  1. expr is not empty, but value is empty, then if expr can be considered as float64, it will be as metric value, else if expr is not empty(i.e. some string), then float64(1) value will be as metric value, else nothing will be exposed.
# http_code=100

- name: errors_total
  type: counter
  help: "Total Errors"
  expr: '{{if ne .http_code "200"}}2{{end}}'

# float64(2) will be used as metric value
# http_code=100

- name: errors_total
  type: counter
  help: "Total Errors"
  expr: '{{if ne .http_code "200"}}yes{{end}}'

# float64(1) will be used as metric value
# http_code=200

- name: errors_total
  type: counter
  help: "Total Errors"
  expr: '{{if ne .http_code "200"}}yes{{end}}'

# nothing will be used as metric value
  1. expr is empty, but value is not empty, then if value can be considered as float64, it will be as metric value, else if value is not empty, float64(1) will be exposed as metric value else float64(0) will be exposed.
# page=/page

- name: errors_total
  type: counter
  help: "Total Errors"
  value: "{{if eq .page "/page"}}2{{else}}3{{end}}"

# float64(2) will be used as metric value
# page=/product

- name: errors_total
  type: counter
  help: "Total Errors"
  value: "{{if eq .page "/page"}}3{{end}}"

# float64(0) will be used as metric value
# page=/page

- name: errors_total
  type: counter
  help: "Total Errors"
  value: "{{if eq .page "/page"}}yes{{end}}"

# float64(1) will be used as metric value

Label value evaluation

- name: handler_total_requests
  type: counterVec
  help: "Total requests by handler"
  value: 1
  labels:
  - name: "status"
    value: "{{.status}}"
  - name: "handler"
    values:
    - expr: "{{if contains .request `blog`}}1{{end}}"
      value: "{{ extractRegExp `\\/blog\\/[a-zA-Z-_\\/]+` .request }}"
    - expr: "{{if eq .request `/`}}1{{end}}"
      value: "home"
    - value: "{{if contains .request `forum`}}{{ extractRegExp `\\/forum\\/[a-zA-Z-_\\/]+` .request }}{{end}}"

Inputs

Input is a source of data. There are several types of inputs.

Syslog

To set up syslog input add the following settings into configuration:

input:
  syslog:
    - name: "some_syslog_input"
      listenAddr: ":9876"

API

To receive data via API it is needed to add the following configuration:

input:
  api:
    - name: "some_api_input"
      listenAddr: ":9999"
      path: "/my_input"

About

Ratibor is a service for making metrics from data

License:MIT License


Languages

Language:Go 95.5%Language:Makefile 4.0%Language:Dockerfile 0.4%Language:Shell 0.1%