Skip to content

Commit

Permalink
feature: mongoshake-prometheus-exporter first commit (#7)
Browse files Browse the repository at this point in the history
* feature: mongoshake-prometheus-exporter first commit

* Update lint-test.yaml

* Update values.yaml

* Update README.md

* Update values.yaml

---------
  • Loading branch information
yuriazeredo committed Feb 15, 2024
1 parent a6658f9 commit b2a21ae
Show file tree
Hide file tree
Showing 15 changed files with 663 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/lint-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ jobs:
fi
- name: Run chart-testing (lint)
run: ct lint --config ct.yaml
run: ct lint --validate-maintainers=false --config ct.yaml

- name: Create kind cluster
uses: helm/kind-action@v1.2.0
if: steps.list-changed.outputs.changed == 'true'

- name: Run chart-testing (install)
run: ct install --config ct.yaml
run: ct install --config ct.yaml
Binary file added charts/mongoshake-prometheus-exporter-1.0.0.tgz
Binary file not shown.
23 changes: 23 additions & 0 deletions charts/mongoshake-prometheus-exporter/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
24 changes: 24 additions & 0 deletions charts/mongoshake-prometheus-exporter/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: mongoshake-prometheus-exporter
description: A Helm chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 1.0.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.0.0"
176 changes: 176 additions & 0 deletions charts/mongoshake-prometheus-exporter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
# MongoShake Prometheus Exporter Helm Chart

* MongoShake Prometheus Exporter is an exporter that adapts MongoShake metrics to the Prometheus format, making it easier for administrators to monitor resources..
* Reference: [MongoShake Prometheus Exporter](https://github.com/osgurisdosre/mongoshake-prometheus-exporter)

## Get Repo Info

```console
helm repo add mongoshake-prometheus-exporter https://osgurisdosre.github.io/helm-charts
helm repo update
```
* You can then run `helm search repo mongoshake-prometheus-exporter` to see the charts.

_See [helm repo](https://helm.sh/docs/helm/helm_repo/) for command documentation._

## Installing the Chart

To install the chart with the release name `my-release`:

```console
helm install mongoshake-prometheus-exporter mongoshake-prometheus-exporter/mongoshake-prometheus-exporter
```

## Uninstalling the Chart

To uninstall/delete the my-release deployment:

```console
helm delete mongoshake-prometheus-exporter
```

The command removes all the Kubernetes components associated with the chart and deletes the release.


## Configuration

| Parameter | Description | Default |
|-------------------------------------------|-----------------------------------------------|---------------------------------------------------------|
| `image.repository` | Image repository | `sergiitk/pagerbeauty` |
| `image.tag` | Overrides the PagerBeauty image tag whose default is the chart appVersion | `latest` |
| `image.pullPolicy` | Image pull policy | `IfNotPresent` |
| `service.type` | Kubernetes service type | `ClusterIP` |
| `service.port` | Kubernetes port where service is exposed | `8000` |
| `ingress.enabled` | Enables Ingress | `false` |
| `ingress.annotations` | Ingress annotations (values are templated) | `{}` |
| `ingress.path` | Ingress accepted path | `/` |
| `ingress.hosts` | Ingress accepted hostnames | `["chart-example.local"]` |
| `ingress.tls` | Ingress TLS configuration | `[]` |
| `ingress.className` | Ingress Class Name. MAY be required for Kubernetes versions >= 1.18 | `""` |
| `resources` | CPU/Memory resource requests/limits | `{}` |
| `nodeSelector` | Node labels for pod assignment | `{}` |
| `tolerations` | Toleration labels for pod assignment | `[]` |
| `affinity` | Affinity settings for pod assignment | `{}` |
| `env` | Extra environment variables passed to pods | `{}` |
| `envFromSecret` | Name of a Kubernetes secret (must be manually created in the same namespace) containing values to be added to the environment. Can be templated | `""` |
| `envFromSecrets` | List of Kubernetes secrets (must be manually created in the same namespace) containing values to be added to the environment. Can be templated | `[]` |
| `envFromConfigMaps` | List of Kubernetes ConfigMaps (must be manually created in the same namespace) containing values to be added to the environment. Can be templated | `[]` |
| `podAnnotations` | Pod annotations | `{}` |
| `serviceAccount.annotations` | ServiceAccount annotations | |
| `serviceAccount.create` | Create service account | `true` |
| `serviceAccount.name` | Service account name to use, when empty will be set to created account if `serviceAccount.create` is set else to `default` | `` |
| `serviceMonitor.enabled` | Enables the creation of a service monitor used later for Prometheus discovery. When empty, it will be set to `false`. | `false` |

### Example

For a demonstration, we used a MongoShake instance operating in Kubernetes.

```bash
curl http://mongoshake.monitoring.svc.cluster.local:9100/repl | jq
```

We get the following response:

```json
{
"who": "mongoshake",
"tag": "",
"replset": "mongoshake-shard-0",
"logs_get": 786,
"logs_repl": 62,
"logs_success": 62,
"tps": 0,
"lsn": {
"unix": 1707334793,
"time": "2024-02-07 19:39:53",
"ts": "7332947099257929731"
},
"lsn_ack": {
"unix": 1707334793,
"time": "2024-02-07 19:39:53",
"ts": "7332947099257929731"
},
"lsn_ckpt": {
"unix": 1707334656,
"time": "2024-02-07 19:37:36",
"ts": "7332946510847410178"
},
"now": {
"unix": 1707334864,
"time": "2024-02-07 19:41:04"
},
"log_size_avg": "503.00B",
"log_size_max": "12.29KB"
}
```

Installing the Chart
```bash
helm repo add mongoshake-prometheus-exporter https://osgurisdosre.github.io/helm-charts
helm repo update
helm install my-release mongoshake-prometheus-exporter/mongoshake-prometheus-exporter -f values -n monitoring
```
In the values file we used the following settings:
```yaml
image:
repository: ghcr.io/osgurisdosre/mongoshake-prometheus-exporter
pullPolicy: IfNotPresent
tag: "latest"

env:
URL_LIST: "http://mongoshake.monitoring.svc.cluster.local:9100/repl"
SCRAPE_INTERVAL: 5

service:
type: ClusterIP
port: 8000
labels:
release: prometheus

serviceMonitor:
enabled: true
path: /metrics
interval: 10s
namespace: monitoring
labels:
release: prometheus

```
Now we can check the output by the service created

```bash
curl http://mongoshake-prometheus-exporter.monitoring.svc.cluster.local:8000/metrics/
```

The following response is obtained:
```bash
# HELP mongoshake_logs_get Number of logs (get)
# TYPE mongoshake_logs_get gauge
mongoshake_logs_get{replset="Release-shard-0",url="http://mongoshake.monitoring.svc.cluster.local:9100/repl"} 44736.0
# HELP mongoshake_logs_repl Number of logs (repl)
# TYPE mongoshake_logs_repl gauge
mongoshake_logs_repl{replset="Release-shard-0",url="http://mongoshake.monitoring.svc.cluster.local:9100/repl"} 1109.0
# HELP mongoshake_logs_success Number of successful logs
# TYPE mongoshake_logs_success gauge
mongoshake_logs_success{replset="Release-shard-0",url="http://mongoshake.monitoring.svc.cluster.local:9100/repl"} 1109.0
# HELP mongoshake_tps Transactions per second
# TYPE mongoshake_tps gauge
mongoshake_tps{replset="Release-shard-0",url="http://mongoshake.monitoring.svc.cluster.local:9100/repl"} 0.0
# HELP mongoshake_replication_latency Replication_latency in MS
# TYPE mongoshake_replication_latency gauge
mongoshake_replication_latency{replset="Release-shard-0",url="http://mongoshake.monitoring.svc.cluster.local:9100/repl"} 0.0
```

Note that the metrics are now being exported in Prometheus format.

### Contributions

Contributions are welcome! If you wish to contribute, please:
- Fork the repository;

- Create a new branch for your feature or fix;

- Send a pull request with your proposal.

To report bugs or request new features, use the issues section of the repository.
22 changes: 22 additions & 0 deletions charts/mongoshake-prometheus-exporter/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- range .paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "mongoshake-prometheus-exporter.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "mongoshake-prometheus-exporter.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "mongoshake-prometheus-exporter.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "mongoshake-prometheus-exporter.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
{{- end }}
66 changes: 66 additions & 0 deletions charts/mongoshake-prometheus-exporter/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "mongoshake-prometheus-exporter.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "mongoshake-prometheus-exporter.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "mongoshake-prometheus-exporter.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "mongoshake-prometheus-exporter.labels" -}}
helm.sh/chart: {{ include "mongoshake-prometheus-exporter.chart" . }}
{{ include "mongoshake-prometheus-exporter.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "mongoshake-prometheus-exporter.selectorLabels" -}}
app.kubernetes.io/name: {{ include "mongoshake-prometheus-exporter.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "mongoshake-prometheus-exporter.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "mongoshake-prometheus-exporter.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}

# {{- define "mongoshake-prometheus-exporter.namespace" }}
# {{ .Release.Namespace }}
# {{- end }}
Loading

0 comments on commit b2a21ae

Please sign in to comment.