~ps10gel/ubuntu/xenial/trafficserver/6.2.0

« back to all changes in this revision

Viewing changes to test/plugin/test-mgmt/test-mgmt.c

  • Committer: Bazaar Package Importer
  • Author(s): Arno Toell
  • Date: 2011-01-13 11:49:18 UTC
  • Revision ID: james.westby@ubuntu.com-20110113114918-vu422h8dknrgkj15
Tags: upstream-2.1.5-unstable
ImportĀ upstreamĀ versionĀ 2.1.5-unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/** @file
 
2
 
 
3
  A brief file description
 
4
 
 
5
  @section license License
 
6
 
 
7
  Licensed to the Apache Software Foundation (ASF) under one
 
8
  or more contributor license agreements.  See the NOTICE file
 
9
  distributed with this work for additional information
 
10
  regarding copyright ownership.  The ASF licenses this file
 
11
  to you under the Apache License, Version 2.0 (the
 
12
  "License"); you may not use this file except in compliance
 
13
  with the License.  You may obtain a copy of the License at
 
14
 
 
15
      http://www.apache.org/licenses/LICENSE-2.0
 
16
 
 
17
  Unless required by applicable law or agreed to in writing, software
 
18
  distributed under the License is distributed on an "AS IS" BASIS,
 
19
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
20
  See the License for the specific language governing permissions and
 
21
  limitations under the License.
 
22
 */
 
23
 
 
24
/***************************************************************
 
25
 * test-mgmt:
 
26
 * This sample plugins calls the Plugin Management APIs
 
27
 * The API covered in this plugin are -
 
28
 *              - TSMgmtCounterGet
 
29
 *              - TSMgmtFloatGet
 
30
 *              - TSMgmtIntGet
 
31
 *              - TSMgmtSringGet
 
32
 *              - TSInstallDirGet
 
33
 *              - TSPluginDirGet
 
34
 **************************************************************/
 
35
 
 
36
#include <stdio.h>
 
37
#include <string.h>
 
38
#include <time.h>
 
39
 
 
40
#if !defined (_WIN32)
 
41
#       include <unistd.h>
 
42
#else
 
43
#       include <windows.h>
 
44
#endif
 
45
 
 
46
#include "ts.h"
 
47
#include "macro.h"
 
48
 
 
49
#define STRING_SIZE 512
 
50
#define AUTO_TAG "AUTO_ERROR"
 
51
#define DEBUG_TAG "ERROR"
 
52
#define PLUGIN_NAME "test-mgmt"
 
53
 
 
54
const char *counterVariables[] = {
 
55
  "proxy.process.socks.connections_unsuccessful",
 
56
  "proxy.process.socks.connections_successful",
 
57
  "proxy.process.log.log_files_open",
 
58
  "proxy.process.log.event_log_error",
 
59
  "proxy.process.log.event_log_access",
 
60
  "proxy.process.log.event_log_access_fail",
 
61
  "proxy.process.log.event_log_access_skip",
 
62
  '\0'
 
63
};
 
