Skip to content

Instantly share code, notes, and snippets.

@megastef
Last active October 4, 2017 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save megastef/4a2024ac4ec48c2344bc6c8aae3f677f to your computer and use it in GitHub Desktop.
Save megastef/4a2024ac4ec48c2344bc6c8aae3f677f to your computer and use it in GitHub Desktop.
Prometheus metrics to Elasticsearch via logagent-js
input:
docker-prometheus:
module: command
# connect to metrics endpoint
command: curl http://127.0.0.1:9323/metrics
sourceName: prometheus_metrics
debug: false
# scrape data every 10 seconds
restart: 10
# transform data structure from prometheus for good Kibana visualisation
parser:
patternFiles: []
patterns:
- # prometheus
sourceName: !!js/regexp /prometheus_metrics/
match:
- type: prometheus_metrics
regex: !!js/regexp /\sHELP|\sTYPE\s/i
inputDrop: !!js/regexp /#\sHELP|#\sTYPE\s/i
- type: prometheus_metrics
regex: !!js/regexp /(\S+)({.+?})\s([\d|\.]+)/i
fields:
- name
- labels
- value
transform: !!js/function >
function (p) {
try {
if (p.name) {
p.name_space=p.name.split('_')[0]
}
if (p.labels) {
// hack, make JS code out of key/value format to parse properties
p.labels = eval ('x=' + p.labels.replace(/=/g,':'))
var l = Object.keys(p.labels)
// convert prometheus numbers in quotes to JS numbers
for (var i=0; i<l.length; i++) {
var n = Number()
if (!isNaN(p.labels[l[i]])) {
p.labels[l[i]] = Number(p.labels[l[i]])
}
}
}
} catch (err) {
console.log(err)
}
p[p.name]=p.value
return p
}
- type: prometheus_metrics
regex: !!js/regexp /(\S+)\s([\d|\.]+)/i
fields:
- name
- value
transform: !!js/function >
function (p) {
if (p.name) {
p.name_space = p.name.split('_')[0]
}
p[p.name]=p.value
}
output:
stdout: yaml
logsene:
module: elasticsearch
url: https://logsene-receiver.sematext.com
# url: http://localhost:9200
index: LOGSENE_TOKEN_HERE
# index: prometheus_stats
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment