-
Notifications
You must be signed in to change notification settings - Fork 56
FEATURE: Add stats_tcp_retrans() #750
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
uhm0311
wants to merge
1
commit into
naver:develop
Choose a base branch
from
uhm0311:uhm0311/develop
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+185
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ | ||
| /* | ||
| * arcus-memcached - Arcus memory cache server | ||
| * Copyright 2010-2014 NAVER Corp. | ||
| * Copyright 2015 JaM2in Co., Ltd. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| /* | ||
| * Detailed statistics management. For simple stats like total number of | ||
| * "get" requests, we use inline code in memcached.c and friends, but when | ||
| * stats detail mode is activated, the code here records more information. | ||
| * | ||
| * Author: | ||
| * Steven Grimm <[email protected]> | ||
| */ | ||
| #include "stats.h" | ||
|
|
||
| #include <ctype.h> | ||
| #include <errno.h> | ||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
| #include <string.h> | ||
|
|
||
| #ifdef STATS_TCP_RETRANS | ||
|
|
||
| static void rtrim(char **src) { | ||
| if (src == NULL || *src == NULL || strlen(*src) == 0) { | ||
| return; | ||
| } | ||
|
|
||
| char *str = *src; | ||
| for (int i = strlen(str) - 1; i >= 0; i--) { | ||
| if (!isspace(str[i])) { | ||
| break; | ||
| } | ||
|
|
||
| str[i] = '\0'; | ||
| } | ||
|
|
||
| *src = str; | ||
| } | ||
|
|
||
| int64_t stats_tcp_retrans(void) { | ||
| char *key_line = NULL; | ||
| char *value_line = NULL; | ||
| int64_t tcp_retrans = -1; | ||
|
|
||
| FILE *fp = fopen("/proc/net/snmp", "r"); | ||
| if (fp == NULL) { | ||
| goto done; | ||
| } | ||
|
|
||
| size_t key_len = 0; | ||
| size_t value_len = 0; | ||
| ssize_t key_read = -1; | ||
| ssize_t value_read = -1; | ||
|
|
||
| char *prefix = "Tcp:"; | ||
| size_t prefix_len = strlen(prefix); | ||
|
|
||
| while ((key_read = getline(&key_line, &key_len, fp)) != -1) { | ||
| if (strncmp(prefix, key_line, prefix_len) != 0) { | ||
| continue; | ||
| } | ||
|
|
||
| if ((value_read = getline(&value_line, &value_len, fp)) != -1) { | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| if (key_read < 0 || value_read < 0) { | ||
| goto done; | ||
| } | ||
|
|
||
| /* | ||
| * below lines are examples of key_line and value_line. | ||
| * for examples below, tcp_retrans = 9814784 | ||
| * | ||
| * Tcp: RtoAlgorithm RtoMin RtoMax MaxConn ActiveOpens PassiveOpens AttemptFails EstabResets CurrEstab InSegs OutSegs RetransSegs InErrs OutRsts InCsumErrors | ||
| * Tcp: 1 200 120000 -1 231273424 45758374 43975115 12045288 360 9853401239 10104984649 9814784 12765 17318799 883 | ||
| */ | ||
|
|
||
| char *delimiter = " "; | ||
| char *retrans_segs = "RetransSegs"; | ||
|
|
||
| char *key_next = NULL; | ||
| char *value_next = NULL; | ||
|
|
||
| char *key_token = strtok_r(key_line, delimiter, &key_next); | ||
| char *value_token = strtok_r(value_line, delimiter, &value_next); | ||
|
|
||
| // first token is always "Tcp:" | ||
| key_token = strtok_r(NULL, delimiter, &key_next); | ||
| value_token = strtok_r(NULL, delimiter, &value_next); | ||
|
|
||
| while (key_token && value_token) { | ||
| // last token always ends with "\n" | ||
| rtrim(&key_token); | ||
| rtrim(&value_token); | ||
|
|
||
| if (strcmp(key_token, retrans_segs) == 0) { | ||
| char *end = NULL; | ||
| errno = 0; | ||
| tcp_retrans = strtoll(value_token, &end, 10); | ||
|
|
||
| if (errno > 0 || *end != '\0') { | ||
| tcp_retrans = -1; | ||
| } | ||
| goto done; | ||
| } | ||
|
|
||
| key_token = strtok_r(NULL, delimiter, &key_next); | ||
| value_token = strtok_r(NULL, delimiter, &value_next); | ||
| } | ||
|
|
||
| done: | ||
| if (fp != NULL) { | ||
| fclose(fp); | ||
| } | ||
|
|
||
| if (key_line != NULL) { | ||
| free(key_line); | ||
| } | ||
|
|
||
| if (value_line != NULL) { | ||
| free(value_line); | ||
| } | ||
|
|
||
| return tcp_retrans; | ||
| } | ||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /* | ||
| * arcus-memcached - Arcus memory cache server | ||
| * Copyright 2010-2014 NAVER Corp. | ||
| * Copyright 2015 JaM2in Co., Ltd. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| /* stats */ | ||
| #ifndef STATS_H | ||
| #define STATS_H | ||
|
|
||
| #include <stdint.h> | ||
|
|
||
| #define STATS_TCP_RETRANS | ||
|
|
||
| #ifdef STATS_TCP_RETRANS | ||
| int64_t stats_tcp_retrans(void); | ||
| #endif | ||
ing-eoking marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.