64
 
 
65
const char *floatVariables[] = {
 
66
  "proxy.config.admin.load_factor",
 
67
  "proxy.config.http.background_fill_completed_threshold",
 
68
  "proxy.config.http.cache.heuristic_lm_factor",
 
69
  "proxy.config.http.cache.fuzz.probability",
 
70
  "proxy.config.cache.gc.watermark",
 
71
  "proxy.config.cache.synthetic_errors.locks",
 
72
  "proxy.config.cache.synthetic_errors.disk.lseek",
 
73
  "proxy.config.cache.synthetic_errors.disk.read",
 
74
  "proxy.config.cache.synthetic_errors.disk.write",
 
75
  "proxy.config.cache.synthetic_errors.disk.readv",
 
76
  "proxy.config.cache.synthetic_errors.disk.writev",
 
77
  "proxy.config.cache.synthetic_errors.disk.pread",
 
78
  "proxy.config.cache.synthetic_errors.disk.pwrite",
 
79
  "proxy.process.http.transaction_totaltime.hit_fresh",
 
80
  "proxy.process.http.transaction_totaltime.hit_revalidated",
 
81
  "proxy.process.http.transaction_totaltime.miss_cold",
 
82
  "proxy.process.http.transaction_totaltime.miss_changed",
 
83
  "proxy.process.http.transaction_totaltime.miss_client_no_cache",
 
84
  "proxy.process.http.transaction_totaltime.miss_not_cacheable",
 
85
  "proxy.process.http.transaction_totaltime.errors.aborts",
 
86
  "proxy.process.http.transaction_totaltime.errors.possible_aborts",
 
87
  "proxy.process.http.transaction_totaltime.errors.connect_failed",
 
88
  "proxy.process.http.transaction_totaltime.errors.pre_accept_hangups",
 
89
  "proxy.process.http.transaction_totaltime.errors.empty_hangups",
 
90
  "proxy.process.http.transaction_totaltime.errors.early_hangups",
 
91
  "proxy.process.http.transaction_totaltime.errors.other",
 
92
  "proxy.process.http.avg_transactions_per_client_connection",
 
93
  "proxy.process.http.avg_transactions_per_server_connection",
 
94
  "proxy.process.http.avg_transactions_per_parent_connection",
 
95
  "proxy.process.cluster.connections_avg_time",
 
96
  "proxy.process.cluster.control_messages_avg_send_time",
 
97
  "proxy.process.cluster.control_messages_avg_receive_time",
 
98
  "proxy.process.cluster.open_delay_time",
 
99
  "proxy.process.cluster.cache_callback_time",
 
100
  "proxy.process.cluster.rmt_cache_callback_time",
 
101
  "proxy.process.cluster.lkrmt_cache_callback_time",
 
102
  "proxy.process.cluster.local_connection_time",
 
103
  "proxy.process.cluster.remote_connection_time",
 
104
  "proxy.process.cluster.rdmsg_assemble_time",
 
105
  "proxy.process.cluster.cluster_ping_time",
 
106
  "proxy.process.cache.percent_full",
 
107
  "proxy.process.cache.gc.segments.avg_clean_time",
 
108
  "proxy.process.cache.gc.segments.avg_clear_time",
 
109
  "proxy.process.cache.reads.avg_time",
 
110
  "proxy.process.cache.reads.avg_size",
 
111
  "proxy.process.cache.flushes.avg_time",
 
112
  "proxy.process.dns.lookup_avg_time",
 
113
  "proxy.process.dns.success_avg_time",
 
114
  "proxy.process.hostdb.ttl",
 
115
  "proxy.process.icp.total_icp_response_time",
 
116
  "proxy.process.icp.total_icp_request_time",
 
117
  '\0'
 
118
};
 
