This repository has been archived by the owner on Sep 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jmxmarathondataaggregator.py
82 lines (65 loc) · 3.6 KB
/
jmxmarathondataaggregator.py
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
81
82
"""
JMXMarathonDataAggregator.py
Author: Steven Gantz
Date: 11/22/2016
This script was designed to be used with Marathon, Prometheus,
and the JMXExporter project to allow Prometheus to retrieve data
from multiple instances of a java container created through Marathon.
Prometheus is unable to view each of these individual instances when
they are hidden behind a proxy and/or load balancer. The only data that
is passed depends on which container Prometheus hits when making a request.
This application can be run from any location, and is given a Marathon url.
The REST Api is then queried and the actual machinename:port is retrieved.
The app will then retrieve the data from every available machine:port/metrics
endpoint and port them to a preset list of ports.
Usage: python3 jmxmarathondataaggregator.py <marathonurl> <appid> <totalScaledInstances>
marathonurl: Full URL of marathon instance whose API will be queried
appid: Full Appid to use within the REST Api calls
totalScaledInstances: Total number of ports to expose based on max number of scaled instances
The License for this application is located at the bottom of the file.
"""
# Official Imports
import sys # Command line arguments
# Local Imports
from commandlineargumentshandler import CommandLineArgumentsHandler
from marathonrestservice import MarathonRestService
from serverhandler import ServerHandler
from expose_metrics import MetricsHandler
from metrics_obj import Metrics
def usageCheck():
""" Run at the start of the application for verify structure """
# Check python version 3 is being used
if sys.version_info[0] < 3:
print("You must use Python 3 to run this script.")
sys.exit(1)
# Verify command line arguments
if len(sys.argv) != 4:
print("Usage: python3 jmxmarathondataaggregator.py <marathonurl> <appid> <totalScaledInstances>")
exit(1);
print("Arguments verified... Initializing...")
usageCheck() # Verify correct inputs entered
inputArgs = CommandLineArgumentsHandler(sys.argv) # Retrieve command line arguments
metrics = Metrics()
client = MarathonRestService(inputArgs.marathonURL, inputArgs.appid) # build marathon service
server = ServerHandler(inputArgs, client, metrics) # build initial server handler
handler = MetricsHandler(metrics) # Start up metrics endpoint
server.startSocketServers() # Kick off socket servers
"""
MIT License
Copyright (c) 2016 Steven Gantz
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""