Project

General

Profile

Feature #1689 » lighttpd-1.4.19-fl_1.patch

Added total_connections (the total number of connections to the server) -- WilikPOS - Anonymous, 2008-06-13 07:11

View differences:

lighttpd-1.4.19-fl/src/mod_status.c 2008-06-13 01:49:01.000000000 -0500
553 553
	return 0;
554 554
}
555 555

  
556
static handler_t mod_status_handle_server_status_xml(server *srv, connection *con, void *p_d) {
557
	plugin_data *p = p_d;
558
	buffer *b;
559
	size_t j;
560
	double avg;
561
	char multiplier = '\0';
562
	char buf[32];
563
	time_t ts;
564

  
565
	int days, hours, mins, seconds;
566

  
567
	b = chunkqueue_get_append_buffer(con->write_queue);
568

  
569
	BUFFER_COPY_STRING_CONST(b, "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?><status>");
570

  
571
	BUFFER_APPEND_STRING_CONST(b, "<server-status><hostname><![CDATA[");
572
	buffer_append_string_buffer(b, con->uri.authority);
573
	BUFFER_APPEND_STRING_CONST(b, " (");
574
	buffer_append_string_buffer(b, con->server_name);
575
	BUFFER_APPEND_STRING_CONST(b, ")]]></hostname><uptime><![CDATA[");
576

  
577
	ts = srv->cur_ts - srv->startup_ts;
578

  
579
	days = ts / (60 * 60 * 24);
580
	ts %= (60 * 60 * 24);
581

  
582
	hours = ts / (60 * 60);
583
	ts %= (60 * 60);
584

  
585
	mins = ts / (60);
586
	ts %= (60);
587

  
588
	seconds = ts;
589

  
590
	if (days) {
591
		buffer_append_long(b, days);
592
		BUFFER_APPEND_STRING_CONST(b, " days ");
593
	}
594

  
595
	if (hours) {
596
		buffer_append_long(b, hours);
597
		BUFFER_APPEND_STRING_CONST(b, " hours ");
598
	}
599

  
600
	if (mins) {
601
		buffer_append_long(b, mins);
602
		BUFFER_APPEND_STRING_CONST(b, " min ");
603
	}
604

  
605
	buffer_append_long(b, seconds);
606
	BUFFER_APPEND_STRING_CONST(b, " s");
607

  
608
	BUFFER_APPEND_STRING_CONST(b, "]]></uptime><start_time><![CDATA[");
609

  
610
	ts = srv->startup_ts;
611

  
612
	strftime(buf, sizeof(buf) - 1, "%Y-%m-%d %H:%M:%S", localtime(&ts));
613
	buffer_append_string(b, buf);
614
	BUFFER_APPEND_STRING_CONST(b, "]]></start_time><stats><requests>");
615

  
616

  
617
	BUFFER_APPEND_STRING_CONST(b, "<absolute_since_start><![CDATA[");
618
	avg = p->abs_requests;
619

  
620
	mod_status_get_multiplier(&avg, &multiplier, 1000);
621

  
622
	buffer_append_long(b, avg);
623
	BUFFER_APPEND_STRING_CONST(b, " ");
624
	if (multiplier)	buffer_append_string_len(b, &multiplier, 1);
625
	BUFFER_APPEND_STRING_CONST(b, "req]]></absolute_since_start>");
626

  
627

  
628
	BUFFER_APPEND_STRING_CONST(b, "<average_since_start><![CDATA[");
629
	avg = p->abs_requests / (srv->cur_ts - srv->startup_ts);
630

  
631
	mod_status_get_multiplier(&avg, &multiplier, 1000);
632

  
633
	buffer_append_long(b, avg);
634
	BUFFER_APPEND_STRING_CONST(b, " ");
635
	if (multiplier)	buffer_append_string_len(b, &multiplier, 1);
636
	BUFFER_APPEND_STRING_CONST(b, "req/s]]></average_since_start>");
637

  
638

  
639
	BUFFER_APPEND_STRING_CONST(b, "<average_5s><![CDATA[");
640
	for (j = 0, avg = 0; j < 5; j++) {
641
		avg += p->mod_5s_requests[j];
642
	}
643

  
644
	avg /= 5;
645

  
646
	mod_status_get_multiplier(&avg, &multiplier, 1000);
647

  
648
	buffer_append_long(b, avg);
649
	BUFFER_APPEND_STRING_CONST(b, " ");
650
	if (multiplier)	buffer_append_string_len(b, &multiplier, 1);
651

  
652
	BUFFER_APPEND_STRING_CONST(b, "req/s]]></average_5s>");
653

  
654

  
655
	BUFFER_APPEND_STRING_CONST(b, "</requests><traffic><absolute_since_start><![CDATA[");
656
	avg = p->abs_traffic_out;
657

  
658
	mod_status_get_multiplier(&avg, &multiplier, 1024);
659

  
660
	sprintf(buf, "%.2f", avg);
661
	buffer_append_string(b, buf);
662
	BUFFER_APPEND_STRING_CONST(b, " ");
663
	if (multiplier)	buffer_append_string_len(b, &multiplier, 1);
664
	BUFFER_APPEND_STRING_CONST(b, "byte]]></absolute_since_start>");
665

  
666
	BUFFER_APPEND_STRING_CONST(b, "<average_since_start><![CDATA[");
667
	avg = p->abs_traffic_out / (srv->cur_ts - srv->startup_ts);
668

  
669
	mod_status_get_multiplier(&avg, &multiplier, 1024);
670

  
671
	sprintf(buf, "%.2f", avg);
672
	buffer_append_string(b, buf);
673
	BUFFER_APPEND_STRING_CONST(b, " ");
674
	if (multiplier)	buffer_append_string_len(b, &multiplier, 1);
675
	BUFFER_APPEND_STRING_CONST(b, "byte/s]]></average_since_start>");
676

  
677
	for (j = 0, avg = 0; j < 5; j++) {
678
		avg += p->mod_5s_traffic_out[j];
679
	}
680

  
681
	avg /= 5;
682

  
683
	BUFFER_APPEND_STRING_CONST(b, "<average_5s><![CDATA[");
684

  
685
	mod_status_get_multiplier(&avg, &multiplier, 1024);
686

  
687
	sprintf(buf, "%.2f", avg);
688
	buffer_append_string(b, buf);
689
	BUFFER_APPEND_STRING_CONST(b, " ");
690
	if (multiplier)	buffer_append_string_len(b, &multiplier, 1);
691
	BUFFER_APPEND_STRING_CONST(b, "byte/s]]></average_5s>");
692

  
693
	BUFFER_APPEND_STRING_CONST(b, "</traffic></stats></server-status><total_connections>");
694

  
695
	buffer_append_long(b, srv->conns->used);
696

  
697
	BUFFER_APPEND_STRING_CONST(b, "</total_connections><connections>");
698
	for (j = 0; j < srv->conns->used; j++) {
699
		connection *c = srv->conns->ptr[j];
700

  
701
		BUFFER_APPEND_STRING_CONST(b, "<connection><ip><![CDATA[");
702
		buffer_append_string(b, inet_ntop_cache_get_ip(srv, &(c->dst_addr)));
703
		BUFFER_APPEND_STRING_CONST(b, "]]></ip><read>");
704

  
705
		if (con->request.content_length) {
706
			BUFFER_APPEND_STRING_CONST(b, "<current>");
707
			buffer_append_long(b, c->request_content_queue->bytes_in);
708
			BUFFER_APPEND_STRING_CONST(b, "</current><total>");
709
			buffer_append_long(b, c->request.content_length);
710
			BUFFER_APPEND_STRING_CONST(b, "</total>");
711
		} else {
712
			BUFFER_APPEND_STRING_CONST(b, "<current>0</current><total>0</total>");
713
		}
714

  
715
		BUFFER_APPEND_STRING_CONST(b, "</read><write><current>");
716

  
717
		buffer_append_off_t(b, chunkqueue_written(c->write_queue));
718
		BUFFER_APPEND_STRING_CONST(b, "</current><total>");
719
		buffer_append_off_t(b, chunkqueue_length(c->write_queue));
720

  
721
		BUFFER_APPEND_STRING_CONST(b, "</total></write><state><![CDATA[");
722

  
723
		buffer_append_string(b, connection_get_state(c->state));
724

  
725
		BUFFER_APPEND_STRING_CONST(b, "]]></state><time>");
726

  
727
		buffer_append_long(b, srv->cur_ts - c->request_start);
728

  
729
		BUFFER_APPEND_STRING_CONST(b, "</time><host><![CDATA[");
730

  
731
		if (buffer_is_empty(c->server_name)) {
732
			buffer_append_string_buffer(b, c->uri.authority);
733
		}
734
		else {
735
			buffer_append_string_buffer(b, c->server_name);
736
		}
737

  
738
		BUFFER_APPEND_STRING_CONST(b, "]]></host><uri><![CDATA[");
739

  
740
		if (!buffer_is_empty(c->uri.path)) {
741
			buffer_append_string_encoded(b, CONST_BUF_LEN(c->uri.path), ENCODING_HTML);
742
		}
743

  
744
		if (!buffer_is_empty(c->uri.query)) {
745
			BUFFER_APPEND_STRING_CONST(b, "?");
746
			buffer_append_string_encoded(b, CONST_BUF_LEN(c->uri.query), ENCODING_HTML);
747
		}
748

  
749
		if (!buffer_is_empty(c->request.orig_uri)) {
750
			BUFFER_APPEND_STRING_CONST(b, " (");
751
			buffer_append_string_encoded(b, CONST_BUF_LEN(c->request.orig_uri), ENCODING_HTML);
752
			BUFFER_APPEND_STRING_CONST(b, ")");
753
		}
754
		BUFFER_APPEND_STRING_CONST(b, "]]></uri><file><![CDATA[");
755

  
756
		buffer_append_string_buffer(b, c->physical.path);
757

  
758
		BUFFER_APPEND_STRING_CONST(b, "]]></file></connection>\n");
759
	}
760

  
761
	BUFFER_APPEND_STRING_CONST(b, "</connections>");
762

  
763
	BUFFER_APPEND_STRING_CONST(b,"</status>");
764

  
765
	response_header_overwrite(srv, con, CONST_STR_LEN("Content-Type"), CONST_STR_LEN("text/xml"));
766

  
767
	return 0;
768
}
556 769

  
557 770
static handler_t mod_status_handle_server_status_text(server *srv, connection *con, void *p_d) {
558 771
	plugin_data *p = p_d;
......
651 864

  
652 865
	if (buffer_is_equal_string(con->uri.query, CONST_STR_LEN("auto"))) {
653 866
		mod_status_handle_server_status_text(srv, con, p_d);
867
	} else if(buffer_is_equal_string(con->uri.query, CONST_STR_LEN("xml"))) {
868
		mod_status_handle_server_status_xml(srv, con, p_d);
654 869
	} else {
655 870
		mod_status_handle_server_status_html(srv, con, p_d);
656 871
	}
(2-2/2)