I am using CGO to get network speed. package main
/* #include <stdio.h> #include <sys/socket.h> #include <sys/ioctl.h> #include <netinet/in.h> #include <linux/sockios.h> #include <linux/if.h> #include <linux/ethtool.h> #include <string.h> #include <stdlib.h> #include <unistd.h> int get_interface_speed(char *ifname){ int sock; struct ifreq ifr; struct ethtool_cmd edata; int rc; sock = socket(AF_INET, SOCK_STREAM, 0); // string copy first argument into struct strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); ifr.ifr_data = &edata; // set some global options from ethtool API edata.cmd = ETHTOOL_GSET; // issue ioctl rc = ioctl(sock, SIOCETHTOOL, &ifr); close(sock); if (rc < 0) { perror("ioctl"); // lets not error out here // make sure to zero out speed return 0; } return edata.speed; } */ import "C" import ( "fmt" "unsafe" ) func main() { ifname := []byte("eth0\x00")// interface name eth0,eth1,wlan0 etc. sp := C.get_interface_speed((*C.char)(unsafe.Pointer(&ifname[0]))) fmt.Println(sp) } Please give some suggestion . On Monday, March 28, 2016 at 5:21:59 PM UTC+5:30, kumargv wrote: > > i am able to get new_inbytes,prev_inbytes,new_outbytes,prev_outbytes From > /proc/net/dev file . > > > inbytes means recived > > outbyte means transmite > > fmt.Println("new_inbytes : ",new_inbytes," prev_inbytes : ",prev_inbytes) > > if new_inbytes >= prev_inbytes{ > > in_traffic = ( ( (new_inbytes - prev_inbytes) * 8 ) / (delta_time) ) > > fmt.Println("in_traffic : ",in_traffic) > > } > > fmt.Println("new_outbytes : ",new_outbytes," prev_outbytes : > ",prev_outbytes) > > if new_outbytes >= prev_outbytes{ > > out_traffic = ( ( (new_outbytes - prev_outbytes) * 8) / (delta_time)) > > fmt.Println("out_traffic : ",out_traffic) > > } > > if speed > 0{ > > in_utilization = (in_traffic / (speed * 10000)) > > out_utilization = (out_traffic / (speed * 10000)) > > } > > > > The Speed variable i am not able to find . > > please help. > > thanks > > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.