Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5306,6 +5306,225 @@
}
],
"type": "timeseries"
},
{
"collapsed": true,
"gridPos": {
"h": 1,
"w": 24,
"x": 0,
"y": 206
},
"id": 137,
"panels": [
{
"datasource": {
"type": "prometheus",
"uid": "${DataSource}"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisBorderShow": false,
"axisCenteredZero": false,
"axisLabel": "Duration (seconds)",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 20,
"gradientMode": "none",
"lineInterpolation": "smooth",
"lineWidth": 2,
"pointSize": 5,
"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
}
]
},
"unit": "s"
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 24,
"x": 0,
"y": 207
},
"id": 138,
"options": {
"legend": {
"calcs": [
"mean",
"max"
],
"displayMode": "table",
"placement": "bottom"
},
"tooltip": {
"mode": "single",
"sort": "none"
}
},
"title": "CMD Duration (p95)",
"type": "timeseries",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "${DataSource}"
},
"expr": "histogram_quantile(0.95, sum(rate(app_cmd_duration_seconds_bucket{app_name=~\"$Service\"}[5m])) by (le, command))",
"legendFormat": "{{command}}",
"refId": "A"
}
]
},
{
"datasource": {
"type": "prometheus",
"uid": "${DataSource}"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 215
},
"id": 139,
"options": {
"colorMode": "value",
"graphMode": "area",
"justifyMode": "auto",
"orientation": "auto",
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"textMode": "auto"
},
"title": "CMD Success Total",
"type": "stat",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "${DataSource}"
},
"expr": "sum(app_cmd_success_total{app_name=~\"$Service\"}) by (command)",
"legendFormat": "{{command}}",
"refId": "A"
}
]
},
{
"datasource": {
"type": "prometheus",
"uid": "${DataSource}"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 1
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 215
},
"id": 140,
"options": {
"colorMode": "value",
"graphMode": "area",
"justifyMode": "auto",
"orientation": "auto",
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"textMode": "auto"
},
"title": "CMD Errors Total",
"type": "stat",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "${DataSource}"
},
"expr": "sum(app_cmd_errors_total{app_name=~\"$Service\"}) by (command)",
"legendFormat": "{{command}}",
"refId": "A"
}
]
}
],
"title": "CMD Metrics",
"type": "row"
}
],
"refresh": "5s",
Expand Down
25 changes: 25 additions & 0 deletions examples/sample-cmd/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Build stage
FROM golang:1.25-alpine AS build
RUN apk add --no-cache build-base

WORKDIR /src

# Copy go.mod + go.sum first for better caching
COPY go.mod go.sum ./
RUN go mod download

# Copy the rest of the source code
COPY . .

# Move into sample-cmd folder and build the package
WORKDIR /src/examples/sample-cmd
RUN CGO_ENABLED=0 go build -a -o /app/main .

# Final stage
FROM alpine:3.14
RUN apk add --no-cache tzdata ca-certificates
COPY --from=build /app/main /main
COPY --from=build /src/examples/sample-cmd/configs /configs

ENTRYPOINT ["/main"]
CMD ["hello"]
2 changes: 2 additions & 0 deletions examples/sample-cmd/configs/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
APP_NAME=sample-cmd
CMD_LOGS_FILE=logs.txt
53 changes: 53 additions & 0 deletions examples/sample-cmd/docker/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Grafana dashboard for CMD metrics is also available in
# examples/http-server/docker/provisioning/dashboards/gofr-dashboard/dashboards.json
# under the "CMD Metrics" row.

version: '3.8'

services:
sample-cmd:
build:
context: ../../../ # project root (so go.mod and go.sum are included)
dockerfile: examples/sample-cmd/Dockerfile
environment:
APP_NAME: sample-cmd
METRICS_PUSH_GATEWAY_URL: http://pushgateway:9091
depends_on:
- pushgateway
networks:
- gofr-network

pushgateway:
image: prom/pushgateway:latest
ports:
- "9091:9091"
networks:
- gofr-network

prometheus:
image: prom/prometheus:latest
ports:
- "9090:9090"
volumes:
- ./prometheus:/etc/prometheus
depends_on:
- pushgateway
networks:
- gofr-network

grafana:
image: grafana/grafana:latest
ports:
- "3000:3000"
environment:
GF_SECURITY_ADMIN_USER: admin
GF_SECURITY_ADMIN_PASSWORD: password
volumes:
- ./provisioning:/etc/grafana/provisioning
depends_on:
- prometheus
networks:
- gofr-network

networks:
gofr-network:
10 changes: 10 additions & 0 deletions examples/sample-cmd/docker/prometheus/prometheus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
global:
scrape_interval: 15s
evaluation_interval: 15s

scrape_configs:
- job_name: 'pushgateway'
honor_labels: true
scrape_interval: 5s
static_configs:
- targets: ['pushgateway:9091']
11 changes: 11 additions & 0 deletions examples/sample-cmd/docker/provisioning/dashboards/dashboards.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: 1

providers:
- name: 'Gofr CMD Dashboard'
orgId: 1
folder: ''
type: file
disableDeletion: false
updateIntervalSeconds: 10
options:
path: /etc/grafana/provisioning/dashboards/gofr-dashboard
Loading
Loading