119
 
 
120
 
 
121
const char *intVariables[] = {
 
122
  "proxy.local.cluster.type",
 
123
  "proxy.config.cop.core_signal",
 
124
  "proxy.config.lm.sem_id",
 
125
  "proxy.config.cluster.type",
 
126
  "proxy.config.cluster.rsport",
 
127
  "proxy.config.cluster.mcport",
 
128
  "proxy.config.cluster.mc_ttl",
 
129
  "proxy.config.cluster.log_bogus_mc_msgs",
 
130
  "proxy.config.admin.web_interface_port",
 
131
  "proxy.config.admin.autoconf_port",
 
132
  "proxy.config.admin.overseer_port",
 
133
  "proxy.config.admin.basic_auth",
 
134
  "proxy.config.admin.use_ssl",
 
135
  "proxy.config.admin.number_config_bak",
 
136
  "proxy.config.admin.ui_refresh_rate",
 
137
  "proxy.config.admin.log_mgmt_access",
 
138
  "proxy.config.admin.log_resolve_hostname",
 
139
  "proxy.config.process_manager.mgmt_port",
 
140
  "proxy.config.vmap.enabled",
 
141
  "proxy.config.vmap.mode",
 
142
  "proxy.config.phone_home.phone_home_send_info_enabled",
 
143
  "proxy.config.phone_home.phone_home_data_encryption_enabled",
 
144
  "proxy.config.phone_home.phone_home_frequency",
 
145
  "proxy.config.http.server_port",
 
146
  "proxy.config.http.insert_request_via_str",
 
147
  "proxy.config.http.insert_response_via_str",
 
148
  "proxy.config.http.enable_url_expandomatic",
 
149
  "proxy.config.http.no_dns_just_forward_to_parent",
 
150
  "proxy.config.http.keep_alive_enabled",
 
151
  "proxy.config.http.send_http11_requests",
 
152
  "proxy.config.http.origin_server_pipeline",
 
153
  "proxy.config.http.user_agent_pipeline",
 
154
  "proxy.config.http.share_server_sessions",
 
155
  "proxy.config.http.record_heartbeat",
 
156
  "proxy.config.http.parent_proxy_routing_enable",
 
157
  "proxy.config.http.parent_proxy.retry_time",
 
158
  "proxy.config.http.parent_proxy.fail_threshold",
 
159
  "proxy.config.http.parent_proxy.total_connect_attempts",
 
160
  "proxy.config.http.parent_proxy.per_parent_connect_attempts",
 
161
  "proxy.config.http.parent_proxy.connect_attempts_timeout",
 
162
  "proxy.config.http.forward.proxy_auth_to_parent",
 
163
  "proxy.config.http.keep_alive_no_activity_timeout_in",
 
164
  "proxy.config.http.keep_alive_no_activity_timeout_out",
 
165
  "proxy.config.http.transaction_no_activity_timeout_in",
 
166
  "proxy.config.http.transaction_no_activity_timeout_out",
 
167
  "proxy.config.http.transaction_active_timeout_in",
 
168
  "proxy.config.http.transaction_active_timeout_out",
 
169
  "proxy.config.http.accept_no_activity_timeout",
 
170
  "proxy.config.http.background_fill_active_timeout",
 
171
  "proxy.config.http.connect_attempts_max_retries",
 
172
  "proxy.config.http.connect_attempts_max_retries_dead_server",
 
173
  "proxy.config.http.connect_attempts_rr_retries",
 
174
  "proxy.config.http.connect_attempts_timeout",
 
175
  "proxy.config.http.down_server.cache_time",
 
176
  "proxy.config.http.down_server.abort_threshold",
 
177
  "proxy.config.http.anonymize_remove_from",
 
178
  "proxy.config.http.anonymize_remove_referer",
 
179
  "proxy.config.http.anonymize_remove_user_agent",
 
180
  "proxy.config.http.anonymize_remove_cookie",
 
181
  "proxy.config.http.anonymize_remove_client_ip",
 
182
  "proxy.config.http.anonymize_insert_client_ip",
 
183
  "proxy.config.http.append_xforwards_header",
 
184
  "proxy.config.http.snarf_username_from_authorization",
 
185
  "proxy.config.http.insert_squid_x_forwarded_for",
 
186
  "proxy.config.http.push_method_enabled",
 
187
  "proxy.config.http.cache.http",
 
188
  "proxy.config.http.cache.ignore_client_no_cache",
 
189
  "proxy.config.http.cache.ims_on_client_no_cache",
 
190
  "proxy.config.http.cache.ignore_server_no_cache",
 
191
  "proxy.config.http.cache.cache_responses_to_cookies",
 
192
  "proxy.config.http.cache.ignore_authentication",
 
193
  "proxy.config.http.cache.cache_urls_that_look_dynamic",
 
194
  "proxy.config.http.cache.enable_default_vary_headers",
 
195
  "proxy.config.http.cache.when_to_revalidate",
 
196
  "proxy.config.http.cache.when_to_add_no_cache_to_msie_requests",
 
197
  "proxy.config.http.cache.required_headers",
 
198
  "proxy.config.http.cache.max_stale_age",
 
199
  "proxy.config.http.cache.add_content_length",
 
200
  "proxy.config.http.cache.range.lookup",
 
201
  "proxy.config.http.cache.heuristic_min_lifetime",
 
202
  "proxy.config.http.cache.heuristic_max_lifetime",
 
203
  "proxy.config.http.cache.guaranteed_min_lifetime",
 
204
  "proxy.config.http.cache.guaranteed_max_lifetime",
 
205
  "proxy.config.http.cache.fuzz.time",
 
206
  "proxy.config.body_factory.enable_customizations",
 
207
  "proxy.config.body_factory.enable_logging",
 
208
  "proxy.config.body_factory.response_suppression_mode",
 
209
  "proxy.config.socks.socks_needed",
 
210
  "proxy.config.socks.socks_version",
 
211
  "proxy.config.socks.socks_server_port",
 
212
  "proxy.config.socks.socks_timeout",
 
213
  "proxy.config.socks.accept_enabled",
 
214
  "proxy.config.net.connections_throttle",
 
215
  "proxy.config.cluster.cluster_port",
 
216
  "proxy.config.cache.permit.pinning",
 
217
  "proxy.config.cache.ram_cache.size",
 
218
  "proxy.config.cache.limits.http.max_alts",
 
219
  "proxy.config.cache.max_doc_size",
 
220
  "proxy.config.dns.search_default_domains",
 
221
  "proxy.config.dns.splitDNS.enabled",
 
222
  "proxy.config.hostdb.size",
 
223
  "proxy.config.hostdb.ttl_mode",
 
224
  "proxy.config.hostdb.timeout",
 
225
  "proxy.config.hostdb.strict_round_robin",
 
226
  "proxy.config.log.logging_enabled",
 
227
  "proxy.config.log.max_secs_per_buffer",
 
228
  "proxy.config.log.max_space_mb_for_logs",
 
229
  "proxy.config.log.max_space_mb_for_orphan_logs",
 
230
  "proxy.config.log.max_space_mb_headroom",
 
231
  "proxy.config.log.custom_logs_enabled",
 
232
  "proxy.config.log.squid_log_enabled",
 
233
  "proxy.config.log.squid_log_is_ascii",
 
234
  "proxy.config.log.common_log_enabled",
 
235
  "proxy.config.log.common_log_is_ascii",
 
236
  "proxy.config.log.extended_log_enabled",
 
237
  "proxy.config.log.extended_log_is_ascii",
 
238
  "proxy.config.log.extended2_log_enabled",
 
239
  "proxy.config.log.extended2_log_is_ascii",
 
240
  "proxy.config.log.separate_icp_logs",
 
241
  "proxy.config.log.separate_host_logs",
 
242
  "proxy.local.log.collation_mode",
 
243
  "proxy.config.log.collation_port",
 
244
  "proxy.config.log.collation_host_tagged",
 
245
  "proxy.config.log.collation_retry_sec",
 
246
  "proxy.config.log.rolling_enabled",
 
247
  "proxy.config.log.rolling_interval_sec",
 
248
  "proxy.config.log.rolling_offset_hr",
 
249
  "proxy.config.log.auto_delete_rolled_files",
 
250
  "proxy.config.log.sampling_frequency",
 
251
  "proxy.config.reverse_proxy.enabled",
 
252
  "proxy.config.url_remap.default_to_server_pac",
 
253
  "proxy.config.url_remap.default_to_server_pac_port",
 
254
  "proxy.config.url_remap.remap_required",
 
255
  "proxy.config.url_remap.pristine_host_hdr",
 
256
  "proxy.config.ssl.enabled",
 
257
  "proxy.config.ssl.server_port",
 
258
  "proxy.config.ssl.client.certification_level",
 
259
  "proxy.config.ssl.client.verify.server",
 
260
  "proxy.config.icp.enabled",
 
261
  "proxy.config.icp.icp_port",
 
262
  "proxy.config.icp.multicast_enabled",
 
263
  "proxy.config.icp.query_timeout",
 
264
  "proxy.config.update.enabled",
 
265
  "proxy.config.update.force",
 
266
  "proxy.config.update.retry_count",
 
267
  "proxy.config.update.retry_interval",
 
268
  "proxy.config.update.concurrent_updates",
 
269
  "proxy.config.diags.debug.enabled",
 
270
  "proxy.config.diags.action.enabled",
 
271
  "proxy.config.diags.show_location",
 
272
  "proxy.config.core_limit",
 
273
  '\0'
 
274
};
 
