forked from prometheus-community/helm-charts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[prometheus-modbus-exporter] full (prometheus-community#3531)
* [prometheus-modbus-exporter] full Signed-off-by: openenergyprojects <[email protected]> * [prometheus-modbus-exporter] update readme Signed-off-by: openenergyprojects <[email protected]> * [prometheus-modbus-exporter] remove stable repo from readme Signed-off-by: openenergyprojects <[email protected]> * [prometheus-modbus-exporter] disable serviceMonitor when crd is not installed, even for self Signed-off-by: openenergyprojects <[email protected]> --------- Signed-off-by: openenergyprojects <[email protected]>
- Loading branch information
1 parent
17ee96b
commit cff6842
Showing
12 changed files
with
527 additions
and
0 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
apiVersion: v2 | ||
name: prometheus-modbus-exporter | ||
description: A Helm chart for prometheus-modbus-exporter | ||
|
||
keywords: | ||
- modbus | ||
- modbus_exporter | ||
- metric | ||
- monitoring | ||
- prometheus | ||
|
||
type: application | ||
|
||
version: 0.1.0 | ||
appVersion: "0.4.0" | ||
|
||
maintainers: | ||
- name: openenergyprojects | ||
email: [email protected] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# prometheus-modbus-exporter | ||
|
||
Prometheus exporter for scraping metrics via modbus based protocol. | ||
|
||
## Intro | ||
|
||
This chart bootstraps a [modbus_exporter](https://github.com/RichiH/modbus_exporter) deployment on a [Kubernetes](http://kubernetes.io) cluster using the [Helm](https://helm.sh) package manager. | ||
|
||
The serviceMonitor objects are created for Prometheus Operator. | ||
|
||
## Configuration | ||
|
||
The configuration of the modbus_exporter can be provided either via helm's custom values, or via an already existing (independently managed) configMap. | ||
Either way, every time the configuration is getting updated, the modbus_exporter is getting restarted in order to fetch it. This is done using sidecar reloader: <https://github.com/Pluies/config-reloader-sidecar>. | ||
|
||
## Tests | ||
|
||
This setup has been tested with both real unit (Janitza Power Analizer UMG series) as well as using an simulator <https://www.modbustools.com/download.html>. | ||
Other simulators (fully free) exist as well: | ||
|
||
1. the one included as part of the test (fake server) in the <https://github.com/RichiH/modbus_exporter/blob/main/tests/fake_server/main.go>, which uses <https://github.com/tbrandon/mbserver> (golang). | ||
2. Many others, like pymodslave, based on py module: <https://github.com/ljean/modbus-tk>, which has its own demo simulator as well. | ||
|
||
## Notes | ||
|
||
There are 4 types of read registries, hence 4 read function codes (1,2,3,4). | ||
Don't forget to prefix (first digit) your registry with the required function. | ||
Your address should be always 6 digits. | ||
E.g. for holding registry 22, the address is: 300022 (where the 3 denotes the holding registry function). | ||
More on Modbus function codes: <https://ozeki.hu/p_5873-modbus-function-codes.html> | ||
|
||
## Prerequisites | ||
|
||
- Kubernetes 1.10+ with Beta APIs enabled | ||
- Helm 3+ | ||
|
||
## Get Repository Info | ||
|
||
```console | ||
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts | ||
helm repo update | ||
``` | ||
|
||
_See [helm repository](https://helm.sh/docs/helm/helm_repo/) for command documentation._ | ||
|
||
## Install Chart | ||
|
||
```console | ||
helm install [RELEASE_NAME] prometheus-community/prometheus-modbus-exporter | ||
``` | ||
|
||
_See [configuration](## Configuring) below._ | ||
|
||
_See [helm install](https://helm.sh/docs/helm/helm_install/) for command documentation._ | ||
|
||
## Uninstall Chart | ||
|
||
```console | ||
helm uninstall [RELEASE_NAME] | ||
``` | ||
|
||
This removes all the Kubernetes components associated with the chart and deletes the release. | ||
|
||
_See [helm uninstall](https://helm.sh/docs/helm/helm_uninstall/) for command documentation._ | ||
|
||
## Upgrading Chart | ||
|
||
```console | ||
helm upgrade [RELEASE_NAME] [CHART] --install | ||
``` | ||
|
||
## Configuring | ||
|
||
See [Customizing the Chart Before Installing](https://helm.sh/docs/intro/using_helm/#customizing-the-chart-before-installing). To see all configurable options with detailed comments, visit the chart's [values.yaml](./values.yaml), or run these configuration commands: | ||
|
||
```console | ||
helm show values prometheus-community/prometheus-modbus-exporter | ||
``` | ||
|
||
For more information please refer to the [modbus_exporter](https://github.com/RichiH/modbus_exporter) documentation. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
For any help, see: | ||
- https://github.com/RichiH/modbus_exporter | ||
- https://github.com/prometheus-community/helm-charts/issues |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
{{/* | ||
Expand the name of the chart. | ||
*/}} | ||
{{- define "prometheus-modbus-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 "prometheus-modbus-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 "prometheus-modbus-exporter.chart" -}} | ||
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} | ||
{{- end }} | ||
|
||
{{/* | ||
Common labels | ||
*/}} | ||
{{- define "prometheus-modbus-exporter.labels" -}} | ||
helm.sh/chart: {{ include "prometheus-modbus-exporter.chart" . }} | ||
{{ include "prometheus-modbus-exporter.selectorLabels" . }} | ||
{{- if .Chart.AppVersion }} | ||
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} | ||
{{- end }} | ||
app.kubernetes.io/managed-by: {{ .Release.Service }} | ||
{{- end }} | ||
|
||
{{/* | ||
Selector labels | ||
*/}} | ||
{{- define "prometheus-modbus-exporter.selectorLabels" -}} | ||
app.kubernetes.io/name: {{ include "prometheus-modbus-exporter.name" . }} | ||
app.kubernetes.io/instance: {{ .Release.Name }} | ||
{{- end }} | ||
|
||
{{/* | ||
Create the name of the service account to use | ||
*/}} | ||
{{- define "prometheus-modbus-exporter.serviceAccountName" -}} | ||
{{- if .Values.serviceAccount.create }} | ||
{{- default (include "prometheus-modbus-exporter.fullname" .) .Values.serviceAccount.name }} | ||
{{- else }} | ||
{{- default "default" .Values.serviceAccount.name }} | ||
{{- end }} | ||
{{- end }} |
13 changes: 13 additions & 0 deletions
13
charts/prometheus-modbus-exporter/templates/configmap.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{{- if not .Values.configMapFile -}} | ||
{{- $fullName := include "prometheus-modbus-exporter.fullname" . -}} | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: {{ $fullName }} | ||
labels: | ||
{{- include "prometheus-modbus-exporter.labels" . | nindent 4 }} | ||
data: | ||
modbus.yml: | | ||
modules: | ||
{{- toYaml .Values.modules | nindent 4 }} | ||
{{- end }} |
88 changes: 88 additions & 0 deletions
88
charts/prometheus-modbus-exporter/templates/deployment.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: {{ include "prometheus-modbus-exporter.fullname" . }} | ||
labels: | ||
{{- include "prometheus-modbus-exporter.labels" . | nindent 4 }} | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
{{- include "prometheus-modbus-exporter.selectorLabels" . | nindent 6 }} | ||
template: | ||
metadata: | ||
{{- with .Values.podAnnotations }} | ||
annotations: | ||
{{- toYaml . | nindent 8 }} | ||
{{- end }} | ||
labels: | ||
{{- include "prometheus-modbus-exporter.selectorLabels" . | nindent 8 }} | ||
spec: | ||
{{- with .Values.imagePullSecrets }} | ||
imagePullSecrets: | ||
{{- toYaml . | nindent 8 }} | ||
{{- end }} | ||
serviceAccountName: {{ include "prometheus-modbus-exporter.serviceAccountName" . }} | ||
securityContext: | ||
{{- toYaml .Values.podSecurityContext | nindent 8 }} | ||
shareProcessNamespace: true # required for config-reloader-sidecar | ||
containers: | ||
- name: {{ include "prometheus-modbus-exporter.fullname" . }} | ||
command: ["/bin/modbus_exporter"] | ||
args: | ||
- "--config.file=/etc/modbus_exporter/modbus.yml" | ||
- "--log.level={{ .Values.log.level }}" | ||
- "--log.format={{ .Values.log.format }}" | ||
securityContext: | ||
{{- toYaml .Values.securityContext | nindent 12 }} | ||
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" | ||
imagePullPolicy: {{ .Values.image.pullPolicy }} | ||
ports: | ||
- name: metrics | ||
containerPort: {{ .Values.service.port }} | ||
protocol: TCP | ||
livenessProbe: | ||
httpGet: | ||
path: /metrics | ||
port: 9602 | ||
readinessProbe: | ||
httpGet: | ||
path: /metrics | ||
port: 9602 | ||
resources: | ||
{{- toYaml .Values.resources | nindent 12 }} | ||
volumeMounts: | ||
- name: configfile | ||
mountPath: /etc/modbus_exporter/ | ||
{{ if .Values.configReloaderSidecar.enable }} | ||
- name: {{ include "prometheus-modbus-exporter.fullname" . }}-config-reloader-sidecar | ||
image: "{{ .Values.configReloaderSidecar.image.repository }}:{{ .Values.configReloaderSidecar.image.tag }}" | ||
env: | ||
- name: CONFIG_DIR | ||
value: /etc/modbus_exporter/ | ||
- name: PROCESS_NAME | ||
value: modbus_exporter | ||
volumeMounts: | ||
- name: configfile | ||
mountPath: /etc/modbus_exporter/ | ||
{{- end -}} | ||
{{- with .Values.nodeSelector }} | ||
nodeSelector: | ||
{{- toYaml . | nindent 8 }} | ||
{{- end }} | ||
{{- with .Values.affinity }} | ||
affinity: | ||
{{- toYaml . | nindent 8 }} | ||
{{- end }} | ||
{{- with .Values.tolerations }} | ||
tolerations: | ||
{{- toYaml . | nindent 8 }} | ||
{{- end }} | ||
volumes: | ||
- name: configfile | ||
configMap: | ||
{{- if not .Values.configMapFile }} | ||
name: {{ include "prometheus-modbus-exporter.fullname" . }} | ||
{{- else }} | ||
name: {{ .Values.configMapFile }} | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: {{ include "prometheus-modbus-exporter.fullname" . }} | ||
labels: | ||
{{- include "prometheus-modbus-exporter.labels" . | nindent 4 }} | ||
spec: | ||
type: {{ .Values.service.type }} | ||
ports: | ||
- port: {{ .Values.service.port }} | ||
targetPort: 9602 | ||
protocol: TCP | ||
name: metrics | ||
selector: | ||
{{- include "prometheus-modbus-exporter.selectorLabels" . | nindent 4 }} |
12 changes: 12 additions & 0 deletions
12
charts/prometheus-modbus-exporter/templates/serviceaccount.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{{- if .Values.serviceAccount.create -}} | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: {{ include "prometheus-modbus-exporter.serviceAccountName" . }} | ||
labels: | ||
{{- include "prometheus-modbus-exporter.labels" . | nindent 4 }} | ||
{{- with .Values.serviceAccount.annotations }} | ||
annotations: | ||
{{- toYaml . | nindent 4 }} | ||
{{- end }} | ||
{{- end }} |
52 changes: 52 additions & 0 deletions
52
charts/prometheus-modbus-exporter/templates/servicemonitor.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{{- $fullName := include "prometheus-modbus-exporter.fullname" . -}} | ||
{{- $endpointsCommonConfig := .Values.serviceMonitor.endpointsCommonConfig -}} | ||
{{- if and .Values.serviceMonitor.enabled ( .Capabilities.APIVersions.Has "monitoring.coreos.com/v1/ServiceMonitor" ) }} | ||
apiVersion: monitoring.coreos.com/v1 | ||
kind: ServiceMonitor | ||
metadata: | ||
name: {{ $fullName }} | ||
labels: | ||
{{- include "prometheus-modbus-exporter.labels" . | nindent 4 }} | ||
{{- with .Values.serviceMonitor.labels }} | ||
{{- toYaml . | nindent 4 }} | ||
{{- end }} | ||
{{- with .Values.serviceMonitor.annotations }} | ||
annotations: | ||
{{ toYaml . | nindent 4 }} | ||
{{- end }} | ||
spec: | ||
selector: | ||
matchLabels: | ||
{{- include "prometheus-modbus-exporter.labels" . | nindent 6 }} | ||
endpoints: | ||
{{- range .Values.serviceMonitor.endpointsConfig }} | ||
- port: metrics | ||
path: "/modbus" | ||
{{ toYaml . | indent 4 }} | ||
{{/*path: "/modbus&target=1.2.3.4:502" */}} | ||
{{ toYaml $endpointsCommonConfig | nindent 4 }} | ||
{{- end }} | ||
{{- end }} | ||
--- | ||
{{- if and .Values.serviceMonitorExporterItself.enabled ( .Capabilities.APIVersions.Has "monitoring.coreos.com/v1/ServiceMonitor" ) }} | ||
apiVersion: monitoring.coreos.com/v1 | ||
kind: ServiceMonitor | ||
metadata: | ||
name: {{ $fullName }}-self-monitor | ||
labels: | ||
{{- include "prometheus-modbus-exporter.labels" . | nindent 4 }} | ||
{{- with .Values.serviceMonitorExporterItself.labels }} | ||
{{ toYaml . | nindent 4 }} | ||
{{- end }} | ||
{{- with .Values.serviceMonitorExporterItself.annotations }} | ||
annotations: | ||
{{ toYaml . | nindent 4 }} | ||
{{- end }} | ||
spec: | ||
selector: | ||
matchLabels: | ||
{{- include "prometheus-modbus-exporter.labels" . | nindent 6 }} | ||
endpoints: | ||
- port: metrics | ||
path: "/metrics" | ||
{{- end }} |
17 changes: 17 additions & 0 deletions
17
charts/prometheus-modbus-exporter/templates/tests/test-connection.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{{/* | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: "{{ include "prometheus-modbus-exporter.fullname" . }}-test-connection" | ||
labels: | ||
{{- include "prometheus-modbus-exporter.labels" . | nindent 4 }} | ||
annotations: | ||
"helm.sh/hook": test | ||
spec: | ||
containers: | ||
- name: wget | ||
image: busybox | ||
command: ['wget'] | ||
args: ['{{ include "prometheus-modbus-exporter.fullname" . }}:{{ .Values.service.port }}'] | ||
restartPolicy: Never | ||
*/}} |
Oops, something went wrong.