6 static void set_data(memcached_stat_st
*stat
, char *key
, char *value
)
8 if (!memcmp("pid", key
, strlen("pid")))
10 stat
->pid
= strtol(value
, (char **)NULL
, 10);
12 else if (!memcmp("uptime", key
, strlen("uptime")))
14 stat
->uptime
= strtol(value
, (char **)NULL
, 10);
16 else if (!memcmp("time", key
, strlen("time")))
18 stat
->time
= strtoll(value
, (char **)NULL
, 10);
20 else if (!memcmp("version", key
, strlen("version")))
22 memcpy(stat
->version
, value
, 8);
24 else if (!memcmp("pointer_size", key
, strlen("pointer_size")))
26 stat
->pointer_size
= strtoll(value
, (char **)NULL
, 10);
28 else if (!memcmp("rusage_user", key
, strlen("rusage_user")))
30 stat
->rusage_user
= strtoll(value
, (char **)NULL
, 10);
32 else if (!memcmp("rusage_system", key
, strlen("rusage_system")))
34 stat
->rusage_system
= strtoll(value
, (char **)NULL
, 10);
36 else if (!memcmp("rusage_user_seconds", key
, strlen("rusage_user_seconds")))
38 stat
->rusage_user_seconds
= strtoll(value
, (char **)NULL
, 10);
40 else if (!memcmp("rusage_user_microseconds", key
, strlen("rusage_user_microseconds")))
42 stat
->rusage_user_microseconds
= strtoll(value
, (char **)NULL
, 10);
44 else if (!memcmp("rusage_system_seconds", key
, strlen("rusage_system_seconds")))
46 stat
->rusage_system_seconds
= strtoll(value
, (char **)NULL
, 10);
48 else if (!memcmp("rusage_system_microseconds", key
, strlen("rusage_system_microseconds")))
50 stat
->rusage_system_microseconds
= strtoll(value
, (char **)NULL
, 10);
52 else if (!memcmp("curr_items", key
, strlen("curr_items")))
54 stat
->curr_items
= strtoll(value
, (char **)NULL
, 10);
56 else if (!memcmp("total_items", key
, strlen("total_items")))
58 stat
->total_items
= strtoll(value
, (char **)NULL
, 10);
60 else if (!memcmp("bytes", key
, strlen("bytes")))
62 stat
->bytes
= strtoll(value
, (char **)NULL
, 10);
64 else if (!memcmp("curr_connections", key
, strlen("curr_connections")))
66 stat
->curr_connections
= strtoll(value
, (char **)NULL
, 10);
68 else if (!memcmp("total_connections", key
, strlen("total_connections")))
70 stat
->total_connections
= strtoll(value
, (char **)NULL
, 10);
72 else if (!memcmp("connection_structures", key
, strlen("connection_structures")))
74 stat
->connection_structures
= strtoll(value
, (char **)NULL
, 10);
76 else if (!memcmp("cmd_get", key
, strlen("cmd_get")))
78 stat
->cmd_get
= strtoll(value
, (char **)NULL
, 10);
80 else if (!memcmp("cmd_set", key
, strlen("cmd_set")))
82 stat
->cmd_set
= strtoll(value
, (char **)NULL
, 10);
84 else if (!memcmp("get_hits", key
, strlen("get_hits")))
86 stat
->get_hits
= strtoll(value
, (char **)NULL
, 10);
88 else if (!memcmp("get_misses", key
, strlen("get_misses")))
90 stat
->get_misses
= strtoll(value
, (char **)NULL
, 10);
92 else if (!memcmp("evictions", key
, strlen("evictions")))
94 stat
->evictions
= strtoll(value
, (char **)NULL
, 10);
96 else if (!memcmp("bytes_read", key
, strlen("bytes_read")))
98 stat
->bytes_read
= strtoll(value
, (char **)NULL
, 10);
100 else if (!memcmp("bytes_written", key
, strlen("bytes_written")))
102 stat
->bytes_written
= strtoll(value
, (char **)NULL
, 10);
104 else if (!memcmp("limit_maxbytes", key
, strlen("limit_maxbytes")))
106 stat
->limit_maxbytes
= strtoll(value
, (char **)NULL
, 10);
108 else if (!memcmp("threads", key
, strlen("threads")))
110 stat
->threads
= strtol(key
, (char **)NULL
, 10);
114 fprintf(stderr
, "Unknown key %s\n", key
);
118 memcached_stat_st
**memcached_stat(memcached_st
*ptr
, memcached_return
*error
)
123 memcached_return
memcached_stat_hostname(memcached_stat_st
*stat
, char *args
,
124 char *hostname
, unsigned int port
)
128 char buffer
[HUGE_STRING_LEN
];
131 memcached_init(&memc
);
133 rc
= memcached_connect(&memc
);
135 if (rc
!= MEMCACHED_SUCCESS
)
139 send_length
= snprintf(buffer
, HUGE_STRING_LEN
,
140 "stats %s\r\n", args
);
142 send_length
= snprintf(buffer
, HUGE_STRING_LEN
,
145 if ((send(memc
.fd
, buffer
, send_length
, 0) == -1))
147 fprintf(stderr
, "failed on stats\n");
149 rc
= MEMCACHED_WRITE_FAILURE
;
153 rc
= memcached_response(&memc
, buffer
, HUGE_STRING_LEN
);
155 if (rc
== MEMCACHED_SUCCESS
)
157 char *string_ptr
, *end_ptr
;
163 if (memcmp(string_ptr
, "STAT ", 5))
166 for (end_ptr
= string_ptr
; *end_ptr
!= ' '; end_ptr
++);
168 key
[(size_t)(end_ptr
-string_ptr
)]= 0;
170 string_ptr
= end_ptr
+ 1;
171 for (end_ptr
= string_ptr
; *end_ptr
!= '\r'; end_ptr
++);
173 value
[(size_t)(end_ptr
-string_ptr
)]= 0;
174 string_ptr
= end_ptr
+ 2;
175 set_data(stat
, key
, value
);
180 memcached_deinit(&memc
);