Skip to content

Commit

Permalink
Merge pull request #8 from fbuchmeier-abi/master
Browse files Browse the repository at this point in the history
fixed parsing of test data, added helm chart, added server port, updated logging
  • Loading branch information
chelnak authored Sep 1, 2021
2 parents dc3f159 + 9c79bc6 commit 8d2db92
Show file tree
Hide file tree
Showing 21 changed files with 346 additions and 35 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
FROM python:3.7.4-alpine3.10

ADD exporter exporter/
add requirements.txt exporter/requirements.txt
ADD requirements.txt exporter/requirements.txt

WORKDIR exporter

RUN pip install -r requirements.txt

EXPOSE 8000

CMD ["python", "app.py"]
57 changes: 43 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,54 @@
[![Build Status](https://craigg.visualstudio.com/Pipelines/_apis/build/status/status-cake-exporter?branchName=master)](https://craigg.visualstudio.com/Pipelines/_build/latest?definitionId=19&branchName=master)



# Status Cake Exporter

Status Cake Exporter is a Prometheus expoter for [StatusCake](https://www.statuscake.com/).
Status Cake Exporter is a Prometheus exporter for [StatusCake](https://www.statuscake.com/).

Metrics are exposed on port 8080. E.g.
Metrics are exposed on port 8000 when using the provided examples/manifest.yml](examples/manifest.yml) in Kubernetes, e.g.

```sh
http://status-cake-exporter.default.svc:8000
```
http://status-cake-exporter.default.svc:8080
```

## Requirements

* Python 3.7 (not tested with anything below this)
* Python dependencies from `requirements.txt`
* Docker
* Kubernetes (optional)
* Helm 3 (optional)

## Usage

| Setting | Required | Default |
|----------|----------|---------|
| USERNAME | Yes | Null |
| USERNAME | Yes | Null |
| API_KEY | Yes | Null |
| TAGS | No | Null |
| LOG_LEVEL| No | info |
| LOG_LEVEL| No | info |
| PORT | No | 8000 |

### Docker

```
The following will expose the exporter at `localhost:8000`:

```sh
export USERNAME=statuscakeuser
export API_KEY=xxxxxxxx
docker run --env USERNAME --env API_KEY chelnak/status-cake-exporter:latest
docker run -d -p 8000:8000 --env USERNAME --env API_KEY chelnak/status-cake-exporter:latest
```

### Kubernetes

To get up and running quickly, use [examples/manifest.yml](examples/manifest.yml) as an example.
To get up and running quickly, use [examples/manifest.yml](examples/manifest.yml) as an example. You will need to create a secret named `status-cake-api-token` containing your `USERNAME` and `API_KEY` first.

Otherwise, you can use the Helm Chart provided in [chart/status-cake-exporter](chart/status-cake-exporter/README.md).

### Terminal

```
```sh
usage: app.py [-h] [--username USERNAME] [--api-key API_KEY]
[--tests.tags TAGS] [--logging.level {debug,info,warn,error}]
[--tests.tags TAGS] [--logging.level {debug,info,warn,error}] [--port PORT]

If an arg is specified in more than one place, then commandline values
override environment variables which override defaults.
Expand All @@ -48,7 +59,8 @@ optional arguments:
--api-key API_KEY API key for the account [env var: API_KEY]
--tests.tags TAGS A comma separated list of tags used to filter tests returned from the api [env var: TAGS]
--logging.level {debug,info,warn,error} Set a log level for the application [env var: LOG_LEVEL]
```
--port The TCP port to start the web server on [env var: PORT]
```

## Metrics

Expand All @@ -75,13 +87,30 @@ scrape_configs:
```
## Grafana
Data collected by Prometheus can be easily surfaced in Grafana.
Using the [Statusmap panel](https://grafana.com/grafana/plugins/flant-statusmap-panel) by [flant](https://github.com/flant/grafana-statusmap) you can create a basic status visualization based on uptime percentage:
![](examples/grafana.png)
### PromQL
```PromQL
status_cake_test_info * on(test_id) group_right(test_name) status_cake_test_uptime_percent
```

## Development

This repository uses [Tilt](https://tilt.dev) for rapid development on Kubernetes.

To use this, run:

```sh
cd chart/status-cake-exporter
tilt up
```

Tilt will reload your environment when it detects changes to your code.

Note: You will need to provide valid credentials for StatusCake in your `Tiltfile` for this to work.
1 change: 1 addition & 0 deletions chart/status-cake-exporter/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src
2 changes: 2 additions & 0 deletions chart/status-cake-exporter/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Tiltfile_*
.git
9 changes: 9 additions & 0 deletions chart/status-cake-exporter/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: v1
appVersion: latest
description: Status Cake Prometheus Exporter
keywords:
- prometheus
- statuscake
maintainers: []
name: status-cake-exporter
version: 1.0.0
39 changes: 39 additions & 0 deletions chart/status-cake-exporter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Statuscake Prometheus Exporter Helm Chart

This Helm chart deploys the StatusCake Prometheus exporter from [chelnak/status-cake-exporter](https://github.com/chelnak/status-cake-exporter).

## Requirements

* Statuscake `username` and `apiKey` defined in [values.yaml](values.yaml).

## Usage

Create your own `values.yaml` file and run:

```bash
helm install status-cake-exporter . --namespace default --values values.yaml
```

## Testing

```bash
helm test ${releaseName}
```

## Development

This repository uses [Tilt](https://tilt.dev) for rapid development on Kubernetes.

To use this, run:

```sh
tilt up
```

Tilt will reload your environment when it detects changes to your code (see [Tiltfile](Tiltfile) for the list of paths watched).

Note: You will need to provide valid credentials for StatusCake in your `Tiltfile` for this to work. To do so, you can copy the file to e.g. `Tiltfile_secret`, update it and then start tilt with:

```sh
tilt up -f Tiltfile_secret
```
7 changes: 7 additions & 0 deletions chart/status-cake-exporter/Tiltfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
docker_build('status-cake-exporter:dev', '../../')
# If not using a standard local dev name, specify your k8s context here
#allow_k8s_contexts('microk8s')
k8s_yaml(helm('.', values='values.yaml', set=['statuscake.logLevel=debug', 'image.repository=status-cake-exporter', 'image.tag=dev', 'statuscake.username=', 'statuscake.apiKey=', 'statuscake.tags=firstTag,secondTag']))
watch_file('.')
watch_file('../../Dockerfile')
watch_file('../../exporter')
27 changes: 27 additions & 0 deletions chart/status-cake-exporter/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 24 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create a default fully qualified app name.
We truncate at 24 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
*/}}
{{- define "fullname" -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- printf "%s-%s" .Release.Name $name | trunc 24 | trimSuffix "-" -}}
{{- end -}}

{{/*
Return the appropriate apiVersion for deployment.
*/}}
{{- define "deployment.apiVersion" -}}
{{- if semverCompare "<1.9-0" .Capabilities.KubeVersion.GitVersion -}}
{{- print "extensions/v1beta1" -}}
{{- else if semverCompare "^1.9-0" .Capabilities.KubeVersion.GitVersion -}}
{{- print "apps/v1" -}}
{{- end -}}
{{- end -}}
52 changes: 52 additions & 0 deletions chart/status-cake-exporter/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
apiVersion: {{ template "deployment.apiVersion" . }}
kind: Deployment
metadata:
name: "{{ .Release.Name }}"
labels:
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
heritage: {{ .Release.Service | quote }}
release: {{ .Release.Name | quote }}
app: "{{ .Release.Name }}"
spec:
replicas: 1
selector:
matchLabels:
app: "{{ .Release.Name }}"
template:
metadata:
labels:
app: "{{ .Release.Name }}"
spec:
containers:
- name: status-cake-exporter
image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
ports:
- containerPort: {{ .Values.service.port }}
env:
- name: USERNAME
valueFrom:
secretKeyRef:
name: {{ .Release.Name }}-api-token
key: USERNAME
- name: API_KEY
valueFrom:
secretKeyRef:
name: {{ .Release.Name }}-api-token
key: API_KEY
{{- if .Values.statuscake.tags }}
- name: TAGS
value: {{ .Values.statuscake.tags }}
{{- end }}
{{- if .Values.statuscake.logLevel }}
- name: LOG_LEVEL
value: {{ .Values.statuscake.logLevel }}
{{- end }}
resources:
{{ toYaml .Values.resources | indent 10 }}
{{- if .Values.image.pullSecrets }}
imagePullSecrets:
{{- range .Values.image.pullSecrets }}
- name: {{ . }}
{{- end }}
{{- end }}
14 changes: 14 additions & 0 deletions chart/status-cake-exporter/templates/secrets.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
apiVersion: v1
kind: Secret
metadata:
name: "{{ .Release.Name }}-api-token"
labels:
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
heritage: {{ .Release.Service | quote }}
release: {{ .Release.Name | quote }}
app: "{{ .Release.Name }}"
type: generic
data:
USERNAME: {{ .Values.statuscake.username | b64enc }}
API_KEY: {{ .Values.statuscake.apiKey | b64enc }}
15 changes: 15 additions & 0 deletions chart/status-cake-exporter/templates/svc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
name: "{{ .Release.Name }}"
labels:
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
heritage: {{ .Release.Service | quote }}
release: {{ .Release.Name | quote }}
app: "{{ .Release.Name }}"
spec:
ports:
- port: {{ .Values.service.port }}
protocol: TCP
selector:
app: "{{ .Release.Name }}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
apiVersion: v1
kind: Pod
metadata:
name: "{{ .Release.Name }}-test-{{ randAlphaNum 5 | lower }}"
annotations:
"helm.sh/hook": test-success
spec:
containers:
- name: {{ .Release.Name }}-test
image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
command:
- "sh"
- "-c"
- |
set -x
# run tests
sh /tests/run.sh
volumeMounts:
- mountPath: /tests
name: tests
readOnly: true
- mountPath: /tools
name: tools
resources:
requests:
cpu: "50m"
memory: "128Mi"
limits:
cpu: "250m"
memory: "256Mi"
volumes:
- name: tests
configMap:
name: {{ .Release.Name }}-tests
- name: tools
emptyDir: {}
restartPolicy: Never
{{- if .Values.image.pullSecrets }}
imagePullSecrets:
{{- range .Values.image.pullSecrets }}
- name: {{ . }}
{{- end }}
{{- end }}
12 changes: 12 additions & 0 deletions chart/status-cake-exporter/templates/tests/test-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-tests
data:
run.sh: |-
for i in $(seq 1 48) ; do
wget -T 10 http://{{ .Release.Name }}:{{ .Values.service.port }}/metrics && exit 0
sleep 5
done
exit 1
26 changes: 26 additions & 0 deletions chart/status-cake-exporter/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
image:
repository: chelnak/status-cake-exporter
tag: latest
# A list of ImagePullSecrets to use for the containers in this Chart
pullSecrets: []

statuscake:
# REQUIRED: username to use when connecting to statuscake
username: ""
# REQUIRED: apikey to use when connecting to statuscake
apiKey: ""
# optional: a comma separated list of tags to filter for
# tags:
# optional: debug, info, warn, error
# logLevel:

service:
port: 8000

resources:
requests:
cpu: "250m"
memory: "256Mi"
limits:
cpu: "250m"
memory: "256Mi"
Loading

0 comments on commit 8d2db92

Please sign in to comment.