How to find bytes_in in Nginx? - nginx
I am using this module https://github.com/Lax/ngx_http_accounting_module for accounting nginx request count and byte out
I can see bytes_out is used in code and is working fine .
code snippet:
ngx_http_accounting_handler(ngx_http_request_t *r){
..
stats->bytes_out += r->connection->sent;
}
But how to calculate bytes_in? any clue? I checked ngx_http_request_s & ngx_connection_s which has 'sent' data but not the receive data. Any suggestion would be really helpful
Thanks
Use r->request_length, much like it's done in nginx core for the $request_length log module variable.
I've updated ngx_http_accounting_module, adding bytes_in support.
The original version(v0.1) of ngx_http_accounting_module didn't implement bytes_in.
In v0.2, this value is added to the stats variable.
stats->nr_requests += 1;
+ stats->bytes_in += r->request_length;
stats->bytes_out += r->connection->sent;
Output format is changed as following code, adding bytes_in: to the output buffer.
- sprintf(output_buffer, "pid:%i|from:%ld|to:%ld|accounting_id:%s|requests:%ld|bytes_out:%ld",
+ sprintf(output_buffer, "pid:%i|from:%ld|to:%ld|accounting_id:%s|requests:%ld|bytes_in:%ld|bytes_out:%ld",
ngx_getpid(),
ngx_http_accounting_old_time,
ngx_http_accounting_new_time,
name,
stats->nr_requests,
+ stats->bytes_in,
stats->bytes_out
);
For more detail, see here: https://github.com/Lax/ngx_http_accounting_module/tree/v0.2 .
Thanks Maxim Dounin!
Related
Scilab - gui - many unknown variables error messages
Still trying to understand the logic of Scilab, I created a small calculation tool for a mechanical element. The main problem I have is finding the right order (or syntax) for the calculation code... I get a lot of "unknown variable" errors and I don't understand why? I tried to change the order of definitions for the functions, declare the variables as global, etc. but nothing seems to help. The code for the calculation is not long and also not complicated, but the gui was built using guibuilder, so the uicontrols definitions are probably much longer than they need to be. Could somebody help me make this code working, as I would learn and understand a lot by this example, althought it contains more than one "problem zones"? Here what I've done: G = 78500; table_titles = ["" "Wire diameter" "Wp" "Tau alwd" "M alwd" "Angle alwd"]; f=figure('figure_position',[910,163],'figure_size', [903,537],'auto_resize','on','background',[33],'figure_name','Graphic window number %d'); ////////// delmenu(f.figure_id,gettext('File')) delmenu(f.figure_id,gettext('?')) delmenu(f.figure_id,gettext('Tools')) toolbar(f.figure_id,'off') handles.dummy = 0; handles.sl_dwire=uicontrol(f,'unit','normalized','BackgroundColor', [-1,-1,-1],'Enable','on','FontAngle','normal','FontName','Tahoma', 'FontSize',[12],'FontUnits','points','FontWeight','normal', 'ForegroundColor',[-1,-1,-1],'HorizontalAlignment','left','ListboxTop', [],'Max',[12],'Min',[0],'Position', [0.0058208,0.77875,0.124375,0.06875],'Relief','default','SliderStep', [0.1,1],'Style','slider','String',"Wire diameter",'Value', [6],'VerticalAlignment','middle','Visible','on','Tag','sl_dwire', 'Callback','sl_dwire_callback(handles)') handles.ed_dwire=uicontrol(f,'unit','normalized','BackgroundColor', [-1,-1,-1],'Enable','off','FontAngle','normal','FontName','Tahoma', 'FontSize',[12],'FontUnits','points','FontWeight','normal', 'ForegroundColor',[-1,-1,-1],'HorizontalAlignment','left','ListboxTop', [],'Max',[1],'Min',[0], 'Position',[0.0058208,0.71875,0.124375,0.06875],'Relief', 'default','SliderStep',[0.01,0.1],'String',"wire diameter: " + msprintf('%2.1f',handles.sl_dwire.Value) + "mm",'Style','text', 'Value',[0],'VerticalAlignment','middle','Visible','on','Tag', 'ed_dwire','Callback','auto') handles.sl_wangle=uicontrol(f,'unit','normalized','BackgroundColor', [-1,-1,-1],'Enable','on','FontAngle','normal','FontName','Tahoma', 'FontSize',[12],'FontUnits','points','FontWeight','normal', 'ForegroundColor',[-1,-1,-1],'HorizontalAlignment','left', 'ListboxTop',[],'Max',[180],'Min',[5],'Position', [0.0090625,0.5191667,0.25625,0.0645833],'Relief','default', 'SliderStep',[0.1,1],'String','Working angle','Style','slider','Value', [50],'VerticalAlignment','middle','Visible','on','Tag','sl_wangle', 'Callback','sl_wangle_callback(handles)') handles.ed_wangle=uicontrol(f,'unit','normalized','BackgroundColor', [-1,-1,-1],'Enable','off','FontAngle','normal','FontName','Tahoma', 'FontSize',[12],'FontUnits','points','FontWeight','normal', 'ForegroundColor',[-1,-1,-1],'HorizontalAlignment','left', 'ListboxTop',[],'Max',[1],'Min',[0],'Position', [0.0090625,0.4591667,0.25625,0.0645833],'Relief','default', 'SliderStep',[0.01,0.1],'String',"Working angle: " + msprintf('%2.1f',handles.sl_wangle.Value) + "°",'Style','text', 'Value',[0],'VerticalAlignment','middle','Visible','on','Tag', 'ed_wangle','Callback','auto') handles.sl_activel=uicontrol(f,'unit','normalized', 'BackgroundColor',[-1,-1,-1],'Enable','on','FontAngle','normal', 'FontName','Tahoma','FontSize',[12],'FontUnits','points','FontWeight', 'normal','ForegroundColor',[-1,-1,-1],'HorizontalAlignment','left', 'ListboxTop',[],'Max',[1000],'Min',[10],'Position', [0.0090625,0.365,0.25625,0.0645833],'Relief','default', 'SliderStep',[0.1,1],'String','Active length' ,'Style','slider', 'Value',[10],'VerticalAlignment','middle','Visible','on','Tag', 'sl_activel','Callback','sl_activel_callback(handles)') handles.ed_activel=uicontrol(f,'unit','normalized', 'BackgroundColor',[-1,-1,-1],'Enable','off','FontAngle','normal', 'FontName','Tahoma','FontSize',[12],'FontUnits','points','FontWeight', 'normal','ForegroundColor',[-1,-1,-1],'HorizontalAlignment','left', 'ListboxTop',[],'Max',[1],'Min',[0],'Position', [0.0090625,0.305,0.25625,0.0645833],'Relief','default', 'SliderStep',[0.01,0.1],'String','Active length: ' + msprintf('%2.1f',handles.sl_activel.Value) + "mm",'Style','text','Value',[0],'VerticalAlignment','middle','Visible', 'on','Tag','ed_activel','Callback','auto') handles.ax_graph= newaxes();handles.ax_graph.margins = [ 0 0 0 0]; handles.ax_graph.axes_bounds = [0.4274266,0.0619266,0.3995485,0.5191743]; handles.tab_param=uicontrol(f,'unit','normalized','BackgroundColor', [-1,-1,-1],'Enable','on','FontAngle','normal','FontName', 'Tahoma','FontSize',[12],'FontUnits','points','FontWeight','normal', 'ForegroundColor',[-1,-1,-1],'HorizontalAlignment','left', 'ListboxTop',[],'Max',[1],'Min',[0], 'Position',[0.4308126,0.1690826,0.3950339,0.2178899],'Relief', 'default','SliderStep',[0.01,0.1],'String',string(table_param),'Style', 'table','Value',[0],'VerticalAlignment','middle','Visible', 'on','Tag','tab_param','Callback','tab_param_callback(handles)') handles.sl_sfactor=uicontrol(f,'unit','normalized', 'BackgroundColor',[-1,-1,-1],'Enable','on','FontAngle','normal', 'FontName','Tahoma','FontSize',[12],'FontUnits','points','FontWeight', 'normal','ForegroundColor',[-1,-1,-1],'HorizontalAlignment','left', 'ListboxTop',[],'Max',[1],'Min',[0], 'Position',[0.0058208,0.6525688,0.124375,0.06875],'Relief','default', 'SliderStep',[0.01,0.1],'String',"Safety factor",'Style', 'slider','Value',[0.58],'VerticalAlignment','middle','Visible','on', 'Tag','ed_sfactor','Callback','sl_sfactor_callback(handles)') handles.ed_sfactor=uicontrol(f,'unit','normalized', 'BackgroundColor',[-1,-1,-1],'Enable','off','FontAngle','normal', 'FontName','Tahoma','FontSize',[12],'FontUnits','points','FontWeight', 'normal','ForegroundColor',[-1,-1,-1],'HorizontalAlignment', 'left','ListboxTop',[],'Max',[1],'Min',[0],'Position', [0.0058208,0.5925688,0.124375,0.06875],'Relief','default', 'SliderStep',[0.01,0.1],'String',"Safety factor : " + msprintf('%2.1f',handles.sl_sfactor.Value),'Style', 'text','Value',[0.58],'VerticalAlignment','middle','Visible','on', 'Tag','ed_dwire','Callback','auto') handles.popm_wtype=uicontrol(f,'unit','normalized', 'BackgroundColor',[-1,-1,-1],'Enable','on','FontAngle','normal', 'FontName','Tahoma','FontSize',[12],'FontUnits','points','FontWeight', 'normal','ForegroundColor',[-1,-1,-1],'HorizontalAlignment','left', 'ListboxTop',[],'Max',[1],'Min',[0],'Position', [0.0058208,0.8618349,0.124375,0.0639450],'Relief','default', 'SliderStep',[0.01,0.1],'String',gettext("SL/DL|SM/DM|SH/DH"),'Style', 'popupmenu','Value',[2],'VerticalAlignment','middle','Visible','on', 'Tag','popm_wtype','Callback','popm_wtype_callback(handles)') ////////// // Callbacks are defined as below. Please do not delete the comments as it will be used in coming version ////////// function sl_sfactor_callback(handles) sf=handles.sl_sfactor.Value; handles.ed_sfactor.String="Safety factor: " + msprintf('%3.2f',sf); endfunction function sl_dwire_callback(handles) wd=handles.sl_dwire.Value; Wp = %pi*wd^3/16; Ip =%pi*wd^4/32; Kt = G*%pi*Ip/(180*L); Talwd = sf * calcform; Malwd = Wp * Talwd; alphaalwd = Malwd / Kt; x=0:0.1:alphaalwd*1.5; plot(x,Kt*x); handles.ed_dwire.String="Wire diameter: " + msprintf('%2.1f',wd) + "mm"; endfunction function popm_wtype_callback(handles) //Write your callback for popm_wtype here if selected == 1 then calcform =(1845 - 700*log10(wd)); elseif selected == 2 then calcform =(2105 - 780*log10(wd)); elseif selected == 3 then calcform = (2220 - 820*log10(wd)); end endfunction function sl_wangle_callback(handles) handles.ed_wangle.String="Working angle: " + msprintf('%2.1f',handles.sl_wangle.Value) + "°"; endfunction function sl_activel_callback(handles) //Write your callback for sl_activel here handles.ed_activel.String="Active length: " + msprintf('%2.1f',handles.sl_activel.Value) + "mm"; L=handles.sl_activel.Value; endfunction function tab_param_callback(handles) //Write your callback for tab_param here table_values = string([ wd Wp Talwd Malwd alphaalwd]); table_param = [table_titles; [table_values]]; endfunction I expect the code to dynamically update the graph and the parameters table according to the positions of input sliders and popup-menu. Again, it would be very helpful if somebody could help me get this code working, as I would get answers for a lot of my questions concerning programming with scilab. Thank you very much in advance!
First of all, your code is not directly executable, caused by the linebreaks. Please add ... after each line of a statement. This improves also the readability. As mentioned by #luispauloml, you try to use variables, which exist just inside of another function. For example you try to reach table_param, which is just alive in tab_param_callback(handles). To get rid of this, you have to define the output for the function: function [table_values, table_param] = tab_param_callback(handles) table_values = string([ wd Wp Talwd Malwd alphaalwd]); table_param = [table_titles; [table_values]]; endfunction Now you can call this function to get the variable: string(tab_param_callback(handles)) I corrected just this case and added the dots as explained. For the other variables, it can be done analogously. Furthermore, I moved the function definition to the beginning of the code. Because if your scrips crashed in the middle, the compiler has no chance to read the function definitions. Please find the code in this file . I hope this helps. Good luck!
Unable to read AT Command Response
I test some basic AT Command in Hyperterminal. The GSM modem response as per my command too. But problem is that it shows me the unreadable text. I use the following code : AT OK AT+CUSD=1,"*247#",15 OK +CUSD: 1,"0062004B006100730068000A00310020004D0032004D0020005400720061006E007300 6600650072000A0032002000440069007300620075007200730065000A00330020004D0079002000 62004B006100730068000A0034002000480065006C0070006C0069006E0065000A",72 AT+CUSD=1,"1",15 OK AT+CUSD=1,"*247#",15 command should display Menu 1 Menu 2 Menu 3 Something like that. But it displayed the hexadecimal code which it unreadable. How can I get plain text ? Can anyone help Me ?
Judging by information provided. Where when you send the +CUSD request with DCS (Data Coding Scheme) of 15. And the response from the Bkash service with DCS of 72. It looks like your modem does not support the encoding specified in the DCS from Bkash. I found is fairly similar question and solution to this question. Try and ensure that +CSCS is set to something like IRA or GSM and see what happens then with your +CUSD responses.
Use the following functions to decode "UCS2" response data: public static String HexStr2UnicodeStr(String strHex) { byte[] ba = Hex2ByteArray(strHex); return HexBytes2UnicodeStr(ba); } public static String HexBytes2UnicodeStr(byte[] ba) { var strMessage = Encoding.BigEndianUnicode.GetString(ba, 0, ba.Length); return strMessage; } for example: String str2 = SmsEngine.HexStr2UnicodeStr("0062004B006100730068000A00310020004D0032004D0020005400720061006E0073006600650072000A0032002000440069007300620075007200730065000A00330020004D007900200062004B006100730068000A0034002000480065006C0070006C0069006E0065000A"); // str2 = "bKash\n1 M2M Transfer\n2 Disburse\n3 My bKash\n4 Helpline\n" Please also check UnicodeStr2HexStr()
Hi this code is something called PDU (Protocol Data Unit). To decode it is not straight forward. you need to understand the structure first.
Peculiar error with ColdFusion on BlueDragon.NET
We've got an odd issue occurring with ColdFusion on BlueDragon.NET. Asking here because of the broad experience of StackOverflow users. Tags inside POSTed content to out BlueDragon.NET server gets removed, and we're not sure where in the stack it's getting removed. So for example if we post this data [CORE] Lesson_Status=Incomplete Lesson_Location=comm_13_a02_bs_enus_t17s06v01 score= time=00:00:56 [Core_Lesson] <sd ac="" pc="7.0" at="1289834380459" ct="" ><t id="lo8" sc=";;" st="c" /></sd> <sd ac='' pc='7.0' at='1289834380459' ct='' ><t id='lo8' sc=';;' st='c' /></sd> <sd ac="" pc="7.0" at="1289834380459" ct="" ><t id="lo8" sc=";;" st="c" /></sd> <sd ac="" pc="7.0" at="1289834380459" ct="" ><t id="lo8" sc=";;" st="c" /></sd> <b>hello1</b> <i>hello2</i> <table border><td>hello3</td></table> <sd>hello4</sd> <sd ac="1">hello5</sd> <t>hello6</t> <t /> <t attr="hello8" /> <strong>hello10</strong> <img> ><> What we get back is this: [CORE] Lesson_Status=Incomplete Lesson_Location=comm_13_a02_bs_enus_t17s06v01 score= time=00:00:56 [Core_Lesson] hello1 hello2 hello3 hello4 hello5 hello6 hello10 > That is, anything that starts with < and ends with > is getting stripped or filtered and no longer appears in ColdFusion's FORM scope when it's posted. Our server with BlueDragon JX does not suffer this problem. If we bypass using the default FORM scope and use this code, the tag-like content appears: <cfscript> // get the content string of the raw HTTP headers, will include all POST content as a long querystring RAWREQUEST = GetHttpRequestData(); // split the string on "&" character, each variable should now be separate // note that at this point duplicate variables will get clobbered RAWFORMFIELDS = ListToArray(RAWREQUEST.content, "&"); // We're creating a structure like "FORM", but better BetterFORM = StructNew(); // Go over each of the raw form fields, take the key // and add it as a key, and decode the value into the value field // and trap the whole thing if for some reason garbage gets in there for(i=1;i LTE ArrayLen(RAWFORMFIELDS);i = i + 1) { temp = ListToArray(RAWFORMFIELDS[i], "="); try { tempkey = temp[1]; tempval = URLDecode(temp[2]); StructInsert(BetterFORM, tempkey, tempval); } catch(Any e) { tempThisError = "Malformed Data: " & RAWFORMFIELDS[i]; // Log the value of tempThisError here? // WriteOutput(tempThisError); } } </cfscript> <cfdump var="#BetterFORM#"> If we do this, and use the created BetterFORM variable, it's there, so it does not seem to be a problem with the requests being filtered at some other point in the stack. I was thinking maybe it was URLScan, but that appears not to be installed. Since BD.NET runs on .NET as the engine, perhaps there's some sanitization setting that is being used on all variables somehow? Suggestions, ideas, etc are welcome on this issue.
I don't have a BD.NET instance handy to check, but Adobe ColdFusion has a setting in the cf administrator to strip "invalid tags". That's my best guess. Adobe CF replaces them with "invalidTag", my guess is that BD.Net just strips it silently.
It turned out to be very mundane. We had a custom tag that did customized string replacements. On one server, it was modified to NOT replace all tags. On this server, we were using an older version that did. So the fault was not a difference between BlueDragon JX and BlueDragon.NET -- it was developer team error.
Is there a standard way to diff du outputs to detect where disk space usage has grown the most
I work with a small team of developers where we share a unix file system to store somewhat large datasets. This file system has a somewhat prohibitive quota on it so about once a month we have to figure out where our free space has gone and see what we can recover. Obviously we use du a fair amount but this is still a tedious process. I had the thought that we may be able to keep last months du output around and compare it to this months to see where we've had the most growth. My guess this plan isn't very original. With this in mind I am asking if there are any scripts out there that already do this. Thanks.
I wrote a program to do this called diff-du. I can't believe nobody had already done this! Anyhow, I find it useful and I hope you will too.
I really don't know if there is a standard way but I need it sometime ago and I wrote a small perl script to handle that. Here is the part of my code: #!/usr/bin/perl $FileName = "du-previous"; $Location = ">"; $Sizes; # Current +++++++++++++++++++++++++++++ $Current = `du "$Location"`; open my $CurrentFile, '<', \$Current; while (<$CurrentFile>) { chomp; if (/^([0-9]+)[ \t]+(.*)$/) { $Sizes{$2} = $1; } } close($CurrentFile); # Previous ++++++++++++++++++++++++++++ open(FILE, $FileName); while (<FILE>) { chomp; if (/^([0-9]+)[ \t]+(.*)$/) { my $Size = $Sizes{$2}; $Sizes{$2} = $Size - $1; } } close(FILE); # Show result +++++++++++++++++++++++++ SHOW: while (($key, $value) = each(%Sizes)) { if ($value == 0) { next SHOW; } printf("%-10d %s\n", $value, $key); } close(FILE); #Save Current +++++++++++++++++++++++++ open my $CurrentFile, '<', \$Current; open(FILE, ">$FileName"); while (<$CurrentFile>) { chomp; print FILE $_."\n"; } close($CurrentFile); close(FILE); The code is not very error-tolerant so you may adjust it. Basically the code, get the current disk usage information, compare the size with the lastest time it run (saved in 'du-previous'), print the different and save the current usage information. If you like it, take it. Hope this helps.
What you really really want is the awesome kdirstat.
For completeness, I've also found du-diff and don't see it mentioned in any other answer. Andrew's diff-du (mentioned in another answer) seems to be more advanced that this one.
Flex: Binding to an MXML-esque "binding string" in action script?
Is it possible to specify MXML-esque "binding strings" in ActionScript? For example, I want to be able to do something like: MXMLBinding(this, "first_item", this, "{myArrayCollection.getItemAt(0)"); MXMLBinding(this, ["nameLbl", "text"], this, "Name: {somePerson.first} {somePerson.last}"); Edit: thanks for the responses and suggestions… Basically, it seems like you can't do this. I've dug around and figured out why.
(Shameless plug) BindageTools can do this: Bind.fromProperty(this, "myArrayCollection", itemAt(0)) .toProperty(this, "first_item"); Bind.fromAll( Bind.fromProperty(this, "somePerson.first"), Bind.fromProperty(this, "somePerson.last") ) .format("Name: {0} {1}") .toProperty(this, "nameLbl.text"); Note that BindageTools puts the source object first and the destination last (whereas BindingUtils puts the destination first and the source last).
Using ChangeWatcher (e.g., via BindingUtils.bindProperty or .bindSetter) is the way to go, yes. I admit it's a strange notation, but once you get used to it, it makes sense, works perfectly and is quite flexible, too. Of course, you could always wrap those functions yourself somehow, if the notation bugged you -- both methods are static, so doing so in a way that feels more appropriate to your application should be a fairly straightforward exercise.
I could use BindingUtils or ChainWatcher, but then I'd end up with code that looks something like this: … BindingUtils.bindSetter(updateName, this, ["somePerson", "first"]); BindingUtils.bindSetter(updateName, this, ["somePerson", "last"]); … protected function updateName(...ignored):void { this.nameLbl.text = "Name: " + somePerson.first + " " + somePerson.last; } Which is just a little bit ugly… And the first example, binding to arrayCollection.getItemAt(0), is even worse.
Does the first parameter (function) of BindingUtils.bindSetter method accept anonymous methods? BindingUtils.bindSetter(function() { this.nameLbl.text = "Name: " + somePerson.first + " " + somePerson.last; }, this, ["somePerson", "last"]); I hate anonymous methods and obviously it's even more uglier - so I won't recommend that even if it works, but just wondering if it works.
Never the answer anyone wants to hear, but just manage this stuff with getters/setters in ActionScript. With a proper MVC, it's dead simple to manually set your display fields. public function set myArrayCollection(value:Array):void { myAC = new ArrayCollection(value); first_item = mcAC.getItemAt(0); // or value[0]; } etc....
Alright, so I've done some digging, and here's what's up. Bindings in MXML are, contrary to reason, setup by Java code (modules/compiler/src/java/flex2/compiler/as3/binding/DataBindingFirstPassEvaluator.java, if I'm not mistaken) at compile time. For example, the binding: first_item="{myArrayCollection.getItemAt(0)}"` is expanded into, among other things, this: // writeWatcher id=0 shouldWriteSelf=true class=flex2.compiler.as3.binding.PropertyWatcher shouldWriteChildren=true watchers[0] = new mx.binding.PropertyWatcher("foo", { propertyChange: true }, // writeWatcherListeners id=0 size=1 [ bindings[0] ], propertyGetter); // writeWatcher id=1 shouldWriteSelf=true class=flex2.compiler.as3.binding.FunctionReturnWatcher shouldWriteChildren=true watchers[1] = new mx.binding.FunctionReturnWatcher("getItemAt", target, function():Array { return [ 0 ]; }, { collectionChange: true }, [bindings[0]], null); // writeWatcherBottom id=0 shouldWriteSelf=true class=flex2.compiler.as3.binding.PropertyWatcher watchers[0].updateParent(target); // writeWatcherBottom id=1 shouldWriteSelf=true class=flex2.compiler.as3.binding.FunctionReturnWatcher // writeEvaluationWatcherPart 1 0 parentWatcher watchers[1].parentWatcher = watchers[0]; watchers[0].addChild(watchers[1]); This means that it is simply impossible to setup curly-brace MXML-style bindings at runtime because the code to do it does not exist in ActionScript.