iis_bridge is a python package for manipulating IIS and monitoring iis pools' memory on windows.
IIS = Internet Information Services. It's a .net web app server.
iis_bridge has been tested with python 2.7 on:
pip install iis_bridge
import iis_bridge as iis # to install iis: iis.install() print("iis version %s" % iis.get_version()) # to reset iis: iis.iisreset()
import iis_bridge as iis # to list the pool names: print(iis.get_pool_names()) # to list the site names: print(iis.get_site_names())
def create(name, runtime_version="4.0", pipeline_mode="Integrated"):As you can see, by default, a 4.0 pool with integrated mode is created.
import iis_bridge.pool as pool if not pool.exists("some_pool"): pool.create("some_pool") if pool.is_running("some_pool"): print("The pool is running!")
import iis_bridge.pool as pool pool.stop("some_pool") pool.stat("some_pool") pool.restart("some_pool")
import iis_bridge.pool as pool pool.config("DefaultAppPool", thirty_two_bit=False) pool.config("DefaultAppPool", identity="ApplicationPoolIdentity") pool.config("DefaultAppPool", identity="LocalService") pool.config("DefaultAppPool", identity="LocalSystem") pool.config("DefaultAppPool", identity="NetworkService") pool.config("DefaultAppPool", identity="SpecificUser", username="my_username", password="my_pass") # to set the idle timeout to 30 minutes: pool.config("DefaultAppPool", idle_timeout="00:30:00") # note that small values ()like 10 seconds) are not allowed pool.config("DefaultAppPool", pipeline_mode="Classic")
import iis_bridge.pool as pool if pool.exists("some_pool"): pool.delete("some_pool")
# to add an iis site on port 5050: import iis_bridge.site as site # site name, port number, app directory, app pool name site.create("mysite", 5050, r"C:\inetpub\wwwroot\myapp", "mypool") # now to list the site names: print(iis.get_site_names())
def monitor_with_load(iterations, # this is the number of iterations of sending the requests = Total duration of sending requests urls, # list of urls to send the requests to. If 'all' is specified, it retrieves the app pools and sends requests to http://localhost:[port] rate, # how many parallel requests to send per iteration mem_type='WorkingSetPrivate', # the type of memory to monitor mem_unit='KB', # the units of memory to monitor timeout=15 # http timeout in seconds ) def html_report(datasets, # the datasets to plot mem_type='WorkingSetPrivate', # the type of memory to monitor mem_unit='KB', # the memory unit: Bytes, KB, MB output_path='out.html', # the path where to save the html report pools_to_monitor=None # list of pools to plot. If not specified, all pools will be plotted ):Here is an example how to monitor the private working set memory of all the application pools for 6 seconds while sending 12 parallel GET http requests per second. The http_report method generates an out.html in the current directory. You can specify output path using the output_path parameter.
import iis_bridge.mon as mon datasets = mon.monitor_with_load(6, 'all', 12, timeout=30) # timeout is in seconds - default=15sec mon.html_report(datasets)which results in:
import iis_bridge.mon as mon import iis_bridge.site as site app1_port = site.get_port("App1") app2_port = site.get_port("App2") urls = ["http://localhost:%s?add=3,4,5" % app1_port,\ "http://localhost:%s" % app2_port,\ ["http://localhost:190/CalcService.svc/multiply", "POST", {"list":[1,2,3]}, "json"],\ ["http://localhost:190/CalcService.svc/multiply", "POST", "", "xml"] ] pools = ["App1", "App2"] mem_unit = 'MB' duration = 10 # seconds reqs_per_sec = 16 # how many request to send per second datasets = mon.monitor_with_load(duration, urls, reqs_per_sec, mem_unit=mem_unit) mon.html_report(datasets, pools_to_monitor=pools, mem_unit=mem_unit) print("Done")
1 2 3
site.get_port("App1")allows you to get the port number of a site called App1 which eliminates hard-coding port numbers hence reducing maintanance. If you specify a url as a string, the default behaviour (GET request html type) will be assumed.
import iis_bridge.mem as mem for w in mem.get_workers(): print(str(w)) output>> DefaultAppPool: pid=12768 WorkingSetPrivate=10052
http_thread = load_gen.HttpFlood(iterations, # number of iterations urls, # the list of urls to send http requests to rate, # the number of reuqests to send per interval (default per second) interval=interval, # (optional default=1 second) the interval between iterations of parallel requests timeout=15 # http timeout in seconds )And here is how to use it:
import iis_bridge.load_gen as load_gen urls = ["http://localhost:80",\ "http://localhost:81/Default.aspx",\ "http://localhost:82/Default.aspx"] # send 6 requests per second for 10 seconds: http_thread = load_gen.HttpFlood(10, urls, 6) http_thread.start() # do your own monitoring if you prefer another tool http_thread.join() # wait for the http generator to stop print("Number of successful requests sent: %i" % http_thread.total_resp_received) print("Average response time: %f seconds" % http_thread.avg_res_time)Note that the default interval is 1 second and rate is the number of parallel requests to send per iteration.
iis.register_asp()
import iis_bridge.isapi as isapi isapi.enable()
import iis_bridge as iis iis.install_wcf()
# to install WCF-Services45 and CF-HTTP-Activation45: import iis_bridge as iis iis.install_wcf(["WCF-Services45", "WCF-HTTP-Activation45"])