junos-exporter 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- junos_exporter-0.0.1/.github/workflows/docker-publish.yml +58 -0
- junos_exporter-0.0.1/.github/workflows/pypi-publish.yml +25 -0
- junos_exporter-0.0.1/.gitignore +10 -0
- junos_exporter-0.0.1/Dockerfile +19 -0
- junos_exporter-0.0.1/LICENSE +21 -0
- junos_exporter-0.0.1/PKG-INFO +191 -0
- junos_exporter-0.0.1/README.md +155 -0
- junos_exporter-0.0.1/config.yml +79 -0
- junos_exporter-0.0.1/junos_exporter/__init__.py +0 -0
- junos_exporter-0.0.1/junos_exporter/__main__.py +4 -0
- junos_exporter-0.0.1/junos_exporter/cli.py +64 -0
- junos_exporter-0.0.1/junos_exporter/config.py +125 -0
- junos_exporter-0.0.1/junos_exporter/connector.py +157 -0
- junos_exporter-0.0.1/junos_exporter/exporter.py +115 -0
- junos_exporter-0.0.1/op/.gitkeep +0 -0
- junos_exporter-0.0.1/pyproject.toml +70 -0
- junos_exporter-0.0.1/textfsm/.gitkeep +0 -0
- junos_exporter-0.0.1/uv.lock +799 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
name: Docker Publish
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags: [ 'v*.*.*' ]
|
|
6
|
+
|
|
7
|
+
env:
|
|
8
|
+
REGISTRY: ghcr.io
|
|
9
|
+
IMAGE_NAME: ${{ github.repository }}
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
build:
|
|
13
|
+
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
permissions:
|
|
16
|
+
contents: read
|
|
17
|
+
packages: write
|
|
18
|
+
id-token: write
|
|
19
|
+
|
|
20
|
+
steps:
|
|
21
|
+
- name: Checkout repository
|
|
22
|
+
uses: actions/checkout@v4
|
|
23
|
+
|
|
24
|
+
- name: Install cosign
|
|
25
|
+
uses: sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 #v3.5.0
|
|
26
|
+
|
|
27
|
+
- name: Set up Docker Buildx
|
|
28
|
+
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
|
|
29
|
+
|
|
30
|
+
- name: Log into registry ${{ env.REGISTRY }}
|
|
31
|
+
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
|
|
32
|
+
with:
|
|
33
|
+
registry: ${{ env.REGISTRY }}
|
|
34
|
+
username: ${{ github.actor }}
|
|
35
|
+
password: ${{ secrets.GITHUB_TOKEN }}
|
|
36
|
+
|
|
37
|
+
- name: Extract Docker metadata
|
|
38
|
+
id: meta
|
|
39
|
+
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
|
|
40
|
+
with:
|
|
41
|
+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
|
42
|
+
|
|
43
|
+
- name: Build and push Docker image
|
|
44
|
+
id: build-and-push
|
|
45
|
+
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
|
|
46
|
+
with:
|
|
47
|
+
context: .
|
|
48
|
+
push: true
|
|
49
|
+
tags: ${{ steps.meta.outputs.tags }}
|
|
50
|
+
labels: ${{ steps.meta.outputs.labels }}
|
|
51
|
+
cache-from: type=gha
|
|
52
|
+
cache-to: type=gha,mode=max
|
|
53
|
+
|
|
54
|
+
- name: Sign the published Docker image
|
|
55
|
+
env:
|
|
56
|
+
TAGS: ${{ steps.meta.outputs.tags }}
|
|
57
|
+
DIGEST: ${{ steps.build-and-push.outputs.digest }}
|
|
58
|
+
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
name: PyPI Publish
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags: ['v*.*.*']
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
publish:
|
|
9
|
+
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
permissions:
|
|
12
|
+
id-token: write
|
|
13
|
+
|
|
14
|
+
steps:
|
|
15
|
+
- name: Checkout repository
|
|
16
|
+
uses: actions/checkout@v4
|
|
17
|
+
|
|
18
|
+
- name: Install uv
|
|
19
|
+
uses: astral-sh/setup-uv@v5
|
|
20
|
+
|
|
21
|
+
- name: Build
|
|
22
|
+
run: uv build
|
|
23
|
+
|
|
24
|
+
- name: Publish to PyPI
|
|
25
|
+
run: uv publish
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim AS builder
|
|
2
|
+
ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy
|
|
3
|
+
ENV UV_PYTHON_DOWNLOADS=0
|
|
4
|
+
|
|
5
|
+
WORKDIR /app
|
|
6
|
+
RUN --mount=type=cache,target=/root/.cache/uv \
|
|
7
|
+
--mount=type=bind,source=uv.lock,target=uv.lock \
|
|
8
|
+
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
|
|
9
|
+
uv sync --frozen --no-install-project --no-dev
|
|
10
|
+
ADD . /app
|
|
11
|
+
RUN --mount=type=cache,target=/root/.cache/uv \
|
|
12
|
+
uv sync --frozen --no-dev
|
|
13
|
+
|
|
14
|
+
FROM python:3.12-slim-bookworm
|
|
15
|
+
|
|
16
|
+
COPY --from=builder --chown=app:app /app /app
|
|
17
|
+
WORKDIR /app
|
|
18
|
+
ENV PATH="/app/.venv/bin:$PATH"
|
|
19
|
+
ENTRYPOINT ["junos-exporter"]
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 minefuto
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: junos-exporter
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Prometheus Exporter for Junos using PyEZ Tables and Views
|
|
5
|
+
Project-URL: Repository, https://github.com/minefuto/junos-exporter.git
|
|
6
|
+
Author-email: minefuto <minefuto@gmail.com>
|
|
7
|
+
License: MIT License
|
|
8
|
+
|
|
9
|
+
Copyright (c) 2025 minefuto
|
|
10
|
+
|
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
13
|
+
in the Software without restriction, including without limitation the rights
|
|
14
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
16
|
+
furnished to do so, subject to the following conditions:
|
|
17
|
+
|
|
18
|
+
The above copyright notice and this permission notice shall be included in all
|
|
19
|
+
copies or substantial portions of the Software.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
|
+
SOFTWARE.
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
Requires-Python: <3.13,>=3.10
|
|
30
|
+
Requires-Dist: fastapi>=0.115.8
|
|
31
|
+
Requires-Dist: junos-eznc>=2.7.2
|
|
32
|
+
Requires-Dist: ntc-templates>=7.7.0
|
|
33
|
+
Requires-Dist: pyyaml>=6.0.2
|
|
34
|
+
Requires-Dist: uvicorn>=0.34.0
|
|
35
|
+
Description-Content-Type: text/markdown
|
|
36
|
+
|
|
37
|
+
# junos-exporter
|
|
38
|
+
|
|
39
|
+
## Overview
|
|
40
|
+
This is a Prometheus Exporter for Junos using PyEZ([Juniper/py-junos-eznc](https://github.com/Juniper/py-junos-eznc)) Tables and Views.
|
|
41
|
+
PyEZ can extract information from Junos operational command output and map it to a Python data structure via yaml.
|
|
42
|
+
`junos-exporter` converts the information provided by PyEZ into the Prometheus metrics format via yaml.
|
|
43
|
+
So, this exporter's metrics can be flexibly configured by simply editing yaml.
|
|
44
|
+
|
|
45
|
+
## Usage
|
|
46
|
+
1. Clone the repository:
|
|
47
|
+
```bash
|
|
48
|
+
git clone https://github.com/minefuto/junos-exporter.git
|
|
49
|
+
cd junos-exporter
|
|
50
|
+
```
|
|
51
|
+
2. Configure the exporter by editing the `config.yml`
|
|
52
|
+
3. Run the exporter:
|
|
53
|
+
```bash
|
|
54
|
+
uv run -m junos_exporter
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Configuration
|
|
58
|
+
Please see the `config.yml` for configuration example.
|
|
59
|
+
|
|
60
|
+
#### Create Exporter Config
|
|
61
|
+
```yaml
|
|
62
|
+
general:
|
|
63
|
+
port: 9326 # exporter's listen port
|
|
64
|
+
prefix: junos # prefix of the metrics
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
#### Create PyEZ Operational Tables
|
|
68
|
+
- [Parsing Structured Output](https://www.juniper.net/documentation/us/en/software/junos-pyez/junos-pyez-developer/topics/task/junos-pyez-tables-op-defining.html)
|
|
69
|
+
- [parsing Unstructured Output](https://www.juniper.net/documentation/us/en/software/junos-pyez/junos-pyez-developer/topics/topic-map/junos-pyez-tables-op-unstructured-output-defining.html)
|
|
70
|
+
- [Using TextFSM Template](https://www.juniper.net/documentation/us/en/software/junos-pyez/junos-pyez-developer/topics/concept/junos-pyez-tables-op-using-textfsm-templates.html)
|
|
71
|
+
|
|
72
|
+
Please store the following configured(config.yml) directory.
|
|
73
|
+
```yaml
|
|
74
|
+
general:
|
|
75
|
+
optables_dir: ./op/ # store the structured & unstructured tables and views configuration file
|
|
76
|
+
textfsm_dir: ./textfsm/ # store the textfsm template file
|
|
77
|
+
```
|
|
78
|
+
If using the following predefined operational table, you can skip this step.
|
|
79
|
+
- [Document](https://www.juniper.net/documentation/us/en/software/junos-pyez/junos-pyez-developer/topics/concept/junos-pyez-tables-op-predefined.html)
|
|
80
|
+
- [Source Code](https://github.com/Juniper/py-junos-eznc/tree/master/lib/jnpr/junos/op)
|
|
81
|
+
|
|
82
|
+
#### Create Convert Rule
|
|
83
|
+
```yaml
|
|
84
|
+
optables:
|
|
85
|
+
EthPortTable: # pyez table name
|
|
86
|
+
metrics:
|
|
87
|
+
- name: interface_link_status # metrics name
|
|
88
|
+
value: oper # metrics value
|
|
89
|
+
type: gauge # metrics type(gauge or count or untyped)
|
|
90
|
+
help: physical interface link status(up:2, down:1) # metrics help
|
|
91
|
+
value_transform: #(optional) if metrics value is str, can be transformed to float
|
|
92
|
+
up: 2
|
|
93
|
+
down: 1
|
|
94
|
+
labels:
|
|
95
|
+
- name: interface # label name
|
|
96
|
+
value: name # label value
|
|
97
|
+
- name: description
|
|
98
|
+
value: description
|
|
99
|
+
regex: .* #(optional) label values can be extracted by using regexp
|
|
100
|
+
- name: link_mode
|
|
101
|
+
value: link_mode
|
|
102
|
+
- name: mac
|
|
103
|
+
value: macaddr
|
|
104
|
+
```
|
|
105
|
+
`metrics value` and `label value` select from fields key of PyEZ View.
|
|
106
|
+
```yaml
|
|
107
|
+
EthPortView:
|
|
108
|
+
groups:
|
|
109
|
+
mac_stats: ethernet-mac-statistics
|
|
110
|
+
flags: if-device-flags
|
|
111
|
+
fields: <- !!
|
|
112
|
+
oper: oper-status
|
|
113
|
+
admin: admin-status
|
|
114
|
+
description: description
|
|
115
|
+
mtu: { mtu : int }
|
|
116
|
+
link_mode: link-mode
|
|
117
|
+
macaddr: current-physical-address
|
|
118
|
+
-snip-
|
|
119
|
+
```
|
|
120
|
+
PyEZ Table's key is automatically mapping to `key` and `name`.
|
|
121
|
+
```yaml
|
|
122
|
+
EthPortTable:
|
|
123
|
+
rpc: get-interface-information
|
|
124
|
+
args:
|
|
125
|
+
media: True
|
|
126
|
+
interface_name: '[afgxe][et]-*'
|
|
127
|
+
args_key: interface_name <- !!
|
|
128
|
+
item: physical-interface
|
|
129
|
+
view: EthPortView
|
|
130
|
+
```
|
|
131
|
+
If there are multiple keys, a number is assigned at the end such as `key.0`, `key.1`.
|
|
132
|
+
```yaml
|
|
133
|
+
IsisAdjacencyTable:
|
|
134
|
+
rpc: get-isis-adjacency-information
|
|
135
|
+
args:
|
|
136
|
+
extensive: True
|
|
137
|
+
item: isis-adjacency
|
|
138
|
+
key:
|
|
139
|
+
- interface-name <- key.0, name.0
|
|
140
|
+
- system-name <- key.1, name.1
|
|
141
|
+
view: IsisAdjacencyView
|
|
142
|
+
```
|
|
143
|
+
The metrics value can be a static value.
|
|
144
|
+
```yaml
|
|
145
|
+
optables:
|
|
146
|
+
ArpTable:
|
|
147
|
+
metrics:
|
|
148
|
+
- name: arp_entry_info
|
|
149
|
+
value: 1 <- !!
|
|
150
|
+
type: gauge
|
|
151
|
+
help: arp entry info
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
#### Create Junos Device Config
|
|
155
|
+
```yaml
|
|
156
|
+
modules:
|
|
157
|
+
router: # module name
|
|
158
|
+
username: admin # junos device's username
|
|
159
|
+
password: admin@123 # junos device's password
|
|
160
|
+
tables: # pyez table name(which pyez table information to retrieve in this module)
|
|
161
|
+
- ArpTable
|
|
162
|
+
- EthPortTable
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
#### Create Prometheus Config
|
|
166
|
+
```yaml
|
|
167
|
+
scrape_configs:
|
|
168
|
+
- job_name: "junos-exporter"
|
|
169
|
+
static_configs:
|
|
170
|
+
- targets:
|
|
171
|
+
- "192.168.1.1" # target device
|
|
172
|
+
- "192.168.1.2"
|
|
173
|
+
labels:
|
|
174
|
+
module: "router" # module name
|
|
175
|
+
- targets:
|
|
176
|
+
- "192.168.10.3"
|
|
177
|
+
labels:
|
|
178
|
+
module: "switch"
|
|
179
|
+
relabel_configs:
|
|
180
|
+
- source_labels: [module]
|
|
181
|
+
target_label: __param_module
|
|
182
|
+
- source_labels: [__address__]
|
|
183
|
+
target_label: __param_target
|
|
184
|
+
- source_labels: [__param_target]
|
|
185
|
+
target_label: instance
|
|
186
|
+
- target_label: __address__
|
|
187
|
+
replacement: 127.0.0.1:9326
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## License
|
|
191
|
+
MIT
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# junos-exporter
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
This is a Prometheus Exporter for Junos using PyEZ([Juniper/py-junos-eznc](https://github.com/Juniper/py-junos-eznc)) Tables and Views.
|
|
5
|
+
PyEZ can extract information from Junos operational command output and map it to a Python data structure via yaml.
|
|
6
|
+
`junos-exporter` converts the information provided by PyEZ into the Prometheus metrics format via yaml.
|
|
7
|
+
So, this exporter's metrics can be flexibly configured by simply editing yaml.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
1. Clone the repository:
|
|
11
|
+
```bash
|
|
12
|
+
git clone https://github.com/minefuto/junos-exporter.git
|
|
13
|
+
cd junos-exporter
|
|
14
|
+
```
|
|
15
|
+
2. Configure the exporter by editing the `config.yml`
|
|
16
|
+
3. Run the exporter:
|
|
17
|
+
```bash
|
|
18
|
+
uv run -m junos_exporter
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Configuration
|
|
22
|
+
Please see the `config.yml` for configuration example.
|
|
23
|
+
|
|
24
|
+
#### Create Exporter Config
|
|
25
|
+
```yaml
|
|
26
|
+
general:
|
|
27
|
+
port: 9326 # exporter's listen port
|
|
28
|
+
prefix: junos # prefix of the metrics
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
#### Create PyEZ Operational Tables
|
|
32
|
+
- [Parsing Structured Output](https://www.juniper.net/documentation/us/en/software/junos-pyez/junos-pyez-developer/topics/task/junos-pyez-tables-op-defining.html)
|
|
33
|
+
- [parsing Unstructured Output](https://www.juniper.net/documentation/us/en/software/junos-pyez/junos-pyez-developer/topics/topic-map/junos-pyez-tables-op-unstructured-output-defining.html)
|
|
34
|
+
- [Using TextFSM Template](https://www.juniper.net/documentation/us/en/software/junos-pyez/junos-pyez-developer/topics/concept/junos-pyez-tables-op-using-textfsm-templates.html)
|
|
35
|
+
|
|
36
|
+
Please store the following configured(config.yml) directory.
|
|
37
|
+
```yaml
|
|
38
|
+
general:
|
|
39
|
+
optables_dir: ./op/ # store the structured & unstructured tables and views configuration file
|
|
40
|
+
textfsm_dir: ./textfsm/ # store the textfsm template file
|
|
41
|
+
```
|
|
42
|
+
If using the following predefined operational table, you can skip this step.
|
|
43
|
+
- [Document](https://www.juniper.net/documentation/us/en/software/junos-pyez/junos-pyez-developer/topics/concept/junos-pyez-tables-op-predefined.html)
|
|
44
|
+
- [Source Code](https://github.com/Juniper/py-junos-eznc/tree/master/lib/jnpr/junos/op)
|
|
45
|
+
|
|
46
|
+
#### Create Convert Rule
|
|
47
|
+
```yaml
|
|
48
|
+
optables:
|
|
49
|
+
EthPortTable: # pyez table name
|
|
50
|
+
metrics:
|
|
51
|
+
- name: interface_link_status # metrics name
|
|
52
|
+
value: oper # metrics value
|
|
53
|
+
type: gauge # metrics type(gauge or count or untyped)
|
|
54
|
+
help: physical interface link status(up:2, down:1) # metrics help
|
|
55
|
+
value_transform: #(optional) if metrics value is str, can be transformed to float
|
|
56
|
+
up: 2
|
|
57
|
+
down: 1
|
|
58
|
+
labels:
|
|
59
|
+
- name: interface # label name
|
|
60
|
+
value: name # label value
|
|
61
|
+
- name: description
|
|
62
|
+
value: description
|
|
63
|
+
regex: .* #(optional) label values can be extracted by using regexp
|
|
64
|
+
- name: link_mode
|
|
65
|
+
value: link_mode
|
|
66
|
+
- name: mac
|
|
67
|
+
value: macaddr
|
|
68
|
+
```
|
|
69
|
+
`metrics value` and `label value` select from fields key of PyEZ View.
|
|
70
|
+
```yaml
|
|
71
|
+
EthPortView:
|
|
72
|
+
groups:
|
|
73
|
+
mac_stats: ethernet-mac-statistics
|
|
74
|
+
flags: if-device-flags
|
|
75
|
+
fields: <- !!
|
|
76
|
+
oper: oper-status
|
|
77
|
+
admin: admin-status
|
|
78
|
+
description: description
|
|
79
|
+
mtu: { mtu : int }
|
|
80
|
+
link_mode: link-mode
|
|
81
|
+
macaddr: current-physical-address
|
|
82
|
+
-snip-
|
|
83
|
+
```
|
|
84
|
+
PyEZ Table's key is automatically mapping to `key` and `name`.
|
|
85
|
+
```yaml
|
|
86
|
+
EthPortTable:
|
|
87
|
+
rpc: get-interface-information
|
|
88
|
+
args:
|
|
89
|
+
media: True
|
|
90
|
+
interface_name: '[afgxe][et]-*'
|
|
91
|
+
args_key: interface_name <- !!
|
|
92
|
+
item: physical-interface
|
|
93
|
+
view: EthPortView
|
|
94
|
+
```
|
|
95
|
+
If there are multiple keys, a number is assigned at the end such as `key.0`, `key.1`.
|
|
96
|
+
```yaml
|
|
97
|
+
IsisAdjacencyTable:
|
|
98
|
+
rpc: get-isis-adjacency-information
|
|
99
|
+
args:
|
|
100
|
+
extensive: True
|
|
101
|
+
item: isis-adjacency
|
|
102
|
+
key:
|
|
103
|
+
- interface-name <- key.0, name.0
|
|
104
|
+
- system-name <- key.1, name.1
|
|
105
|
+
view: IsisAdjacencyView
|
|
106
|
+
```
|
|
107
|
+
The metrics value can be a static value.
|
|
108
|
+
```yaml
|
|
109
|
+
optables:
|
|
110
|
+
ArpTable:
|
|
111
|
+
metrics:
|
|
112
|
+
- name: arp_entry_info
|
|
113
|
+
value: 1 <- !!
|
|
114
|
+
type: gauge
|
|
115
|
+
help: arp entry info
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
#### Create Junos Device Config
|
|
119
|
+
```yaml
|
|
120
|
+
modules:
|
|
121
|
+
router: # module name
|
|
122
|
+
username: admin # junos device's username
|
|
123
|
+
password: admin@123 # junos device's password
|
|
124
|
+
tables: # pyez table name(which pyez table information to retrieve in this module)
|
|
125
|
+
- ArpTable
|
|
126
|
+
- EthPortTable
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
#### Create Prometheus Config
|
|
130
|
+
```yaml
|
|
131
|
+
scrape_configs:
|
|
132
|
+
- job_name: "junos-exporter"
|
|
133
|
+
static_configs:
|
|
134
|
+
- targets:
|
|
135
|
+
- "192.168.1.1" # target device
|
|
136
|
+
- "192.168.1.2"
|
|
137
|
+
labels:
|
|
138
|
+
module: "router" # module name
|
|
139
|
+
- targets:
|
|
140
|
+
- "192.168.10.3"
|
|
141
|
+
labels:
|
|
142
|
+
module: "switch"
|
|
143
|
+
relabel_configs:
|
|
144
|
+
- source_labels: [module]
|
|
145
|
+
target_label: __param_module
|
|
146
|
+
- source_labels: [__address__]
|
|
147
|
+
target_label: __param_target
|
|
148
|
+
- source_labels: [__param_target]
|
|
149
|
+
target_label: instance
|
|
150
|
+
- target_label: __address__
|
|
151
|
+
replacement: 127.0.0.1:9326
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## License
|
|
155
|
+
MIT
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
general:
|
|
2
|
+
port: 9326
|
|
3
|
+
prefix: junos
|
|
4
|
+
optables_dir: ./op/
|
|
5
|
+
textfsm_dir: ./textfsm/
|
|
6
|
+
|
|
7
|
+
modules:
|
|
8
|
+
router:
|
|
9
|
+
username: admin
|
|
10
|
+
password: admin@123
|
|
11
|
+
tables:
|
|
12
|
+
- ArpTable
|
|
13
|
+
- EthPortTable
|
|
14
|
+
switch:
|
|
15
|
+
username: admin
|
|
16
|
+
password: admin@123
|
|
17
|
+
tables:
|
|
18
|
+
- ArpTable
|
|
19
|
+
- EthPortTable
|
|
20
|
+
|
|
21
|
+
optables:
|
|
22
|
+
ArpTable:
|
|
23
|
+
metrics:
|
|
24
|
+
- name: arp_entry_info
|
|
25
|
+
value: 1
|
|
26
|
+
type: gauge
|
|
27
|
+
help: arp entry info
|
|
28
|
+
labels:
|
|
29
|
+
- name: mac
|
|
30
|
+
value: mac_address
|
|
31
|
+
- name: address
|
|
32
|
+
value: ip_address
|
|
33
|
+
- name: interface
|
|
34
|
+
value: interface
|
|
35
|
+
EthPortTable:
|
|
36
|
+
metrics:
|
|
37
|
+
- name: interface_link_status
|
|
38
|
+
value: oper
|
|
39
|
+
type: gauge
|
|
40
|
+
help: physical interface link status(up:2, down:1)
|
|
41
|
+
value_transform:
|
|
42
|
+
up: 2
|
|
43
|
+
down: 1
|
|
44
|
+
- name: interface_admin_status
|
|
45
|
+
value: oper
|
|
46
|
+
type: gauge
|
|
47
|
+
help: physical interface admin status(up:2, down:1)
|
|
48
|
+
value_transform:
|
|
49
|
+
up: 2
|
|
50
|
+
down: 1
|
|
51
|
+
- name: interface_mtu
|
|
52
|
+
value: mtu
|
|
53
|
+
type: gauge
|
|
54
|
+
help: physical interface mtu
|
|
55
|
+
- name: interface_input_bytes
|
|
56
|
+
value: rx_bytes
|
|
57
|
+
type: counter
|
|
58
|
+
help: physical interface input bytes counter
|
|
59
|
+
- name: interface_output_bytes
|
|
60
|
+
value: tx_bytes
|
|
61
|
+
type: counter
|
|
62
|
+
help: physical interface output bytes counter
|
|
63
|
+
- name: interface_input_packets
|
|
64
|
+
value: rx_packets
|
|
65
|
+
type: counter
|
|
66
|
+
help: physical interface input packets counter
|
|
67
|
+
- name: interface_output_packets
|
|
68
|
+
value: tx_packets
|
|
69
|
+
type: counter
|
|
70
|
+
help: physical interface output packets counter
|
|
71
|
+
labels:
|
|
72
|
+
- name: interface
|
|
73
|
+
value: name
|
|
74
|
+
- name: description
|
|
75
|
+
value: description
|
|
76
|
+
- name: link_mode
|
|
77
|
+
value: link_mode
|
|
78
|
+
- name: mac
|
|
79
|
+
value: macaddr
|
|
File without changes
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import os
|
|
3
|
+
import sys
|
|
4
|
+
from collections.abc import AsyncGenerator
|
|
5
|
+
from contextlib import asynccontextmanager
|
|
6
|
+
from typing import Generator
|
|
7
|
+
|
|
8
|
+
import uvicorn
|
|
9
|
+
from fastapi import Depends, FastAPI
|
|
10
|
+
from fastapi.responses import PlainTextResponse
|
|
11
|
+
from pydantic import ValidationError
|
|
12
|
+
from starlette.exceptions import HTTPException as StarletteHTTPException
|
|
13
|
+
|
|
14
|
+
from .config import Config
|
|
15
|
+
from .connector import ConnecterBuilder, Connector
|
|
16
|
+
from .exporter import Exporter, ExporterBuilder
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@asynccontextmanager
|
|
20
|
+
async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
|
|
21
|
+
config = Config.get()
|
|
22
|
+
app.exporter = ExporterBuilder(config) # type: ignore
|
|
23
|
+
app.connector = ConnecterBuilder(config) # type: ignore
|
|
24
|
+
yield
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
app = FastAPI(default_response_class=PlainTextResponse, lifespan=lifespan)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@app.exception_handler(StarletteHTTPException)
|
|
31
|
+
def http_exception_handler(request, exc) -> PlainTextResponse:
|
|
32
|
+
return PlainTextResponse(content=str(exc.detail), status_code=exc.status_code)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def get_connector(target: str, module: str) -> Generator[Connector, None, None]:
|
|
36
|
+
with app.connector.build(target, module) as connector: # type: ignore
|
|
37
|
+
yield connector
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@app.get("/metrics")
|
|
41
|
+
def collect(
|
|
42
|
+
target: str, module: str, connector: Connector = Depends(get_connector)
|
|
43
|
+
) -> str:
|
|
44
|
+
exporter: Exporter = app.exporter.build(module) # type: ignore
|
|
45
|
+
return exporter.collect(connector)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def cli() -> None:
|
|
49
|
+
try:
|
|
50
|
+
parser = argparse.ArgumentParser()
|
|
51
|
+
parser.add_argument(
|
|
52
|
+
"-c",
|
|
53
|
+
"--config",
|
|
54
|
+
type=str,
|
|
55
|
+
default="config.yml",
|
|
56
|
+
help="configuration file path",
|
|
57
|
+
)
|
|
58
|
+
args = parser.parse_args()
|
|
59
|
+
config = Config(args.config)
|
|
60
|
+
uvicorn.run("junos_exporter.cli:app", host="0.0.0.0", port=config.port)
|
|
61
|
+
except FileNotFoundError:
|
|
62
|
+
sys.exit(f"config file({os.path.abspath(args.config)}) is not found")
|
|
63
|
+
except ValidationError as e:
|
|
64
|
+
sys.exit(f"config file({os.path.abspath(args.config)}) is invalid.\n{e}")
|