275
 
 
276
const char *stringVariables[] = {
 
277
  "proxy.config.proxy_name",
 
278
  "proxy.config.proxy_binary",
 
279
  "proxy.config.proxy_binary_opts",
 
280
  "proxy.config.manager_binary",
 
281
  "proxy.config.cli_binary",
 
282
  "proxy.config.watch_script",
 
283
  "proxy.config.env_prep",
 
284
  "proxy.config.config_dir",
 
285
  "proxy.config.temp_dir",
 
286
  "proxy.config.syslog_facility",
 
287
  "proxy.config.cluster.mc_group_addr",
 
288
  "proxy.config.admin.html_doc_root",
 
289
  "proxy.config.admin.admin_user",
 
290
  "proxy.config.admin.admin_password",
 
291
  "proxy.config.admin.ssl_cert_file",
 
292
  "proxy.config.admin.user_id",
 
293
  "proxy.config.alarm.bin",
 
294
  "proxy.config.alarm.abs_path",
 
295
  "proxy.config.phone_home.phone_home_server",
 
296
  "proxy.config.phone_home.phone_home_path",
 
297
  "proxy.config.phone_home.phone_home_id",
 
298
  "proxy.config.header.parse.no_host_url_redirect",
 
299
  "proxy.config.http.server_port_attr",
 
300
  "proxy.config.http.server_other_ports",
 
301
  "proxy.config.http.connect_ports",
 
302
  "proxy.config.http.parent_proxies",
 
303
  "proxy.config.http.anonymize_other_header_list",
 
304
  "proxy.config.http.cache.vary_default_text",
 
305
  "proxy.config.http.cache.vary_default_images",
 
306
  "proxy.config.http.cache.vary_default_other",
 
307
  "proxy.config.socks.socks_server_ip_str",
 
308
  "proxy.config.cluster.ethernet_interface",
 
309
  "proxy.config.dns.url_expansions",
 
310
  "proxy.config.log.hostname",
 
311
  "proxy.config.log.logfile_dir",
 
312
  "proxy.config.log.logfile_perm",
 
313
  "proxy.config.log.squid_log_name",
 
314
  "proxy.config.log.squid_log_header",
 
315
  "proxy.config.log.common_log_name",
 
316
  "proxy.config.log.common_log_header",
 
317
  "proxy.config.log.extended_log_name",
 
318
  "proxy.config.log.extended_log_header",
 
319
  "proxy.config.log.extended2_log_name",
 
320
  "proxy.config.log.extended2_log_header",
 
321
  "proxy.config.log.collation_host",
 
322
  "proxy.config.log.collation_secret",
 
323
  "proxy.config.ssl.server.cert.filename",
 
324
  "proxy.config.ssl.server.cert.path",
 
325
  "proxy.config.ssl.server.private_key.filename",
 
326
  "proxy.config.ssl.server.private_key.path",
 
327
  "proxy.config.ssl.CA.cert.filename",
 
328
  "proxy.config.ssl.CA.cert.path",
 
329
  "proxy.config.ssl.client.cert.filename",
 
330
  "proxy.config.ssl.client.cert.path",
 
331
  "proxy.config.ssl.client.private_key.filename",
 
332
  "proxy.config.ssl.client.private_key.path",
 
333
  "proxy.config.ssl.client.CA.cert.filename",
 
334
  "proxy.config.ssl.client.CA.cert.path",
 
335
  "proxy.config.icp.icp_interface",
 
336
  "proxy.config.plugin.plugin_dir",
 
337
  "proxy.config.diags.debug.tags",
 
338
  "proxy.config.diags.output.diag",
 
339
  "proxy.config.diags.action.tags",
 
340
  "proxy.config.diags.output.debug",
 
341
  "proxy.config.diags.output.status",
 
342
  "proxy.config.diags.output.note",
 
343
  "proxy.config.diags.output.warning",
 
344
  "proxy.config.diags.output.error",
 
345
  "proxy.config.diags.output.fatal",
 
346
  "proxy.config.diags.output.alert",
 
347
  "proxy.config.diags.output.emergency",
 
348
  '\0'
 
349
};
 
