@@ -90,19 +90,29 @@ Run the script as follows and observe the usage information shown. Note how the
9090description appears along with the ` c ` argument.
9191``` bash
9292python adder.py --help
93- usage: adder.py [-h] [--name NAME] [--log LOG] [--log-level LOG_LEVEL]
94- [--quiet]
93+ usage: adder.py [-h] [--name NAME] [--log-level LOG_LEVEL]
94+ [--log-format {json,pretty}] [--log-file LOG_FILE] [--quiet]
95+ [--metric-grouping-interval METRIC_GROUPING_INTERVAL]
96+ [--debug]
9597 {run} ...
9698
9799Adds numbers
98100
99101optional arguments:
100102 -h, --help show this help message and exit
101103 --name NAME Name to identify this instance
102- --log LOG Name of log file
103104 --log-level LOG_LEVEL
104105 Logging level as picked from the logging module
105- --quiet
106+ --log-format {json,pretty}
107+ Force the format of the logs. By default, if the
108+ command is from a terminal, print colorful logs.
109+ Otherwise print json.
110+ --log-file LOG_FILE Writes logs to log file if specified, default: None
111+ --quiet if true, does not print logs to stderr, default: False
112+ --metric-grouping-interval METRIC_GROUPING_INTERVAL
113+ To group metrics based on time interval ex:10 i.e; (10
114+ sec)
115+ --debug To run the code in debug mode
106116
107117commands:
108118 {run}
@@ -137,3 +147,30 @@ https://docs.python.org/2/library/logging.html#logging-levels.
137147
138148` log` is a log object created using python' s standard `logging` module. You can
139149read more about it at https://docs.python.org/2/library/logging.html.
150+
151+ ### Metric-Grouping
152+ We can collect the Metrics based on time interval.
153+ test.py
154+ ```
155+ from basescript import BaseScript
156+ import time
157+ import random
158+
159+ class Stats(BaseScript):
160+ def __init__(self):
161+ super(Stats, self).__init__()
162+
163+ def run(self):
164+ ts = time.time()
165+ while True:
166+ # New Metric Format.
167+ self.log.info("stats", time_duration=(time.time()-ts), type="metric", random_number=random.randint(1, 50))
168+
169+ if __name__ == ' __main__' :
170+ Stats().start()
171+ ```
172+
173+ Run the command to see the output.
174+ ```
175+ python test.py --metric-grouping-interval 5 run
176+ ```
0 commit comments