@@ -22,7 +22,7 @@ function get_contents(filename)
2222 local f = io.open (filename , " rb" )
2323 local contents = " "
2424 if f then
25- contents = f :read " *a"
25+ contents = f :read ( " *a" )
2626 f :close ()
2727 end
2828
3434function print_metric (metric , labels , value )
3535 local label_string = " "
3636 if labels then
37- for label ,value in pairs (labels ) do
38- label_string = label_string .. label .. ' ="' .. value .. ' ",'
37+ for label , value in pairs (labels ) do
38+ label_string = label_string .. label .. ' ="' .. value .. ' ",'
3939 end
4040 label_string = " {" .. string.sub (label_string , 1 , - 2 ) .. " }"
4141 end
6767function run_all_collectors (collectors )
6868 local metric_duration = metric (" node_scrape_collector_duration_seconds" , " gauge" )
6969 local metric_success = metric (" node_scrape_collector_success" , " gauge" )
70- for _ ,cname in pairs (collectors ) do
70+ for _ , cname in pairs (collectors ) do
7171 if col_mods [cname ] ~= nil then
7272 local duration , success = timed_scrape (col_mods [cname ])
73- local labels = {collector = cname }
73+ local labels = { collector = cname }
7474 metric_duration (labels , duration )
7575 metric_success (labels , success )
7676 end
8080-- Web server-specific functions
8181
8282function handle_request (env )
83- if env .PATH_INFO ~= ' /metrics' then
83+ if env .PATH_INFO ~= " /metrics" then
8484 uhttpd .send (" Status: 404 Not Found\r\n " )
8585 uhttpd .send (" Server: lua-metrics\r\n " )
8686 uhttpd .send (" Content-Type: text/plain\r\n\r\n " )
@@ -91,7 +91,7 @@ function handle_request(env)
9191 uhttpd .send (" Content-Type: text/plain; version=0.0.4\r\n\r\n " )
9292 local cols = {}
9393 for c in env .QUERY_STRING :gmatch (" collect[^=]*=([^&]+)" ) do
94- cols [# cols + 1 ] = c
94+ cols [# cols + 1 ] = c
9595 end
9696 if # cols == 0 then
9797 cols = col_names
@@ -107,12 +107,14 @@ col_names = {}
107107ls_fd = io.popen (" ls -1 /usr/lib/lua/prometheus-collectors/*.lua" )
108108for c in ls_fd :lines () do
109109 c = c :match (" ([^/]+)%.lua$" )
110- col_mods [c ] = require (' prometheus-collectors.' .. c )
111- col_names [# col_names + 1 ] = c
110+ col_mods [c ] = require (" prometheus-collectors." .. c )
111+ col_names [# col_names + 1 ] = c
112112end
113113ls_fd :close ()
114114
115- output = function (str ) uhttpd .send (str .. " \n " ) end
115+ output = function (str )
116+ uhttpd .send (str .. " \n " )
117+ end
116118
117119if arg ~= nil then
118120 output = print
0 commit comments