Build as Docker image w/Example Dashboard #3

Merged
stphnsmpsn merged 1 commits from feature/example_dashboard into master 2023-09-12 23:46:48 -03:00
14 changed files with 4351 additions and 8 deletions

1
.dockerignore Normal file
View File

@@ -0,0 +1 @@
target

View File

@@ -1,5 +1,5 @@
[package]
name = "server_metrics"
name = "system-exporter"
version = "0.1.0"
edition = "2021"

24
Dockerfile Normal file
View File

@@ -0,0 +1,24 @@
# ---- Build Stage ----
FROM rust:1.71.1-slim-bullseye as build
ARG DEBIAN_FRONTEND=noninteractive
RUN apt update && apt install -y \
iputils-ping \
libpq-dev \
cmake \
pkg-config \
gcc \
g++ \
python3 \
libssl-dev \
protobuf-compiler \
git
ARG DEBIAN_FRONTEND=noninteractive
WORKDIR /app
COPY . .
RUN cargo build --release
## ---- Production Stage ----
FROM debian:bookworm AS production
WORKDIR /app
COPY --from=build /app/target/release/system-exporter ./
CMD [ "./system-exporter" ]

View File

@@ -1,2 +1,10 @@
# system-exporter
This repo will export useful metrics about your system and provide a nice dashboard.
Note: currently only supports docker
## Usage
1. Build: `docker build -t dockermonrs .`
2. Run: `cd example && docker-compose up -d`

View File

@@ -0,0 +1,38 @@
global:
resolve_timeout: 5m
slack_api_url: 'https://hooks.slack.com/services/XXX'
templates:
- '/etc/alertmanager/template/*.tmpl'
route:
group_by: ['alertname']
group_wait: 10s
group_interval: 10s
repeat_interval: 1h
receiver: 'webhook'
routes:
- receiver: 'slack-notification'
group_by: ['service']
match_re:
alertname: 'node.*down'
inhibit_rules:
- source_match:
severity: 'critical'
target_match:
severity: 'warning'
equal: ['alertname', 'dev', 'instance']
- source_match_re:
alertname: 'node.*down'
target_match:
alertname: 'webservicedown'
receivers:
- name: 'webhook'
webhook_configs:
- url: 'http://127.0.0.1:5000/webhook'
- name: 'slack-notification'
slack_configs:
- channel: '#notification'
send_resolved: false

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,11 @@
apiVersion: 1
providers:
- name: "Prometheus"
orgId: 1
folder: ""
type: file
disableDeletion: false
editable: true
options:
path: /etc/grafana/provisioning/dashboards

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,15 @@
apiVersion: 1
datasources:
- name: Prometheus
type: prometheus
access: proxy
orgId: 1
url: http://prometheus:9090
basicAuth: false
isDefault: true
editable: true
uid: prometheus
version: 1
jsonData:
httpMethod: GET

View File

@@ -0,0 +1,26 @@
global:
scrape_interval: 5s
alerting:
alertmanagers:
- static_configs:
- targets: ['alertmanager:9093']
rule_files:
- "/etc/prometheus/rules/*"
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
labels:
group: 'prometheus'
- job_name: 'system-exporter'
static_configs:
- targets: ['system-exporter:45454']
- job_name: 'node-exporter'
static_configs:
- targets: ['node-exporter:9100']

View File

@@ -0,0 +1,10 @@
groups:
- name: sample-alerts
rules:
- alert: node down
expr: 0
labels:
severity: critical
service: linux
annotations:
summary: node down

View File

@@ -0,0 +1,69 @@
version: "3.8"
services:
socat:
container_name: socat
image: bobrik/socat
command: TCP-LISTEN:2375,fork UNIX-CONNECT:/var/run/docker.sock
ports:
- "2375:2375"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
system-exporter:
container_name: system-exporter
image: dockermonrs
command: /app/system-exporter --docker-server http://socat:2375
ports:
- "45454:45454"
prometheus:
container_name: prometheus
image: bitnami/prometheus:latest
restart: unless-stopped
volumes:
- ./config/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
- ./config/prometheus//rules:/etc/prometheus/rules
command: "--config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/prometheus"
ports:
- 19090:9090
grafana:
container_name: grafana
image: grafana/grafana:latest
restart: unless-stopped
volumes:
- ./config/grafana/defaults.ini:/usr/share/grafana/conf/defaults.ini
- ./config/grafana/provisioning:/etc/grafana/provisioning
ports:
- "13000:3000"
depends_on:
- prometheus
alertmanager:
container_name: alertmanager
image: bitnami/alertmanager:latest
restart: unless-stopped
ports:
- 19093:9093
volumes:
- ./config/alertmanager/alertmanager.yml:/etc/alertmanager/alertmanager.yml
- ./config/grafana/provisioning/datasources/datasources.yml:/etc/grafana/provisioning/datasources/datasources.yaml
node-exporter:
container_name: node-exporter
image: bitnami/node-exporter:latest
restart: unless-stopped
privileged: true
ports:
- "19100:9100"
volumes:
- /proc:/host/proc:ro
- /sys:/host/sys:ro
- /:/rootfs:ro
command:
- "--path.procfs=/host/proc"
- "--path.sysfs=/host/sys"
- "--collector.filesystem.ignored-mount-points"
- "^/(rootfs/)?(dev|etc|host|proc|run|sys|volume1)($$|/)"

View File

@@ -21,10 +21,14 @@ pub struct DockerContainer {
pub image: String,
#[serde(rename = "ImageID")]
pub image_id: String,
#[serde(default)]
pub labels: HashMap<String, String>,
#[serde(default)]
pub mounts: Vec<Mount>,
#[serde(default)]
pub names: Vec<String>,
pub network_settings: NetworkSettings,
#[serde(default)]
pub ports: Vec<Port>,
pub state: String,
pub status: String,
@@ -90,9 +94,9 @@ pub struct Bridge {
#[serde(rename_all = "PascalCase")]
pub struct Port {
#[serde(rename(deserialize = "IP"))]
pub ip: String,
pub private_port: i32,
pub public_port: i32,
pub ip: Option<String>,
pub private_port: Option<i32>,
pub public_port: Option<i32>,
#[serde(rename(deserialize = "Type"))]
pub type_: String,
pub type_: Option<String>,
}

View File

@@ -53,9 +53,12 @@ impl DockerClient {
match serde_json::from_value(json_value.clone()) {
Ok(value) => Ok(value),
Err(_) => Err(SystemExporterError::RemoteServerError(
serde_json::from_value(json_value)?,
)),
Err(e) => {
println!("error: {}", e);
Err(SystemExporterError::RemoteServerError(
serde_json::from_value(json_value)?,
))
}
}
}
}