Skip to content

Instantly share code, notes, and snippets.

@B4dM4n
Created July 28, 2018 11:45
Show Gist options
  • Save B4dM4n/a24b9c27df4c54015e2630aaefd4eb29 to your computer and use it in GitHub Desktop.
Save B4dM4n/a24b9c27df4c54015e2630aaefd4eb29 to your computer and use it in GitHub Desktop.
A shell script to collect rclone memory stats that can be read by the prometheus node_exporter textfile module
#!/usr/bin/env zsh
set -euo pipefail
EXPORTER_DIR=/run/node_exporter_text
MOUNTS=(
"remote1: /mnt/remote1 127.0.0.1:5572"
"remote2: /mnt/remote2 127.0.0.1:5573"
)
function handle_mount() {
local src=$1
local dst=$2
local rc=$3
local p=$(rclone rc --rc-addr $rc core/pid | jq -r '.pid')
local sum=0
while read count type; do
((sum+=count))
echo 'rclone_lsof_mount{role="'$src'",mode="'${type:l}'"} '$count >> $EXPORTER_DIR/rclone.prom.$$
done < <(lsof $dst | tail -n+2 | awk '{print $5;}' | sort | uniq -c)
echo 'rclone_lsof_mount{role="'$src'",mode="all"} '$sum >> $EXPORTER_DIR/rclone.prom.$$
rclone rc --rc-addr $rc core/memstats | \
jq -r --arg role $src '. | to_entries | map("rclone_rc_memstats{role=\"\($role)\",mode=\"\(.key)\"} \(.value)") | join("\n")' >> $EXPORTER_DIR/rclone.prom.$$
while read mode value rest; do
echo "rclone_proc_status{role=\"$src\",mode=\"${mode%:}\"} $((value*1024))" >> $EXPORTER_DIR/rclone.prom.$$
done < <(egrep -e '^Vm' -e '^Rss' < /proc/$p/status)
}
for m in ${MOUNTS[@]}; do
handle_mount ${=m} || :
done
mv $EXPORTER_DIR/rclone.prom.$$ $EXPORTER_DIR/rclone.prom
[Unit]
Description=Node Exporter
[Service]
User=node_exporter
ExecStartPre=+/bin/mkdir -p /run/node_exporter_text
ExecStart=/usr/local/bin/node_exporter \
"--collector.filesystem.ignored-fs-types=^((sys|proc|auto)fs|fuse.*)$" \
"--collector.filesystem.ignored-mount-points=^/(sys|proc|dev|run/.*|var/lib/docker/.*)($|/)" \
"--collector.textfile.directory=/run/node_exporter_text"
Restart=on-failure
RestartSec=4s
[Install]
WantedBy=multi-user.target
[Unit]
Description=Collect rclone metrics
[Service]
ExecStart=/usr/local/bin/export_rclone.sh
[Unit]
Description=Collect rclone metrics timer
[Timer]
OnCalendar=*-*-* *:*:00,15,30,45
AccuracySec=2s
[Install]
WantedBy=multi-user.target
Rclone Prometheus memory stats
{
"__inputs": [
{
"name": "DS_PROMETHEUS",
"label": "prometheus",
"description": "",
"type": "datasource",
"pluginId": "prometheus",
"pluginName": "Prometheus"
}
],
"__requires": [
{
"type": "grafana",
"id": "grafana",
"name": "Grafana",
"version": "5.2.0-beta3"
},
{
"type": "panel",
"id": "graph",
"name": "Graph",
"version": "5.0.0"
},
{
"type": "datasource",
"id": "prometheus",
"name": "Prometheus",
"version": "5.0.0"
}
],
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": "-- Grafana --",
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"type": "dashboard"
}
]
},
"editable": true,
"gnetId": null,
"graphTooltip": 0,
"id": null,
"iteration": 1532777096043,
"links": [],
"panels": [
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "${DS_PROMETHEUS}",
"fill": 1,
"gridPos": {
"h": 9,
"w": 6,
"x": 0,
"y": 0
},
"id": 6,
"legend": {
"avg": false,
"current": false,
"max": false,
"min": false,
"show": true,
"total": false,
"values": false
},
"lines": true,
"linewidth": 1,
"links": [],
"nullPointMode": "null",
"percentage": false,
"pointradius": 5,
"points": false,
"renderer": "flot",
"repeat": "filter",
"repeatDirection": "h",
"seriesOverrides": [],
"spaceLength": 10,
"stack": false,
"steppedLine": false,
"targets": [
{
"expr": "rclone_lsof_mount{${filter:csv}}",
"format": "time_series",
"intervalFactor": 1,
"legendFormat": "{{mode}}",
"refId": "A"
}
],
"thresholds": [],
"timeFrom": null,
"timeShift": null,
"title": "Open Files",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
},
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "${DS_PROMETHEUS}",
"decimals": null,
"fill": 1,
"gridPos": {
"h": 9,
"w": 6,
"x": 0,
"y": 9
},
"id": 10,
"legend": {
"avg": false,
"current": true,
"max": false,
"min": false,
"show": true,
"total": false,
"values": true
},
"lines": true,
"linewidth": 1,
"links": [],
"nullPointMode": "null",
"percentage": false,
"pointradius": 5,
"points": false,
"renderer": "flot",
"repeat": "filter",
"repeatDirection": "h",
"seriesOverrides": [
{
"alias": "/VmRSS/",
"linewidth": 3
}
],
"spaceLength": 10,
"stack": false,
"steppedLine": false,
"targets": [
{
"expr": "rclone_proc_status{${filter:csv},mode!~'RssShmem|VmLck|VmPMD|VmStk|VmPin|VmPTE|VmLib|VmExe'}",
"format": "time_series",
"intervalFactor": 1,
"legendFormat": "{{mode}}",
"refId": "A"
}
],
"thresholds": [],
"timeFrom": null,
"timeShift": null,
"title": "Memory",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"format": "decbytes",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
},
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "${DS_PROMETHEUS}",
"fill": 1,
"gridPos": {
"h": 9,
"w": 6,
"x": 0,
"y": 18
},
"id": 17,
"legend": {
"avg": false,
"current": false,
"max": false,
"min": false,
"show": true,
"total": false,
"values": false
},
"lines": true,
"linewidth": 1,
"links": [],
"nullPointMode": "null",
"percentage": false,
"pointradius": 5,
"points": false,
"renderer": "flot",
"repeat": "filter",
"repeatDirection": "h",
"seriesOverrides": [
{
"alias": "/Heap(Alloc|Sys)/",
"linewidth": 3
}
],
"spaceLength": 10,
"stack": false,
"steppedLine": false,
"targets": [
{
"expr": "rclone_rc_memstats{${filter:csv},mode!~\"TotalAlloc|Frees|Mallocs\"}",
"format": "time_series",
"intervalFactor": 1,
"legendFormat": "{{mode}}",
"refId": "A"
}
],
"thresholds": [],
"timeFrom": null,
"timeShift": null,
"title": "Memstats",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"format": "decbytes",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
},
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "${DS_PROMETHEUS}",
"fill": 1,
"gridPos": {
"h": 9,
"w": 6,
"x": 0,
"y": 27
},
"id": 18,
"legend": {
"avg": false,
"current": false,
"max": false,
"min": false,
"show": true,
"total": false,
"values": false
},
"lines": true,
"linewidth": 1,
"links": [],
"nullPointMode": "null",
"percentage": false,
"pointradius": 5,
"points": false,
"renderer": "flot",
"repeat": "filter",
"repeatDirection": "h",
"seriesOverrides": [
{
"alias": "/Frees|Mallocs/",
"fill": 0,
"yaxis": 2
}
],
"spaceLength": 10,
"stack": false,
"steppedLine": false,
"targets": [
{
"expr": "rate(rclone_rc_memstats{${filter:csv},mode=\"TotalAlloc\"}[1m])",
"format": "time_series",
"intervalFactor": 1,
"legendFormat": "{{mode}}",
"refId": "A"
},
{
"expr": "rate(rclone_rc_memstats{${filter:csv},mode=~\"Frees|Mallocs\"}[1m])",
"format": "time_series",
"intervalFactor": 1,
"legendFormat": "{{mode}}",
"refId": "B"
}
],
"thresholds": [],
"timeFrom": null,
"timeShift": null,
"title": "Memstats Rates",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"format": "decbytes",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
}
],
"refresh": "1m",
"schemaVersion": 16,
"style": "dark",
"tags": [],
"templating": {
"list": [
{
"allValue": null,
"current": {},
"datasource": "${DS_PROMETHEUS}",
"hide": 0,
"includeAll": true,
"label": null,
"multi": true,
"name": "filter",
"options": [],
"query": "query_result(sum(rclone_lsof_mount) without (mode,group,job))",
"refresh": 1,
"regex": "/\\{([^}]+)\\}/",
"sort": 1,
"tagValuesQuery": "",
"tags": [],
"tagsQuery": "",
"type": "query",
"useTags": false
}
]
},
"time": {
"from": "now-24h",
"to": "now"
},
"timepicker": {
"refresh_intervals": [
"5s",
"10s",
"30s",
"1m",
"5m",
"15m",
"30m",
"1h",
"2h",
"1d"
],
"time_options": [
"5m",
"15m",
"1h",
"6h",
"12h",
"24h",
"2d",
"7d",
"30d"
]
},
"timezone": "",
"title": "rclone",
"uid": "ma_CZwNmz",
"version": 6
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment