forked from carlosedp/cluster-monitoring
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ups_exporter.jsonnet
80 lines (69 loc) · 2.25 KB
/
ups_exporter.jsonnet
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
local k = import 'ksonnet/ksonnet.beta.4/k.libsonnet';
{
_config+:: {
namespace: 'monitoring',
ups: {
ips: ['192.168.1.62'],
},
// Add custom dashboards
grafanaDashboards+:: {
'apc-ups-dashboard.json': (import 'grafana-dashboards/apc-ups-dashboard.json'),
},
},
upsExporter+:: {
serviceMonitor:
{
apiVersion: 'monitoring.coreos.com/v1',
kind: 'ServiceMonitor',
metadata: {
name: 'ups-exporter',
namespace: $._config.namespace,
labels: {
'k8s-app': 'ups-exporter',
},
},
spec: {
jobLabel: 'k8s-app',
selector: {
matchLabels: {
'k8s-app': 'ups-exporter',
},
},
endpoints: [
{
port: 'metrics',
scheme: 'http',
interval: '30s',
},
],
},
},
service:
local service = k.core.v1.service;
local servicePort = k.core.v1.service.mixin.spec.portsType;
local upsExporterPort = servicePort.newNamed('metrics', 9099, 9099);
service.new('ups-exporter', null, upsExporterPort) +
service.mixin.metadata.withNamespace($._config.namespace) +
service.mixin.metadata.withLabels({ 'k8s-app': 'ups-exporter' }) +
service.mixin.spec.withClusterIp('None'),
endpoints:
local endpoints = k.core.v1.endpoints;
local endpointSubset = endpoints.subsetsType;
local endpointPort = endpointSubset.portsType;
local upsPort = endpointPort.new() +
endpointPort.withName('metrics') +
endpointPort.withPort(9099) +
endpointPort.withProtocol('TCP');
local subset = endpointSubset.new() +
endpointSubset.withAddresses([
{ ip: IP }
for IP in $._config.ups.ips
]) +
endpointSubset.withPorts(upsPort);
endpoints.new() +
endpoints.mixin.metadata.withName('ups-exporter') +
endpoints.mixin.metadata.withNamespace($._config.namespace) +
endpoints.mixin.metadata.withLabels({ 'k8s-app': 'ups-exporter' }) +
endpoints.withSubsets(subset),
},
}