350
 
 
351
 
 
352
static void
 
353
handleTxnStart()
 
354
{
 
355
  const char **p;
 
356
  TSMgmtCounter counterValue = 0;
 
357
  TSMgmtFloat floatValue = 0.0;
 
358
  TSMgmtInt intValue = 0;
 
359
  TSMgmtString stringValue = '\0';
 
360
 
 
361
  char errorLine[STRING_SIZE];
 
362
 
 
363
  LOG_SET_FUNCTION_NAME("handleTxnStart");
 
364
 
 
365
 
 
366
  /* Print each of the COUNTER variables */
 
367
 
 
368
  TSDebug(PLUGIN_NAME, "\n============= COUNTER =============");
 
369
 
 
370
  p = counterVariables;
 
371
 
 
372
  while (*p) {
 
373
    if (!TSMgmtCounterGet(*p, &counterValue)) {
 
374
      sprintf(errorLine, "ERROR: couldn't retrieve [%s] ", *p);
 
375
      LOG_AUTO_ERROR("TSMgmtCounterGet", errorLine);
 
376
    } else {
 
377
      TSDebug(PLUGIN_NAME, "%s = %" PRId64 "", *p, counterValue);
 
378
    }
 
379
 
 
380
    *p++;
 
381
  }
 
382
 
 
383
  /* Print each of the FLOAT variables */
 
384
 
 
385
  TSDebug(PLUGIN_NAME, "\n============= FLOAT =============");
 
386
 
 
387
  p = floatVariables;
 
388
 
 
389
  while (*p) {
 
390
    if (!TSMgmtFloatGet(*p, &floatValue)) {
 
391
      sprintf(errorLine, "ERROR: couldn't retrieve [%s] ", *p);
 
392
      LOG_AUTO_ERROR("TSMgmtFloatGet", errorLine);
 
393
    } else {
 
394
      TSDebug(PLUGIN_NAME, "%s = %f", *p, floatValue);
 
395
    }
 
396
 
 
397
    *p++;
 
398
  }
 
399
 
 
400
  /* Print each of the FLOAT variables */
 
401
 
 
402
  TSDebug(PLUGIN_NAME, "\n============= INT =============");
 
403
 
 
404
  p = intVariables;
 
405
 
 
406
  while (*p) {
 
407
    if (!TSMgmtIntGet(*p, &intValue)) {
 
408
      sprintf(errorLine, "ERROR: couldn't retrieve [%s] ", *p);
 
409
      LOG_AUTO_ERROR("TSMgmtIntGet", errorLine);
 
410
    } else {
 
411
      TSDebug(PLUGIN_NAME, "%s = %" PRId64 "", *p, intValue);
 
412
    }
 
413
 
 
414
    *p++;
 
415
  }
 
416
 
 
417
  /* Print each of the FLOAT variables */
 
418
 
 
419
  TSDebug(PLUGIN_NAME, "\n============= STRING =============");
 
420
 
 
421
  p = stringVariables;
 
422
 
 
423
  while (*p) {
 
424
    if (TSMgmtStringGet(*p, &stringValue)) {
 
425
      sprintf(errorLine, "ERROR: couldn't retrieve [%s] ", *p);
 
426
      LOG_AUTO_ERROR("TSMgmtStringGet", errorLine);
 
427
    } else {
 
428
      TSDebug(PLUGIN_NAME, "%s = %s", *p, stringValue);
 
429
    }
 
430
 
 
431
    *p++;
 
432
  }
 
433
 
 
434
}
 
435
 
 
436
 
 
437
void
 
438
TSPluginInit(int argc, const char *argv[])
 
439
{
 
440
  const char *ts_install_dir = TSInstallDirGet();
 
441
  const char *plugin_dir = TSPluginDirGet();
 
442
 
 
443
  /* Print the Traffic Server install and the plugin directory */
 
444
  printf("TS install dir: %s\n", ts_install_dir);
 
445
  printf("Plugin dir: %s\n", plugin_dir);
 
446
 
 
447
  handleTxnStart();
 
448
}