From 38867f0c679fd0364174e6013e790f295b01be44 Mon Sep 17 00:00:00 2001 From: usbharu Date: Mon, 7 Jul 2025 14:50:54 +0900 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E3=81=95=E3=82=8C=E3=81=A6?= =?UTF-8?q?=E3=81=84=E3=81=AA=E3=81=84=E3=83=A1=E3=83=88=E3=83=AA=E3=82=AF?= =?UTF-8?q?=E3=82=B9=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- collector.go | 39 +- dashboard.json | 1156 ++++++++++++++++++++++++++++++++++++++++++++++++ go.mod | 16 +- go.sum | 18 + main.go | 79 +--- prometheus.yml | 2 + 6 files changed, 1226 insertions(+), 84 deletions(-) create mode 100644 dashboard.json diff --git a/collector.go b/collector.go index a53e117..5121f72 100644 --- a/collector.go +++ b/collector.go @@ -6,7 +6,7 @@ import ( "github.com/sirupsen/logrus" "github.com/yitsushi/go-misskey/services/notes/timeline" "io" - "net/http" + "math" "time" ) @@ -79,20 +79,24 @@ func collectPing() { time.Sleep(5 * time.Second) var buf = bytes.NewBuffer([]byte(`{}`)) start := time.Now() - resp, err := http.Post(protocol+"://"+endpoint+"/api/ping", "application/json", buf) + resp, err := httpClient.Post(protocol+"://"+endpoint+"/api/ping", "application/json", buf) if err != nil { logrus.WithField("type", "ping").Warning(err) + misskeyPingResponseCode.Set(math.NaN()) + misskeyApiResponseTime.WithLabelValues("ping", "").Observe(math.NaN()) + misskeyApiResponseTimeRaw.WithLabelValues("ping", "").Set(math.NaN()) continue } err = resp.Body.Close() if err != nil { logrus.WithField("type", "ping").Warning(err) + misskeyPingResponseCode.Set(math.NaN()) + misskeyApiResponseTime.WithLabelValues("ping", "").Observe(math.NaN()) + misskeyApiResponseTimeRaw.WithLabelValues("ping", "").Set(math.NaN()) continue } misskeyPingResponseCode.Set(float64(resp.StatusCode)) t := float64(time.Since(start).Milliseconds()) / 1000 - misskeyPingResponseTime.Observe(t) - misskeyPingResponseTimeRaw.Set(t) misskeyApiResponseTime.WithLabelValues("ping", "").Observe(t) misskeyApiResponseTimeRaw.WithLabelValues("ping", "").Set(t) } @@ -104,6 +108,7 @@ func collectMeta() { meta, err := client.Meta().InstanceMeta(true) if err != nil { logrus.WithField("type", "meta").Warning(err) + misskeyMeta.WithLabelValues("UNKNOWN").Set(math.NaN()) continue } misskeyMeta.WithLabelValues(*meta.Version).Set(1) @@ -116,6 +121,10 @@ func collectStats() { stats, err := client.Meta().Stats() if err != nil { logrus.WithField("type", "stats").Warning(err) + misskeyNotesCount.Set(math.NaN()) + misskeyUsersCount.Set(math.NaN()) + misskeyOriginalNotesCount.Set(math.NaN()) + misskeyOriginalUsersCount.Set(math.NaN()) continue } misskeyNotesCount.Set(float64(stats.NotesCount)) @@ -132,7 +141,7 @@ type OnlineUsers struct { func collectOnlineUsers() { for { time.Sleep(1 * time.Minute) - response, err := http.Get(protocol + "://" + endpoint + "/api/get-online-users-count") + response, err := httpClient.Get(protocol + "://" + endpoint + "/api/get-online-users-count") if err != nil { logrus.WithField("type", "online-users").Warning(err) continue @@ -167,11 +176,12 @@ func collectTimeline() { global, err := client.Notes().Timeline().Global(timeline.GlobalRequest{Limit: 10}) if err != nil { logrus.WithField("type", "timeline").Warning(err) + misskeyApiResponseTime.WithLabelValues("timeline", "global").Observe(math.NaN()) + misskeyApiResponseTimeRaw.WithLabelValues("timeline", "global").Set(math.NaN()) + misskeyGlobalTimelineLastNotePublished.Set(math.NaN()) return } t := float64(time.Since(start).Milliseconds()) / 1000 - misskeyGlobalTimelineResponseTime.Observe(t) - misskeyGlobalTimelineResponseTimeRaw.Set(t) misskeyApiResponseTime.WithLabelValues("timeline", "global").Observe(t) misskeyApiResponseTimeRaw.WithLabelValues("timeline", "global").Set(t) if len(global) != 0 { @@ -183,11 +193,12 @@ func collectTimeline() { global, err := client.Notes().Timeline().Local(timeline.LocalRequest{Limit: 10}) if err != nil { logrus.WithField("type", "timeline").Warning(err) + misskeyApiResponseTime.WithLabelValues("timeline", "local").Observe(math.NaN()) + misskeyApiResponseTimeRaw.WithLabelValues("timeline", "local").Set(math.NaN()) + misskeyLocalTimelineLastNotePublished.Set(math.NaN()) return } t := float64(time.Since(start).Milliseconds()) / 1000 - misskeyLocalTimelineResponseTime.Observe(t) - misskeyLocalTimelineResponseTimeRaw.Set(t) misskeyApiResponseTime.WithLabelValues("timeline", "local").Observe(t) misskeyApiResponseTimeRaw.WithLabelValues("timeline", "local").Set(t) if len(global) != 0 { @@ -199,11 +210,12 @@ func collectTimeline() { global, err := client.Notes().Timeline().Get(timeline.GetRequest{Limit: 10}) if err != nil { logrus.WithField("type", "timeline").Warning(err) + misskeyApiResponseTime.WithLabelValues("timeline", "home").Observe(math.NaN()) + misskeyApiResponseTimeRaw.WithLabelValues("timeline", "home").Set(math.NaN()) + misskeyHomeTimelineLastNotePublished.Set(math.NaN()) return } t := float64(time.Since(start).Milliseconds()) / 1000 - misskeyHomeTimelineResponseTime.Observe(t) - misskeyHomeTimelineResponseTimeRaw.Set(t) misskeyApiResponseTime.WithLabelValues("timeline", "home").Observe(t) misskeyApiResponseTimeRaw.WithLabelValues("timeline", "home").Set(t) if len(global) != 0 { @@ -215,11 +227,12 @@ func collectTimeline() { global, err := client.Notes().Timeline().Hybrid(timeline.HybridRequest{Limit: 10}) if err != nil { logrus.WithField("type", "timeline").Warning(err) + misskeyApiResponseTime.WithLabelValues("timeline", "social").Observe(math.NaN()) + misskeyApiResponseTimeRaw.WithLabelValues("timeline", "social").Set(math.NaN()) + misskeySocialTimelineLastNotePublished.Set(math.NaN()) return } t := float64(time.Since(start).Milliseconds()) / 1000 - misskeySocialTimelineResponseTime.Observe(t) - misskeySocialTimelineResponseTimeRaw.Set(t) misskeyApiResponseTime.WithLabelValues("timeline", "social").Observe(t) misskeyApiResponseTimeRaw.WithLabelValues("timeline", "social").Set(t) if len(global) != 0 { diff --git a/dashboard.json b/dashboard.json new file mode 100644 index 0000000..6d8ee24 --- /dev/null +++ b/dashboard.json @@ -0,0 +1,1156 @@ +{ + "__inputs": [ + { + "name": "DS_PROMETHEUS", + "label": "prometheus", + "description": "", + "type": "datasource", + "pluginId": "prometheus", + "pluginName": "Prometheus" + } + ], + "__elements": {}, + "__requires": [ + { + "type": "grafana", + "id": "grafana", + "name": "Grafana", + "version": "11.6.0" + }, + { + "type": "datasource", + "id": "prometheus", + "name": "Prometheus", + "version": "1.0.0" + }, + { + "type": "panel", + "id": "stat", + "name": "Stat", + "version": "" + }, + { + "type": "panel", + "id": "timeseries", + "name": "Time series", + "version": "" + } + ], + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": { + "type": "grafana", + "uid": "-- Grafana --" + }, + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "type": "dashboard" + } + ] + }, + "editable": true, + "fiscalYearStartMonth": 0, + "graphTooltip": 2, + "id": null, + "links": [], + "panels": [ + { + "datasource": { + "uid": "${datasource}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green" + } + ] + } + }, + "overrides": [] + }, + "id": 12, + "options": { + "colorMode": "none", + "graphMode": "none", + "justifyMode": "center", + "orientation": "auto", + "percentChangeColorMode": "standard", + "reduceOptions": { + "calcs": [], + "fields": "", + "limit": 1, + "values": false + }, + "showPercentChange": false, + "textMode": "name", + "wideLayout": true + }, + "pluginVersion": "11.6.0", + "targets": [ + { + "disableTextWrap": false, + "editorMode": "code", + "expr": "misskey_meta", + "fullMetaSearch": false, + "includeNullMetadata": true, + "legendFormat": "{{version}}", + "range": true, + "refId": "A", + "useBackend": false, + "datasource": { + "uid": "${datasource}" + } + } + ], + "title": "Misskey Version", + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "decimals": 1, + "fieldMinMax": false, + "mappings": [], + "max": 100, + "min": 0, + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "red" + }, + { + "color": "green", + "value": 98 + } + ] + }, + "unit": "percent" + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 3, + "x": 6, + "y": 0 + }, + "id": 2, + "options": { + "colorMode": "value", + "graphMode": "area", + "justifyMode": "auto", + "orientation": "horizontal", + "percentChangeColorMode": "standard", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "showPercentChange": false, + "textMode": "value", + "wideLayout": true + }, + "pluginVersion": "11.6.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${datasource}" + }, + "disableTextWrap": false, + "editorMode": "code", + "exemplar": false, + "expr": "avg_over_time(clamp_max(count_over_time(misskey_ping_response_code{misskey_instance=\"$misskey_instance\"}[1m]), 1)[30d:1m]) * 100", + "format": "time_series", + "fullMetaSearch": false, + "includeNullMetadata": true, + "instant": false, + "legendFormat": "__auto", + "range": true, + "refId": "A", + "useBackend": false + } + ], + "title": "Availability(30d)", + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green" + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 3, + "x": 9, + "y": 0 + }, + "id": 5, + "options": { + "colorMode": "value", + "graphMode": "area", + "justifyMode": "auto", + "orientation": "auto", + "percentChangeColorMode": "standard", + "reduceOptions": { + "calcs": [ + "last" + ], + "fields": "", + "values": false + }, + "showPercentChange": false, + "textMode": "auto", + "wideLayout": true + }, + "pluginVersion": "11.6.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${datasource}" + }, + "disableTextWrap": false, + "editorMode": "builder", + "expr": "misskey_online_users{misskey_instance=\"$misskey_instance\"}", + "fullMetaSearch": false, + "includeNullMetadata": true, + "legendFormat": "__auto", + "range": true, + "refId": "A", + "useBackend": false + } + ], + "title": "Online Users", + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "fieldMinMax": true, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "text" + } + ] + }, + "unit": "none" + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 6, + "x": 12, + "y": 0 + }, + "id": 3, + "options": { + "colorMode": "value", + "graphMode": "area", + "justifyMode": "auto", + "orientation": "auto", + "percentChangeColorMode": "same_as_value", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "showPercentChange": true, + "textMode": "auto", + "wideLayout": true + }, + "pluginVersion": "11.6.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${datasource}" + }, + "disableTextWrap": false, + "editorMode": "builder", + "expr": "misskey_notes_count{misskey_instance=\"$misskey_instance\"}", + "fullMetaSearch": false, + "includeNullMetadata": true, + "instant": false, + "legendFormat": "All", + "range": true, + "refId": "A", + "useBackend": false + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "disableTextWrap": false, + "editorMode": "builder", + "exemplar": false, + "expr": "misskey_original_notes_count{misskey_instance=\"$misskey_instance\"}", + "fullMetaSearch": false, + "hide": false, + "includeNullMetadata": true, + "instant": false, + "legendFormat": "Local", + "range": true, + "refId": "B", + "useBackend": false + } + ], + "title": "Note Count", + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${datasource}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "fieldMinMax": true, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "text" + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 6, + "x": 18, + "y": 0 + }, + "id": 4, + "options": { + "colorMode": "value", + "graphMode": "area", + "justifyMode": "auto", + "orientation": "auto", + "percentChangeColorMode": "same_as_value", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "showPercentChange": true, + "textMode": "auto", + "wideLayout": true + }, + "pluginVersion": "11.6.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "disableTextWrap": false, + "editorMode": "builder", + "expr": "misskey_users_count{misskey_instance=\"$misskey_instance\"}", + "fullMetaSearch": false, + "includeNullMetadata": true, + "legendFormat": "All", + "range": true, + "refId": "A", + "useBackend": false + }, + { + "datasource": { + "type": "prometheus", + "uid": "${datasource}" + }, + "disableTextWrap": false, + "editorMode": "builder", + "expr": "misskey_original_users_count{misskey_instance=\"$misskey_instance\"}", + "fullMetaSearch": false, + "hide": false, + "includeNullMetadata": true, + "instant": false, + "legendFormat": "Local", + "range": true, + "refId": "B", + "useBackend": false + } + ], + "title": "User Count", + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "fieldMinMax": false, + "mappings": [ + { + "options": { + "0": { + "index": 1, + "text": "DOWN" + }, + "1": { + "index": 0, + "text": "UP" + } + }, + "type": "value" + } + ], + "noValue": "UNKNOWN", + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "red" + }, + { + "color": "red", + "value": 0 + }, + { + "color": "green", + "value": 1 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 3, + "w": 3, + "x": 0, + "y": 3 + }, + "id": 1, + "options": { + "colorMode": "background_solid", + "graphMode": "none", + "justifyMode": "center", + "orientation": "auto", + "percentChangeColorMode": "standard", + "reduceOptions": { + "calcs": [ + "last" + ], + "fields": "", + "values": false + }, + "showPercentChange": false, + "textMode": "value", + "wideLayout": true + }, + "pluginVersion": "11.6.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${datasource}" + }, + "disableTextWrap": false, + "editorMode": "builder", + "expr": "clamp_max(count_over_time(misskey_ping_response_code{misskey_instance=\"$misskey_instance\"}[1m]), 1)", + "fullMetaSearch": false, + "includeNullMetadata": true, + "legendFormat": "__auto", + "range": true, + "refId": "A", + "useBackend": false + } + ], + "title": "Health", + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "fieldMinMax": false, + "mappings": [ + { + "options": { + "0": { + "index": 1, + "text": "DOWN" + }, + "1": { + "index": 0, + "text": "UP" + } + }, + "type": "value" + } + ], + "noValue": "UNKNOWN", + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "red" + }, + { + "color": "red", + "value": 0 + }, + { + "color": "green", + "value": 1 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 3, + "w": 3, + "x": 3, + "y": 3 + }, + "id": 7, + "options": { + "colorMode": "background_solid", + "graphMode": "none", + "justifyMode": "center", + "orientation": "auto", + "percentChangeColorMode": "standard", + "reduceOptions": { + "calcs": [ + "last" + ], + "fields": "", + "values": false + }, + "showPercentChange": false, + "textMode": "value", + "wideLayout": true + }, + "pluginVersion": "11.6.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${datasource}" + }, + "disableTextWrap": false, + "editorMode": "builder", + "expr": "up{misskey_instance=\"$misskey_instance\"}", + "fullMetaSearch": false, + "includeNullMetadata": true, + "legendFormat": "__auto", + "range": true, + "refId": "A", + "useBackend": false + } + ], + "title": "Exporter Health", + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "barWidthFactor": 0.6, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineStyle": { + "fill": "solid" + }, + "lineWidth": 1, + "pointSize": 1, + "scaleDistribution": { + "log": 2, + "type": "log" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "dashed+area" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green" + }, + { + "color": "#EAB839", + "value": 0.2 + }, + { + "color": "orange", + "value": 1 + }, + { + "color": "red", + "value": 2 + } + ] + }, + "unit": "s" + }, + "overrides": [] + }, + "gridPos": { + "h": 11, + "w": 12, + "x": 0, + "y": 6 + }, + "id": 6, + "options": { + "legend": { + "calcs": [ + "last", + "min", + "max", + "median" + ], + "displayMode": "table", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "hideZeros": false, + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "11.6.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${datasource}" + }, + "disableTextWrap": false, + "editorMode": "builder", + "exemplar": false, + "expr": "histogram_quantile(0.99, sum by(api, type, le) (rate(misskey_api_response_time_bucket{misskey_instance=\"$misskey_instance\"}[$__rate_interval])))", + "format": "time_series", + "fullMetaSearch": false, + "hide": false, + "includeNullMetadata": false, + "instant": false, + "interval": "", + "legendFormat": "{{api}} {{type}}", + "range": true, + "refId": "A", + "useBackend": false + } + ], + "title": "API Response Time(99%PCTL)", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "barWidthFactor": 0.6, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineStyle": { + "fill": "solid" + }, + "lineWidth": 1, + "pointSize": 1, + "scaleDistribution": { + "log": 2, + "type": "log" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "dashed+area" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green" + }, + { + "color": "#EAB839", + "value": 0.2 + }, + { + "color": "orange", + "value": 1 + }, + { + "color": "red", + "value": 2 + } + ] + }, + "unit": "s" + }, + "overrides": [] + }, + "gridPos": { + "h": 11, + "w": 12, + "x": 12, + "y": 6 + }, + "id": 8, + "options": { + "legend": { + "calcs": [ + "last", + "min", + "max", + "median" + ], + "displayMode": "table", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "hideZeros": false, + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "11.6.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${datasource}" + }, + "disableTextWrap": false, + "editorMode": "builder", + "expr": "misskey_api_response_time_raw{misskey_instance=\"$misskey_instance\"}", + "fullMetaSearch": false, + "hide": false, + "includeNullMetadata": false, + "instant": false, + "legendFormat": "{{api}} {{type}}", + "range": true, + "refId": "A", + "useBackend": false + } + ], + "title": "API Response Time(RAW)", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green" + }, + { + "color": "orange", + "value": 1 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 17 + }, + "id": 9, + "options": { + "colorMode": "value", + "graphMode": "area", + "justifyMode": "auto", + "orientation": "auto", + "percentChangeColorMode": "standard", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "showPercentChange": false, + "textMode": "value_and_name", + "wideLayout": true + }, + "pluginVersion": "11.6.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${datasource}" + }, + "disableTextWrap": false, + "editorMode": "builder", + "expr": "sum by(status) (misskey_jobqueue_jobs{type=\"deliver\", misskey_instance=\"$misskey_instance\"})", + "fullMetaSearch": false, + "includeNullMetadata": true, + "legendFormat": "{{type}} {{status}}", + "range": true, + "refId": "A", + "useBackend": false + } + ], + "title": "Deliver", + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green" + }, + { + "color": "orange", + "value": 1 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 17 + }, + "id": 10, + "options": { + "colorMode": "value", + "graphMode": "area", + "justifyMode": "auto", + "orientation": "auto", + "percentChangeColorMode": "standard", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "showPercentChange": false, + "textMode": "value_and_name", + "wideLayout": true + }, + "pluginVersion": "11.6.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${datasource}" + }, + "disableTextWrap": false, + "editorMode": "builder", + "expr": "sum by(status) (misskey_jobqueue_jobs{type=\"inbox\", misskey_instance=\"$misskey_instance\"})", + "fullMetaSearch": false, + "includeNullMetadata": true, + "legendFormat": "{{type}} {{status}}", + "range": true, + "refId": "A", + "useBackend": false + } + ], + "title": "Inbox", + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "barWidthFactor": 0.6, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "dashed+area" + } + }, + "decimals": 0, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green" + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "none" + }, + "overrides": [] + }, + "gridPos": { + "h": 18, + "w": 24, + "x": 0, + "y": 25 + }, + "id": 11, + "options": { + "legend": { + "calcs": [ + "max" + ], + "displayMode": "table", + "placement": "right", + "showLegend": true + }, + "tooltip": { + "hideZeros": false, + "mode": "multi", + "sort": "desc" + } + }, + "pluginVersion": "11.6.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${datasource}" + }, + "disableTextWrap": false, + "editorMode": "builder", + "expr": "misskey_jobqueue_jobs{misskey_instance=\"$misskey_instance\"}", + "fullMetaSearch": false, + "includeNullMetadata": true, + "interval": "1", + "legendFormat": "{{type}} {{status}}", + "range": true, + "refId": "A", + "useBackend": false + } + ], + "title": "Job Queue", + "type": "timeseries" + } + ], + "refresh": "auto", + "schemaVersion": 41, + "tags": [], + "templating": { + "list": [ + { + "current": {}, + "name": "datasource", + "options": [], + "query": "prometheus", + "refresh": 1, + "regex": "", + "type": "datasource" + }, + { + "current": {}, + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "definition": "label_values(misskey_instance)", + "description": "", + "name": "misskey_instance", + "options": [], + "query": { + "qryType": 1, + "query": "label_values(misskey_instance)", + "refId": "PrometheusVariableQueryEditor-VariableQuery" + }, + "refresh": 1, + "regex": "", + "type": "query" + } + ] + }, + "time": { + "from": "now-3h", + "to": "now" + }, + "timepicker": {}, + "timezone": "browser", + "title": "Misskey", + "uid": "eej5avfu4yyo0f", + "version": 30, + "weekStart": "" +} \ No newline at end of file diff --git a/go.mod b/go.mod index 9ea6229..15550a8 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.23.0 toolchain go1.23.3 require ( + github.com/prometheus/client_golang v1.22.0 github.com/sirupsen/logrus v1.9.3 github.com/yitsushi/go-misskey v1.1.6 ) @@ -12,13 +13,12 @@ require ( require ( github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect - github.com/klauspost/compress v1.17.9 // indirect + github.com/klauspost/compress v1.18.0 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect - github.com/prometheus/client_golang v1.20.5 // indirect - github.com/prometheus/client_model v0.6.1 // indirect - github.com/prometheus/common v0.55.0 // indirect - github.com/prometheus/procfs v0.15.1 // indirect - golang.org/x/net v0.39.0 // indirect - golang.org/x/sys v0.32.0 // indirect - google.golang.org/protobuf v1.34.2 // indirect + github.com/prometheus/client_model v0.6.2 // indirect + github.com/prometheus/common v0.65.0 // indirect + github.com/prometheus/procfs v0.17.0 // indirect + golang.org/x/net v0.41.0 // indirect + golang.org/x/sys v0.33.0 // indirect + google.golang.org/protobuf v1.36.6 // indirect ) diff --git a/go.sum b/go.sum index d7575a0..2c7310f 100644 --- a/go.sum +++ b/go.sum @@ -7,18 +7,30 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA= github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= +github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo= +github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+bR9r+8l63Y= github.com/prometheus/client_golang v1.20.5/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE= +github.com/prometheus/client_golang v1.22.0 h1:rb93p9lokFEsctTys46VnV1kLCDpVZ0a/Y92Vm0Zc6Q= +github.com/prometheus/client_golang v1.22.0/go.mod h1:R7ljNsLXhuQXYZYtw6GAE9AZg8Y7vEW5scdCXrWRXC0= github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E= github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= +github.com/prometheus/client_model v0.6.2 h1:oBsgwpGs7iVziMvrGhE53c/GrLUsZdHnqNwqPLxwZyk= +github.com/prometheus/client_model v0.6.2/go.mod h1:y3m2F6Gdpfy6Ut/GBsUqTWZqCUvMVzSfMLjcu6wAwpE= github.com/prometheus/common v0.55.0 h1:KEi6DK7lXW/m7Ig5i47x0vRzuBsHuvJdi5ee6Y3G1dc= github.com/prometheus/common v0.55.0/go.mod h1:2SECS4xJG1kd8XF9IcM1gMX6510RAEL65zxzNImwdc8= +github.com/prometheus/common v0.65.0 h1:QDwzd+G1twt//Kwj/Ww6E9FQq1iVMmODnILtW1t2VzE= +github.com/prometheus/common v0.65.0/go.mod h1:0gZns+BLRQ3V6NdaerOhMbwwRbNh9hkGINtQAsP5GS8= github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= +github.com/prometheus/procfs v0.16.1 h1:hZ15bTNuirocR6u0JZ6BAHHmwS1p8B4P6MRqxtzMyRg= +github.com/prometheus/procfs v0.16.1/go.mod h1:teAbpZRB1iIAJYREa1LsoWUXykVXA1KlTmWl8x/U+Is= +github.com/prometheus/procfs v0.17.0 h1:FuLQ+05u4ZI+SS/w9+BWEM2TXiHKsUQ9TADiRH7DuK0= +github.com/prometheus/procfs v0.17.0/go.mod h1:oPQLaDAMRbA+u8H5Pbfq+dl3VDAvHxMUOVhe0wYB2zw= github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM= github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= @@ -36,6 +48,8 @@ golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ= golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= golang.org/x/net v0.39.0 h1:ZCu7HMWDxpXpaiKdhzIfaltL9Lp31x/3fCP11bc6/fY= golang.org/x/net v0.39.0/go.mod h1:X7NRbYVEA+ewNkCNyJ513WmMdQ3BineSwVtN2zD/d+E= +golang.org/x/net v0.41.0 h1:vBTly1HeNPEn3wtREYfy4GZ/NECgw2Cnl+nK6Nz3uvw= +golang.org/x/net v0.41.0/go.mod h1:B/K4NNqkfmg07DQYrbwvSluqCJOOXwUjeb/5lOisjbA= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= @@ -44,8 +58,12 @@ golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20= golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw= +golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= +google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY= +google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0 h1:hjy8E9ON/egN1tAYqKb61G10WtihqetD4sz2H+8nIeA= diff --git a/main.go b/main.go index d36dea7..8063263 100644 --- a/main.go +++ b/main.go @@ -5,9 +5,11 @@ import ( "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/sirupsen/logrus" "github.com/yitsushi/go-misskey" + "net" "net/http" "os" "strings" + "time" ) //TIP

To run your code, right-click the code and select Run.

Alternatively, click @@ -22,6 +24,17 @@ var path = os.Getenv("MISSKEY_PATH") var apiKey = os.Getenv("MISSKEY_API_TOKEN") var logLevelEnv = os.Getenv("LOGGER_LEVEL") var logFormatEnv = os.Getenv("LOGGER_FORMAT") +var httpClient = &http.Client{ + Timeout: 5 * time.Second, + Transport: &http.Transport{ + DialContext: (&net.Dialer{ + Timeout: time.Second, + }).DialContext, + TLSHandshakeTimeout: time.Second, + ResponseHeaderTimeout: time.Second, + IdleConnTimeout: time.Second, + }, +} var ( misskeyJobQueueJobsCount = prometheus.NewGaugeVec( @@ -61,35 +74,13 @@ var ( Help: "Original Users Coount", }, ) - misskeyPingResponseTimeRaw = prometheus.NewGauge( - prometheus.GaugeOpts{ - Name: "misskey_ping_response_time_raw", - Help: "Response Time for misskey Ping", - }, - ) - misskeyPingResponseTime = prometheus.NewHistogram( - prometheus.HistogramOpts{ - Name: "misskey_ping_response_time", - Help: "Response Time for misskey Ping", - Buckets: prometheus.DefBuckets, - }, - ) misskeyPingResponseCode = prometheus.NewGauge( prometheus.GaugeOpts{ Name: "misskey_ping_response_code", Help: "Response Code for misskey Ping", }, ) - misskeyGlobalTimelineResponseTime = prometheus.NewHistogram( - prometheus.HistogramOpts{ - Name: "misskey_global_timeline_response_time", - Help: "Response Time for misskey Global Timeline", - }) - misskeyLocalTimelineResponseTime = prometheus.NewHistogram( - prometheus.HistogramOpts{ - Name: "misskey_local_timeline_response_time", - Help: "Response Time for misskey Local Timeline", - }) + misskeyGlobalTimelineLastNotePublished = prometheus.NewGauge( prometheus.GaugeOpts{ Name: "misskey_global_timeline_last_note_published", @@ -100,42 +91,14 @@ var ( Name: "misskey_local_timeline_last_note_published", Help: "Last Note Published on Local Timeline", }) - misskeyGlobalTimelineResponseTimeRaw = prometheus.NewGauge( - prometheus.GaugeOpts{ - Name: "misskey_global_timeline_response_time_raw", - Help: "Response Time for misskey Global Timeline", - }) - misskeyLocalTimelineResponseTimeRaw = prometheus.NewGauge( - prometheus.GaugeOpts{ - Name: "misskey_local_timeline_response_time_raw", - Help: "Response Time for misskey Local Timeline", - }) - misskeyHomeTimelineResponseTime = prometheus.NewHistogram( - prometheus.HistogramOpts{ - Name: "misskey_home_timeline_response_time", - Help: "Response Time for misskey Home Timeline", - }) - misskeyHomeTimelineResponseTimeRaw = prometheus.NewGauge( - prometheus.GaugeOpts{ - Name: "misskey_home_timeline_response_time_raw", - Help: "Response Time for misskey Home Timeline", - }) + misskeyHomeTimelineLastNotePublished = prometheus.NewGauge( prometheus.GaugeOpts{ Name: "misskey_home_timeline_last_note_published", Help: "Last Note Published on Home Timeline", }, ) - misskeySocialTimelineResponseTime = prometheus.NewHistogram( - prometheus.HistogramOpts{ - Name: "misskey_social_timeline_response_time", - Help: "Response Time for misskey Home Timeline", - }) - misskeySocialTimelineResponseTimeRaw = prometheus.NewGauge( - prometheus.GaugeOpts{ - Name: "misskey_social_timeline_response_time_raw", - Help: "Response Time for misskey Home Timeline", - }) + misskeySocialTimelineLastNotePublished = prometheus.NewGauge( prometheus.GaugeOpts{ Name: "misskey_social_timeline_last_note_published", @@ -219,20 +182,10 @@ func main() { prometheus.MustRegister(misskeyUsersCount) prometheus.MustRegister(misskeyOriginalNotesCount) prometheus.MustRegister(misskeyOriginalUsersCount) - prometheus.MustRegister(misskeyPingResponseTime) - prometheus.MustRegister(misskeyPingResponseTimeRaw) prometheus.MustRegister(misskeyPingResponseCode) - prometheus.MustRegister(misskeyGlobalTimelineResponseTime) - prometheus.MustRegister(misskeyLocalTimelineResponseTime) prometheus.MustRegister(misskeyGlobalTimelineLastNotePublished) prometheus.MustRegister(misskeyLocalTimelineLastNotePublished) - prometheus.MustRegister(misskeyGlobalTimelineResponseTimeRaw) - prometheus.MustRegister(misskeyLocalTimelineResponseTimeRaw) - prometheus.MustRegister(misskeyHomeTimelineResponseTime) - prometheus.MustRegister(misskeyHomeTimelineResponseTimeRaw) prometheus.MustRegister(misskeyHomeTimelineLastNotePublished) - prometheus.MustRegister(misskeySocialTimelineResponseTime) - prometheus.MustRegister(misskeySocialTimelineResponseTimeRaw) prometheus.MustRegister(misskeySocialTimelineLastNotePublished) prometheus.MustRegister(misskeyApiResponseTime) prometheus.MustRegister(misskeyApiResponseTimeRaw) diff --git a/prometheus.yml b/prometheus.yml index a9fb7ab..1258ad2 100644 --- a/prometheus.yml +++ b/prometheus.yml @@ -5,5 +5,7 @@ scrape_configs: - job_name: 'process_exporter' static_configs: - targets: ['misskey-exporter:8080'] + labels: + misskey_instance: misskey.usbharu.dev rule_files: - rules.yaml \ No newline at end of file