// <cmd> {<len> <column id>} <types> <#kvs> [{<len> <key>} {<len> <value>}]... void put_or_set(server_t *s, grn_ctx *ctx, int set) { uint32_t len; HOG_RECV(s, &len, sizeof(len), return); len = ntohl(len); char *buf = hog_alloc(NULL, len); HOG_RECV(s, buf, len, goto cleanup); grn_obj *col, *table; col = grn_ctx_get(ctx, buf, len); if(grn_obj_is_table(ctx, col)) table = col; else table = grn_column_table(ctx, col); // get key and value types char types[2]; HOG_RECV(s, types, 2, goto cleanup); // receive keys and values uint32_t nkeys; HOG_RECV(s, &nkeys, sizeof(nkeys), goto cleanup); nkeys = ntohl(nkeys); grn_obj value; GRN_OBJ_INIT(&value, GRN_BULK, 0, types[1]); for(uint32_t i = 0; i < nkeys; ++i){ HOG_RECV(s, &len, sizeof(len), goto value_fin); len = ntohl(len); buf = hog_alloc(buf, len); HOG_RECV(s, buf, len, goto value_fin); ntoh_buf(buf, len, types[0]); grn_id id; if(set){ id = grn_table_get(ctx, table, buf, len); }else{ id = grn_table_add(ctx, table, buf, len, NULL); } HOG_RECV(s, &len, sizeof(len), goto value_fin); len = ntohl(len); buf = hog_alloc(buf, len); HOG_RECV(s, buf, len, goto value_fin); if(id == GRN_ID_NIL) continue; ntoh_buf(buf, len, types[1]); GRN_BULK_REWIND(&value); grn_bulk_write(ctx, &value, buf, len); grn_obj_set_value(ctx, col, id, &value, GRN_OBJ_SET); } submit_one(s->socket); value_fin: GRN_OBJ_FIN(ctx, &value); cleanup: free(buf); }
static int vmem_read (void) { #if KERNEL_LINUX derive_t pgpgin = 0; derive_t pgpgout = 0; int pgpgvalid = 0; derive_t pswpin = 0; derive_t pswpout = 0; int pswpvalid = 0; derive_t pgfault = 0; derive_t pgmajfault = 0; int pgfaultvalid = 0; FILE *fh; char buffer[1024]; fh = fopen ("/proc/vmstat", "r"); if (fh == NULL) { char errbuf[1024]; ERROR ("vmem plugin: fopen (/proc/vmstat) failed: %s", sstrerror (errno, errbuf, sizeof (errbuf))); return (-1); } while (fgets (buffer, sizeof (buffer), fh) != NULL) { char *fields[4]; int fields_num; char *key; char *endptr; derive_t counter; gauge_t gauge; fields_num = strsplit (buffer, fields, STATIC_ARRAY_SIZE (fields)); if (fields_num != 2) continue; key = fields[0]; endptr = NULL; counter = strtoll (fields[1], &endptr, 10); if (fields[1] == endptr) continue; endptr = NULL; gauge = strtod (fields[1], &endptr); if (fields[1] == endptr) continue; /* * Number of pages * * The total number of {inst} pages, e. g dirty pages. */ if (strncmp ("nr_", key, strlen ("nr_")) == 0) { char *inst = key + strlen ("nr_"); value_t value = { .gauge = gauge }; submit_one (NULL, "vmpage_number", inst, value); } /* * Page in and page outs. For memory and swap. */ else if (strcmp ("pgpgin", key) == 0)
static void check_ignorelist_and_submit (const char *dev, struct ir_link_stats_storage_s *stats) { if (check_ignorelist (dev, "interface", NULL) == 0) { submit_two (dev, "if_octets", NULL, stats->rx_bytes, stats->tx_bytes); submit_two (dev, "if_packets", NULL, stats->rx_packets, stats->tx_packets); submit_two (dev, "if_errors", NULL, stats->rx_errors, stats->tx_errors); } else { DEBUG ("netlink plugin: Ignoring %s/interface.", dev); } if (check_ignorelist (dev, "if_detail", NULL) == 0) { submit_two (dev, "if_dropped", NULL, stats->rx_dropped, stats->tx_dropped); submit_one (dev, "if_multicast", NULL, stats->multicast); submit_one (dev, "if_collisions", NULL, stats->collisions); submit_one (dev, "if_rx_errors", "length", stats->rx_length_errors); submit_one (dev, "if_rx_errors", "over", stats->rx_over_errors); submit_one (dev, "if_rx_errors", "crc", stats->rx_crc_errors); submit_one (dev, "if_rx_errors", "frame", stats->rx_frame_errors); submit_one (dev, "if_rx_errors", "fifo", stats->rx_fifo_errors); submit_one (dev, "if_rx_errors", "missed", stats->rx_missed_errors); submit_one (dev, "if_tx_errors", "aborted", stats->tx_aborted_errors); submit_one (dev, "if_tx_errors", "carrier", stats->tx_carrier_errors); submit_one (dev, "if_tx_errors", "fifo", stats->tx_fifo_errors); submit_one (dev, "if_tx_errors", "heartbeat", stats->tx_heartbeat_errors); submit_one (dev, "if_tx_errors", "window", stats->tx_window_errors); } else { DEBUG ("netlink plugin: Ignoring %s/if_detail.", dev); } } /* void check_ignorelist_and_submit */