Prometheus and Grafana for Object Stores
This page shows how to collect each object store's metrics with Prometheus and Grafanagraph them in Grafana.
Why Prometheus needs a small exporter
Prometheus can't scrape the StorONE REST API directly, for Objecttwo Storesreasons:
POST /login, sent as Authorization: Bearer <token>, and sessions end after a period of inactivity (see Authentication).
No metrics on the data network. Nothing on a store's floating IP serves metrics to a scraper (see Network exposure).
The approach is a small exporter: a service that logs in to the REST API, fetches each store's metrics as Prometheus text, and serves it to Prometheus.
Prometheus → exporter (
/probe?target=<Application>/<Volume>) → StorONE REST API (log in, fetch metrics) → Grafana dashboards and alerts
Setting up the exporter
Create a dedicated StorONE user for monitoring, with the least privilege that can run applications objects stores metrics. Don't reuse an administrator account.
Save the script below as s1_s3_exporter.py on a host that can reach the StorONE management IP, for example the Prometheus server. It needs Python 3 and no extra packages. It logs in, logs in again when the session ends, and serves the metrics as plain text.
Set the environment variables S1_MGMT (for example https://10.0.0.10), S1_USER and S1_PASSWORD. Optionally set PORT (default 9105). If the management interface uses a certificate the exporter host can't verify, either point S1_CA at the CA certificate file, or set S1_SKIP_VERIFY=1, which is the same as curl -k.
Run it as a service (for example a systemd unit), and keep the password in a protected environment file rather than on the command line.
Test it:
curl 'http://localhost:9105/probe?target=Backup/ObjVol1'
The answer should be Prometheus text. Note the metric names it shows; you'll use them in Grafana. If something's wrong, the exporter answers with HTTP 500 and a # scrape failed: line that says why, for example a login failure or the error StorONE returned for an unknown application or volume.
s1_s3_exporter.py
#!/usr/bin/env python3
"""Expose StorONE S1 object-store metrics to Prometheus (multi-target exporter).
Prometheus scrapes /probe?target=<Application>/<Volume> on this exporter; the
exporter logs in to the S1 REST API, fetches that store's metrics as Prometheus
text, and returns them. Standard library only.
"""
import json, os, re, ssl, threading, urllib.error, urllib.parse, urllib.request
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
S1 = os.environ["S1_MGMT"].rstrip("/") # e.g. https://10.0.0.10
USER, PWD = os.environ["S1_USER"], os.environ["S1_PASSWORD"]
CTX = ssl.create_default_context(cafile=os.environ.get("S1_CA")) # optional CA file
if os.environ.get("S1_SKIP_VERIFY") == "1": # same as curl -k
CTX.check_hostname, CTX.verify_mode = False, ssl.CERT_NONE
_lock = threading.Lock()
_token = None
# A sample line of Prometheus text: metric_name{labels} <number> [timestamp]
_SAMPLE = re.compile(r"^[A-Za-z_:][A-Za-z0-9_:]*(\{[^}]*\})?[ \t]+"
r"[-+]?(?:\d+(?:\.\d*)?(?:[eE][-+]?\d+)?|\.\d+|NaN|Inf)(?:[ \t]+-?\d+)?[ \t]*$", re.M)
def _login():
body = json.dumps({"Username": USER, "Password": PWD}).encode()
req = urllib.request.Request(S1 + "/login", data=body, method="POST",
headers={"Content-Type": "application/json"})
try:
with urllib.request.urlopen(req, context=CTX, timeout=20) as r:
res = json.load(r)
except urllib.error.HTTPError as e: # 401 = wrong user/password etc.
raise RuntimeError(f"login failed: HTTP {e.code}") from None
token = res.get("SessionToken")
if not token:
raise RuntimeError(f"login failed: {res.get('Status')} {res.get('ErrorMessage') or ''}".strip())
return token
def _token_for(stale=None):
"""Return a session token, logging in again if `stale` is the current one."""
global _token
with _lock:
if _token is None or _token == stale:
_token = _login()
return _token
def _get_text(path, token):
req = urllib.request.Request(S1 + path, headers={"Authorization": "Bearer " + token})
try:
with urllib.request.urlopen(req, context=CTX, timeout=20) as r:
return r.status, r.read().decode("utf-8", "replace")
except urllib.error.HTTPError as e:
return e.code, e.read().decode("utf-8", "replace")
def store_metrics(app, vol):
# With outputType=Prometheus the response body is the raw Prometheus text,
# not the JSON envelope. Errors other than authentication still return HTTP 200,
# so a body without any metric lines is treated as an error.
q = urllib.parse.urlencode({"application": app, "volume": vol, "outputType": "Prometheus"})
path = "/applications/objects/stores/metrics?" + q
token = _token_for()
for attempt in (1, 2):
code, text = _get_text(path, token)
if code == 200 and _SAMPLE.search(text):
return text
if attempt == 1 and code in (200, 401): # expired or ended session: log in once more
token = _token_for(stale=token)
continue
detail = " ".join(text.split())[:200] or "empty response"
raise RuntimeError(f"HTTP {code}: {detail}")
class Handler(BaseHTTPRequestHandler):
def do_GET(self):
url = urllib.parse.urlparse(self.path)
if url.path != "/probe":
self.send_error(404)
return
target = urllib.parse.parse_qs(url.query).get("target", [""])[0] # "App/Volume"
try:
app, vol = target.split("/", 1)
if not app or not vol:
raise ValueError("target must be Application/Volume")
body, code = store_metrics(app, vol), 200
except Exception as e:
body, code = f"# scrape failed: {e}\n", 500
data = body.encode()
self.send_response(code)
self.send_header("Content-Type", "text/plain; version=0.0.4")
self.send_header("Content-Length", str(len(data)))
self.end_headers()
self.wfile.write(data)
def log_message(self, fmt, *args): # keep the service log quiet
pass
if __name__ == "__main__":
ThreadingHTTPServer(("", int(os.environ.get("PORT", "9105"))), Handler).serve_forever()
Configuring Prometheus
Each store is one target, written as Application/Volume. The relabelling below passes the target to the exporter and keeps it as a store label, so metrics from different stores never collide.
prometheus.yml
scrape_configs:
- job_name: s1-object-stores
metrics_path: /probe
scrape_interval: 30s
static_configs:
- targets: ["Backup/ObjVol1", "Archive/ObjVolA"] # one entry per object store
labels:
s1_system: s1-prod-01
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__address__]
target_label: store
- target_label: __address__
replacement: localhost:9105 # where the exporter runs
Scraping every 30 seconds also keeps the exporter's StorONE session active. Add a target whenever you create a store. A store that's deleted or not running makes its target fail (up == 0), which is a useful alert in itself.
Building Grafana dashboards
store variable (query: label_values(up{job="s1-object-stores"}, store)), so one dashboard serves every store.
Add panels using the metric names you noted when testing the exporter. Useful starting points:
rate() over the request counter, summed by the operation and bucket labels.
Throughput: rate() over the bytes-transferred counters.
Latency: the latency metric per operation (GET and PUT behave very differently).
Errors: rate() over the error counters, as a share of all requests.
Store up: up{job="s1-object-stores", store="$store"}.
Add alerts for: store target down, error rate above your baseline, and latency above your service level.
Remember that these metrics describe S3 traffic. Watch the store's capacity separately (see Monitoring object stores).