1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-04-24 13:48:49 +08:00

NOISSUE - Add prometheus and grafana for metrics (#1753)

* add prometheus and grafana for metrics

Signed-off-by: SammyOina <sammyoina@gmail.com>

* add grafana tag
move prometheus metrics

Signed-off-by: SammyOina <sammyoina@gmail.com>

* add empty lines

Signed-off-by: SammyOina <sammyoina@gmail.com>

* add example dashboard

Signed-off-by: SammyOina <sammyoina@gmail.com>

* fix scraping path

Signed-off-by: SammyOina <sammyoina@gmail.com>

* add things metric to dashboard

Signed-off-by: SammyOina <sammyoina@gmail.com>

* change execution path

Signed-off-by: SammyOina <sammyoina@gmail.com>

* fix typo and switch from yaml to yml

Signed-off-by: SammyOina <sammyoina@gmail.com>

* update dashboard

Signed-off-by: SammyOina <sammyoina@gmail.com>

* update example dashboard

Signed-off-by: SammyOina <sammyoina@gmail.com>

* update dashboard

Signed-off-by: SammyOina <sammyoina@gmail.com>

* remove thresholds from gauges

Signed-off-by: SammyOina <sammyoina@gmail.com>

---------

Signed-off-by: SammyOina <sammyoina@gmail.com>
This commit is contained in:
Sammy Kerata Oina 2023-04-14 13:58:11 +03:00 committed by GitHub
parent b435b80d03
commit 0e3e716c48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 781 additions and 10 deletions

View File

@ -354,7 +354,6 @@ MF_SMTP_NOTIFIER_DB=subscriptions
MF_SMTP_NOTIFIER_TEMPLATE=smtp-notifier.tmpl
MF_SMTP_NOTIFIER_FROM_ADDR=from@example.com
### SMPP Notifier
MF_SMPP_NOTIFIER_PORT=9014
MF_SMPP_NOTIFIER_LOG_LEVEL=debug
@ -373,5 +372,11 @@ MF_SMPP_SRC_ADDR_NPI=0
MF_SMPP_DST_ADDR_TON=1
MF_SMPP_DST_ADDR_NPI=1
### GRAFANA and PROMETHEUS
MF_PROMETHEUS_PORT=9090
MF_GRAFANA_PORT=3000
MF_GRAFANA_ADMIN_USER=mainflux
MF_GRAFANA_ADMIN_PASSWORD=mainflux
# Docker image tag
MF_RELEASE_TAG=latest

View File

@ -0,0 +1,55 @@
# Copyright (c) Mainflux
# SPDX-License-Identifier: Apache-2.0
# This docker-compose file contains optional Prometheus and Grafana service for Mainflux platform.
# Since this service is optional, this file is dependent of docker-compose.yml file
# from <project_root>/docker. In order to run this service, execute command:
# docker-compose -f docker/addons/prometheus/docker-compose.yml up
# from project root.
version: "3.7"
networks:
docker_mainflux-base-net:
external: true
volumes:
mainflux-prometheus-volume:
services:
promethues:
image: prom/prometheus:v2.42.0
container_name: mainflux-prometheus
restart: on-failure
ports:
- ${MF_PROMETHEUS_PORT}:${MF_PROMETHEUS_PORT}
networks:
- docker_mainflux-base-net
volumes:
- type: bind
source: ./metrics/prometheus.yml
target: /etc/prometheus/prometheus.yml
- mainflux-prometheus-volume:/prometheus
grafana:
image: grafana/grafana:8.2.6
container_name: mainflux-grafana
depends_on:
- promethues
restart: on-failure
ports:
- ${MF_GRAFANA_PORT}:${MF_GRAFANA_PORT}
environment:
- GF_SECURITY_ADMIN_USER=${MF_GRAFANA_ADMIN_USER}
- GF_SECURITY_ADMIN_PASSWORD=${MF_GRAFANA_ADMIN_PASSWORD}
networks:
- docker_mainflux-base-net
volumes:
- type: bind
source: ./grafana/datasource.yml
target: /etc/grafana/provisioning/datasources/datasource.yml
- type: bind
source: ./grafana/dashboard.yml
target: /etc/grafana/provisioning/dashboards/main.yaml
- type: bind
source: ./grafana/example-dashboard.json
target: /var/lib/grafana/dashboards/example-dashboard.json

View File

@ -0,0 +1,12 @@
apiVersion: 1
providers:
- name: "Dashboard provider"
orgId: 1
type: file
disableDeletion: false
updateIntervalSeconds: 10
allowUiUpdates: false
options:
path: /var/lib/grafana/dashboards
foldersFromFilesStructure: true

View File

@ -0,0 +1,9 @@
apiVersion: 1
datasources:
- name: Prometheus
type: prometheus
url: http://mainflux-prometheus:9090
isDefault: true
access: proxy
editable: true

View File

@ -0,0 +1,679 @@
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": "-- Grafana --",
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"target": {
"limit": 100,
"matchAny": false,
"tags": [],
"type": "dashboard"
},
"type": "dashboard"
}
]
},
"editable": true,
"fiscalYearStartMonth": 0,
"gnetId": null,
"graphTooltip": 0,
"links": [],
"liveNow": false,
"panels": [
{
"datasource": "Prometheus",
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"mappings": [
{
"options": {
"0": {
"color": "red",
"index": 1,
"text": "down"
},
"1": {
"color": "green",
"index": 0,
"text": "up"
}
},
"type": "value"
}
],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "red",
"value": null
},
{
"color": "green",
"value": 1
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 4,
"w": 12,
"x": 0,
"y": 0
},
"id": 14,
"options": {
"colorMode": "value",
"graphMode": "none",
"justifyMode": "auto",
"orientation": "vertical",
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"text": {},
"textMode": "auto"
},
"pluginVersion": "8.2.6",
"targets": [
{
"exemplar": false,
"expr": "up{}",
"interval": "",
"intervalFactor": 2,
"legendFormat": "{{instance}}",
"refId": "A"
}
],
"title": "State",
"type": "stat"
},
{
"datasource": "Prometheus",
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
},
"unit": "bytes"
},
"overrides": []
},
"gridPos": {
"h": 4,
"w": 12,
"x": 12,
"y": 0
},
"id": 8,
"interval": "30s",
"options": {
"colorMode": "none",
"graphMode": "none",
"justifyMode": "auto",
"orientation": "auto",
"reduceOptions": {
"calcs": [
"last"
],
"fields": "",
"values": false
},
"text": {},
"textMode": "auto"
},
"pluginVersion": "8.2.6",
"targets": [
{
"exemplar": true,
"expr": "go_memstats_alloc_bytes{}",
"format": "time_series",
"instant": false,
"interval": "",
"intervalFactor": 10,
"legendFormat": "{{instance}}",
"refId": "A"
}
],
"timeFrom": null,
"title": "Allocated Bytes",
"type": "stat"
},
{
"datasource": "Prometheus",
"description": "",
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 22,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"lineInterpolation": "linear",
"lineWidth": 1,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "auto",
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 9,
"w": 24,
"x": 0,
"y": 4
},
"id": 4,
"interval": "15s",
"options": {
"legend": {
"calcs": [
"mean",
"sum",
"lastNotNull"
],
"displayMode": "table",
"placement": "bottom"
},
"tooltip": {
"mode": "multi"
}
},
"targets": [
{
"exemplar": true,
"expr": "promhttp_metric_handler_requests_total{}",
"hide": false,
"interval": "",
"intervalFactor": 2,
"legendFormat": "{{instance}} - Code {{code}}",
"refId": "A"
}
],
"timeFrom": null,
"title": "Total HTTP Requests",
"transformations": [],
"type": "timeseries"
},
{
"datasource": "Prometheus",
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 0,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"lineInterpolation": "linear",
"lineWidth": 1,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "auto",
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 24,
"x": 0,
"y": 13
},
"id": 2,
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom"
},
"tooltip": {
"mode": "single"
}
},
"targets": [
{
"exemplar": true,
"expr": "go_goroutines{}",
"interval": "",
"legendFormat": "{{instance}}",
"refId": "A"
}
],
"title": "Goroutines instaces",
"type": "timeseries"
},
{
"datasource": "Prometheus",
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 7,
"w": 8,
"x": 0,
"y": 21
},
"id": 16,
"options": {
"orientation": "auto",
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"showThresholdLabels": false,
"showThresholdMarkers": true,
"text": {}
},
"pluginVersion": "8.2.6",
"targets": [
{
"exemplar": true,
"expr": "auth_api_request_count{}",
"interval": "",
"legendFormat": "{{method}}",
"refId": "A"
}
],
"title": "Auth Request count",
"type": "gauge"
},
{
"datasource": "Prometheus",
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 7,
"w": 8,
"x": 8,
"y": 21
},
"id": 22,
"options": {
"orientation": "auto",
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"showThresholdLabels": false,
"showThresholdMarkers": true,
"text": {}
},
"pluginVersion": "8.2.6",
"targets": [
{
"exemplar": true,
"expr": "users_api_request_count{}",
"interval": "",
"legendFormat": "{{method}}",
"refId": "A"
}
],
"title": "Users Request Count",
"type": "gauge"
},
{
"datasource": "Prometheus",
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 7,
"w": 8,
"x": 16,
"y": 21
},
"id": 18,
"options": {
"orientation": "auto",
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"showThresholdLabels": false,
"showThresholdMarkers": true,
"text": {}
},
"pluginVersion": "8.2.6",
"targets": [
{
"exemplar": true,
"expr": "coap_adapter_api_request_count{}",
"interval": "",
"legendFormat": "{{method}}",
"refId": "A"
}
],
"title": "Coap Adapter Request Count",
"type": "gauge"
},
{
"datasource": "Prometheus",
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 7,
"w": 8,
"x": 0,
"y": 28
},
"id": 10,
"options": {
"orientation": "auto",
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"showThresholdLabels": false,
"showThresholdMarkers": true,
"text": {}
},
"pluginVersion": "8.2.6",
"targets": [
{
"exemplar": true,
"expr": "things_api_request_count{}",
"instant": false,
"interval": "",
"legendFormat": "{{method}}",
"refId": "A"
}
],
"title": "Things Request Count",
"type": "gauge"
},
{
"datasource": "Prometheus",
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 7,
"w": 8,
"x": 8,
"y": 28
},
"id": 20,
"options": {
"orientation": "auto",
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"showThresholdLabels": false,
"showThresholdMarkers": true,
"text": {}
},
"pluginVersion": "8.2.6",
"targets": [
{
"exemplar": true,
"expr": "ws_adapter_api_request_count{}",
"interval": "",
"legendFormat": "{{method}}",
"refId": "A"
}
],
"title": "Web Sockets Request Count",
"type": "gauge"
},
{
"datasource": "Prometheus",
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 7,
"w": 8,
"x": 16,
"y": 28
},
"id": 6,
"options": {
"orientation": "auto",
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"showThresholdLabels": false,
"showThresholdMarkers": true,
"text": {}
},
"pluginVersion": "8.2.6",
"targets": [
{
"exemplar": true,
"expr": "http_adapter_api_request_count{}",
"format": "time_series",
"instant": false,
"interval": "",
"legendFormat": "{{method}}",
"refId": "A"
}
],
"title": "HTTP Adapter Request Count",
"type": "gauge"
}
],
"refresh": "5s",
"schemaVersion": 32,
"style": "dark",
"tags": [],
"templating": {
"list": []
},
"time": {
"from": "now-5m",
"to": "now"
},
"timepicker": {},
"timezone": "",
"title": "mainflux",
"uid": "sgKwOwY4k",
"version": 7
}

View File

@ -0,0 +1,20 @@
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_configs:
- job_name: 'mainflux'
honor_timestamps: true
scrape_interval: 15s
scrape_timeout: 10s
metrics_path: /metrics
follow_redirects: true
enable_http2: true
static_configs:
- targets:
- mainflux-things:9000
- mainflux-users:9002
- mainflux-auth:9020
- mainflux-http:8008
- mainflux-ws:8186
- mainflux-coap:5683

View File

@ -1,9 +0,0 @@
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_configs:
- job_name: 'mainflux'
static_configs:
- targets: ['mainflux-things:9000', 'mainflux-users:9002', 'mainflux-auth:9020', 'mainflux-http:8008', 'mainflux-ws:8186','mainflux-coap:5683']